]>
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"
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
25 #include <wx/mac/uma.h>
27 BEGIN_EVENT_TABLE(wxStaticText
, wxControl
)
28 EVT_PAINT(wxStaticText::OnPaint
)
31 bool wxStaticText::Create(wxWindow
*parent
, wxWindowID id
,
32 const wxString
& label
,
39 m_backgroundColour
= parent
->GetBackgroundColour() ;
40 m_foregroundColour
= parent
->GetForegroundColour() ;
43 m_windowId
= (int)NewControlId();
47 m_windowStyle
= style
;
50 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
51 SetSizeOrDefault( size
) ;
56 void wxStaticText::OnDraw( wxDC
&dc
)
58 if (m_width
<= 0 || m_height
<= 0)
66 wxString text
= m_label
;
72 while( i
< text
.Length() )
74 if( text
[i
] == 13 || text
[i
] == 10)
76 paragraph
= text
.Mid( laststop
, i
- laststop
) ;
77 while( paragraph
.Length() > 0 )
79 dc
.GetTextExtent( paragraph
, &width
, &height
) ;
80 if ( width
> m_width
)
82 for ( int p
= paragraph
.Length() -1 ; p
> 0 ; --p
)
84 if ( paragraph
[p
]=='.' )
86 dc
.GetTextExtent( paragraph
.Left(p
+1) , &width
, &height
) ;
87 if ( width
<= m_width
)
90 if ( HasFlag( wxALIGN_CENTER
) )
92 pos
+= ( m_width
- width
) / 2 ;
94 else if ( HasFlag( wxALIGN_RIGHT
) )
96 pos
+= ( m_width
- width
) ;
98 dc
.DrawText( paragraph
.Left(p
+1), pos
, y
) ;
100 paragraph
= paragraph
.Mid(p
+1) ;
104 if ( paragraph
[p
]==' ' )
106 dc
.GetTextExtent( paragraph
.Left(p
) , &width
, &height
) ;
107 if ( width
<= m_width
)
110 if ( HasFlag( wxALIGN_CENTER
) )
112 pos
+= ( m_width
- width
) / 2 ;
114 else if ( HasFlag( wxALIGN_RIGHT
) )
116 pos
+= ( m_width
- width
) ;
118 dc
.DrawText( paragraph
.Left(p
), pos
, y
) ;
120 paragraph
= paragraph
.Mid(p
+1) ;
128 dc
.DrawText( paragraph
, x
, y
) ;
137 paragraph
= text
.Mid( laststop
, text
.Length() - laststop
) ;
138 while( paragraph
.Length() > 0 )
140 dc
.GetTextExtent( paragraph
, &width
, &height
) ;
141 if ( width
> m_width
)
143 for ( int p
= paragraph
.Length() -1 ; p
> 0 ; --p
)
145 if ( paragraph
[p
]=='.' )
147 dc
.GetTextExtent( paragraph
.Left(p
+1) , &width
, &height
) ;
148 if ( width
<= m_width
)
151 if ( HasFlag( wxALIGN_CENTER
) )
153 pos
+= ( m_width
- width
) / 2 ;
155 else if ( HasFlag( wxALIGN_RIGHT
) )
157 pos
+= ( m_width
- width
) ;
159 dc
.DrawText( paragraph
.Left(p
+1), pos
, y
) ;
161 paragraph
= paragraph
.Mid(p
+1) ;
165 if ( paragraph
[p
]==' ' )
167 dc
.GetTextExtent( paragraph
.Left(p
) , &width
, &height
) ;
168 if ( width
<= m_width
)
171 if ( HasFlag( wxALIGN_CENTER
) )
173 pos
+= ( m_width
- width
) / 2 ;
175 else if ( HasFlag( wxALIGN_RIGHT
) )
177 pos
+= ( m_width
- width
) ;
179 dc
.DrawText( paragraph
.Left(p
), pos
, y
) ;
181 paragraph
= paragraph
.Mid(p
+1) ;
190 if ( HasFlag( wxALIGN_CENTER
) )
192 pos
+= ( m_width
- width
) / 2 ;
194 else if ( HasFlag( wxALIGN_RIGHT
) )
196 pos
+= ( m_width
- width
) ;
198 dc
.DrawText( paragraph
, pos
, y
) ;
205 void wxStaticText::OnPaint( wxPaintEvent
&event
)
211 wxSize
wxStaticText::DoGetBestSize() const
214 int widthTextMax
= 0, widthLine
,
215 heightTextTotal
= 0, heightLineDefault
= 0, heightLine
= 0;
218 for ( const wxChar
*pc
= m_label
; ; pc
++ ) {
219 if ( *pc
== wxT('\n') || *pc
== wxT('\0') ) {
221 // we can't use GetTextExtent - it will return 0 for both width
222 // and height and an empty line should count in height
224 if ( !heightLineDefault
)
225 heightLineDefault
= heightLine
;
226 if ( !heightLineDefault
)
227 GetTextExtent(_T("W"), NULL
, &heightLineDefault
);
229 heightTextTotal
+= heightLineDefault
;
232 GetTextExtent(curLine
, &widthLine
, &heightLine
);
233 if ( widthLine
> widthTextMax
)
234 widthTextMax
= widthLine
;
235 heightTextTotal
+= heightLine
;
238 if ( *pc
== wxT('\n') ) {
251 return wxSize(widthTextMax
, heightTextTotal
);
254 void wxStaticText::SetLabel(const wxString
& st
)
258 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )