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
)
87 DrawThemeTabPane ( &rect
, kThemeStateActive
);
93 parent
= parent
->GetParent() ;
102 wxString text
= m_label
;
108 while( i
< text
.Length() )
110 if( text
[i
] == 13 || text
[i
] == 10)
112 paragraph
= text
.Mid( laststop
, i
- laststop
) ;
113 while( paragraph
.Length() > 0 )
115 dc
.GetTextExtent( paragraph
, &width
, &height
) ;
116 if ( width
> m_width
)
118 for ( int p
= paragraph
.Length() -1 ; p
> 0 ; --p
)
120 if ( paragraph
[p
]=='.' )
122 dc
.GetTextExtent( paragraph
.Left(p
+1) , &width
, &height
) ;
123 if ( width
<= m_width
)
126 if ( HasFlag( wxALIGN_CENTER
) )
128 pos
+= ( m_width
- width
) / 2 ;
130 else if ( HasFlag( wxALIGN_RIGHT
) )
132 pos
+= ( m_width
- width
) ;
134 dc
.DrawText( paragraph
.Left(p
+1), pos
, y
) ;
136 paragraph
= paragraph
.Mid(p
+1) ;
140 if ( paragraph
[p
]==' ' )
142 dc
.GetTextExtent( paragraph
.Left(p
) , &width
, &height
) ;
143 if ( width
<= m_width
)
146 if ( HasFlag( wxALIGN_CENTER
) )
148 pos
+= ( m_width
- width
) / 2 ;
150 else if ( HasFlag( wxALIGN_RIGHT
) )
152 pos
+= ( m_width
- width
) ;
154 dc
.DrawText( paragraph
.Left(p
), pos
, y
) ;
156 paragraph
= paragraph
.Mid(p
+1) ;
164 dc
.DrawText( paragraph
, x
, y
) ;
173 paragraph
= text
.Mid( laststop
, text
.Length() - laststop
) ;
174 while( paragraph
.Length() > 0 )
176 dc
.GetTextExtent( paragraph
, &width
, &height
) ;
177 if ( width
> m_width
)
179 for ( int p
= paragraph
.Length() -1 ; p
> 0 ; --p
)
181 if ( paragraph
[p
]=='.' )
183 dc
.GetTextExtent( paragraph
.Left(p
+1) , &width
, &height
) ;
184 if ( width
<= m_width
)
187 if ( HasFlag( wxALIGN_CENTER
) )
189 pos
+= ( m_width
- width
) / 2 ;
191 else if ( HasFlag( wxALIGN_RIGHT
) )
193 pos
+= ( m_width
- width
) ;
195 dc
.DrawText( paragraph
.Left(p
+1), pos
, y
) ;
197 paragraph
= paragraph
.Mid(p
+1) ;
201 if ( paragraph
[p
]==' ' )
203 dc
.GetTextExtent( paragraph
.Left(p
) , &width
, &height
) ;
204 if ( width
<= m_width
)
207 if ( HasFlag( wxALIGN_CENTER
) )
209 pos
+= ( m_width
- width
) / 2 ;
211 else if ( HasFlag( wxALIGN_RIGHT
) )
213 pos
+= ( m_width
- width
) ;
215 dc
.DrawText( paragraph
.Left(p
), pos
, y
) ;
217 paragraph
= paragraph
.Mid(p
+1) ;
226 if ( HasFlag( wxALIGN_CENTER
) )
228 pos
+= ( m_width
- width
) / 2 ;
230 else if ( HasFlag( wxALIGN_RIGHT
) )
232 pos
+= ( m_width
- width
) ;
234 dc
.DrawText( paragraph
, pos
, y
) ;
241 void wxStaticText::OnPaint( wxPaintEvent
&event
)
247 wxSize
wxStaticText::DoGetBestSize() const
250 int widthTextMax
= 0, widthLine
,
251 heightTextTotal
= 0, heightLineDefault
= 0, heightLine
= 0;
254 for ( const wxChar
*pc
= m_label
; ; pc
++ ) {
255 if ( *pc
== wxT('\n') || *pc
== wxT('\0') ) {
257 // we can't use GetTextExtent - it will return 0 for both width
258 // and height and an empty line should count in height
260 if ( !heightLineDefault
)
261 heightLineDefault
= heightLine
;
262 if ( !heightLineDefault
)
263 GetTextExtent(_T("W"), NULL
, &heightLineDefault
);
265 heightTextTotal
+= heightLineDefault
;
268 GetTextExtent(curLine
, &widthLine
, &heightLine
);
269 if ( widthLine
> widthTextMax
)
270 widthTextMax
= widthLine
;
271 heightTextTotal
+= heightLine
;
274 if ( *pc
== wxT('\n') ) {
287 return wxSize(widthTextMax
, heightTextTotal
);
290 void wxStaticText::SetLabel(const wxString
& st
)
294 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
298 MacUpdateImmediately() ;
299 // wxClientDC dc(this);