]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStaticText
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "stattext.h"
17 #include "wx/stattext.h"
19 #include "wx/dcclient.h"
23 #if !USE_SHARED_LIBRARY
24 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
27 #include <wx/mac/uma.h>
29 BEGIN_EVENT_TABLE(wxStaticText
, wxControl
)
30 EVT_PAINT(wxStaticText::OnPaint
)
33 bool wxStaticText::Create(wxWindow
*parent
, wxWindowID id
,
34 const wxString
& label
,
41 m_backgroundColour
= parent
->GetBackgroundColour() ;
42 m_foregroundColour
= parent
->GetForegroundColour() ;
45 m_windowId
= (int)NewControlId();
49 m_windowStyle
= style
;
52 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
53 SetSizeOrDefault( size
) ;
58 void wxStaticText::OnDraw( wxDC
&dc
)
60 if (m_width
<= 0 || m_height
<= 0)
68 wxString text
= m_label
;
74 while( i
< text
.Length() )
76 if( text
[i
] == 13 || text
[i
] == 10)
78 paragraph
= text
.Mid( laststop
, i
- laststop
) ;
79 while( paragraph
.Length() > 0 )
81 dc
.GetTextExtent( paragraph
, &width
, &height
) ;
82 if ( width
> m_width
)
84 for ( int p
= paragraph
.Length() -1 ; p
> 0 ; --p
)
86 if ( paragraph
[p
]=='.' )
88 dc
.GetTextExtent( paragraph
.Left(p
+1) , &width
, &height
) ;
89 if ( width
<= m_width
)
92 if ( HasFlag( wxALIGN_CENTER
) )
94 pos
+= ( m_width
- width
) / 2 ;
96 else if ( HasFlag( wxALIGN_RIGHT
) )
98 pos
+= ( m_width
- width
) ;
100 dc
.DrawText( paragraph
.Left(p
+1), pos
, y
) ;
102 paragraph
= paragraph
.Mid(p
+1) ;
106 if ( paragraph
[p
]==' ' )
108 dc
.GetTextExtent( paragraph
.Left(p
) , &width
, &height
) ;
109 if ( width
<= m_width
)
112 if ( HasFlag( wxALIGN_CENTER
) )
114 pos
+= ( m_width
- width
) / 2 ;
116 else if ( HasFlag( wxALIGN_RIGHT
) )
118 pos
+= ( m_width
- width
) ;
120 dc
.DrawText( paragraph
.Left(p
), pos
, y
) ;
122 paragraph
= paragraph
.Mid(p
+1) ;
130 dc
.DrawText( paragraph
, x
, y
) ;
139 paragraph
= text
.Mid( laststop
, text
.Length() - laststop
) ;
140 while( paragraph
.Length() > 0 )
142 dc
.GetTextExtent( paragraph
, &width
, &height
) ;
143 if ( width
> m_width
)
145 for ( int p
= paragraph
.Length() -1 ; p
> 0 ; --p
)
147 if ( paragraph
[p
]=='.' )
149 dc
.GetTextExtent( paragraph
.Left(p
+1) , &width
, &height
) ;
150 if ( width
<= m_width
)
153 if ( HasFlag( wxALIGN_CENTER
) )
155 pos
+= ( m_width
- width
) / 2 ;
157 else if ( HasFlag( wxALIGN_RIGHT
) )
159 pos
+= ( m_width
- width
) ;
161 dc
.DrawText( paragraph
.Left(p
+1), pos
, y
) ;
163 paragraph
= paragraph
.Mid(p
+1) ;
167 if ( paragraph
[p
]==' ' )
169 dc
.GetTextExtent( paragraph
.Left(p
) , &width
, &height
) ;
170 if ( width
<= m_width
)
173 if ( HasFlag( wxALIGN_CENTER
) )
175 pos
+= ( m_width
- width
) / 2 ;
177 else if ( HasFlag( wxALIGN_RIGHT
) )
179 pos
+= ( m_width
- width
) ;
181 dc
.DrawText( paragraph
.Left(p
), pos
, y
) ;
183 paragraph
= paragraph
.Mid(p
+1) ;
192 if ( HasFlag( wxALIGN_CENTER
) )
194 pos
+= ( m_width
- width
) / 2 ;
196 else if ( HasFlag( wxALIGN_RIGHT
) )
198 pos
+= ( m_width
- width
) ;
200 dc
.DrawText( paragraph
, pos
, y
) ;
207 void wxStaticText::OnPaint( wxPaintEvent
&event
)
213 wxSize
wxStaticText::DoGetBestSize() const
216 int widthTextMax
= 0, widthLine
,
217 heightTextTotal
= 0, heightLineDefault
= 0, heightLine
= 0;
220 for ( const wxChar
*pc
= m_label
; ; pc
++ ) {
221 if ( *pc
== wxT('\n') || *pc
== wxT('\0') ) {
223 // we can't use GetTextExtent - it will return 0 for both width
224 // and height and an empty line should count in height
226 if ( !heightLineDefault
)
227 heightLineDefault
= heightLine
;
228 if ( !heightLineDefault
)
229 GetTextExtent(_T("W"), NULL
, &heightLineDefault
);
231 heightTextTotal
+= heightLineDefault
;
234 GetTextExtent(curLine
, &widthLine
, &heightLine
);
235 if ( widthLine
> widthTextMax
)
236 widthTextMax
= widthLine
;
237 heightTextTotal
+= heightLine
;
240 if ( *pc
== wxT('\n') ) {
253 return wxSize(widthTextMax
, heightTextTotal
);
256 void wxStaticText::SetLabel(const wxString
& st
)
260 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )