]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/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
)
63 wxString text
= m_label
;
69 while( i
< text
.Length() )
71 if( text
[i
] == 13 || text
[i
] == 10)
73 paragraph
= text
.Mid( laststop
, i
- laststop
) ;
74 while( paragraph
.Length() > 0 )
76 dc
.GetTextExtent( paragraph
, &width
, &height
) ;
77 if ( width
> m_width
)
79 for ( int p
= paragraph
.Length() -1 ; p
> 0 ; --p
)
81 if ( paragraph
[p
]=='.' )
83 dc
.GetTextExtent( paragraph
.Left(p
+1) , &width
, &height
) ;
84 if ( width
<= m_width
)
87 if ( HasFlag( wxALIGN_CENTER
) )
89 pos
+= ( m_width
- width
) / 2 ;
91 else if ( HasFlag( wxALIGN_RIGHT
) )
93 pos
+= ( m_width
- width
) ;
95 dc
.DrawText( paragraph
.Left(p
+1), pos
, y
) ;
97 paragraph
= paragraph
.Mid(p
+1) ;
101 if ( paragraph
[p
]==' ' )
103 dc
.GetTextExtent( paragraph
.Left(p
) , &width
, &height
) ;
104 if ( width
<= m_width
)
107 if ( HasFlag( wxALIGN_CENTER
) )
109 pos
+= ( m_width
- width
) / 2 ;
111 else if ( HasFlag( wxALIGN_RIGHT
) )
113 pos
+= ( m_width
- width
) ;
115 dc
.DrawText( paragraph
.Left(p
), pos
, y
) ;
117 paragraph
= paragraph
.Mid(p
+1) ;
125 dc
.DrawText( paragraph
, x
, y
) ;
134 paragraph
= text
.Mid( laststop
, text
.Length() - laststop
) ;
135 while( paragraph
.Length() > 0 )
137 dc
.GetTextExtent( paragraph
, &width
, &height
) ;
138 if ( width
> m_width
)
140 for ( int p
= paragraph
.Length() -1 ; p
> 0 ; --p
)
142 if ( paragraph
[p
]=='.' )
144 dc
.GetTextExtent( paragraph
.Left(p
+1) , &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
+1), pos
, y
) ;
158 paragraph
= paragraph
.Mid(p
+1) ;
162 if ( paragraph
[p
]==' ' )
164 dc
.GetTextExtent( paragraph
.Left(p
) , &width
, &height
) ;
165 if ( width
<= m_width
)
168 if ( HasFlag( wxALIGN_CENTER
) )
170 pos
+= ( m_width
- width
) / 2 ;
172 else if ( HasFlag( wxALIGN_RIGHT
) )
174 pos
+= ( m_width
- width
) ;
176 dc
.DrawText( paragraph
.Left(p
), pos
, y
) ;
178 paragraph
= paragraph
.Mid(p
+1) ;
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
, pos
, y
) ;
202 void wxStaticText::OnPaint( wxPaintEvent
&event
)
208 wxSize
wxStaticText::DoGetBestSize() const
211 int widthTextMax
= 0, widthLine
,
212 heightTextTotal
= 0, heightLineDefault
= 0, heightLine
= 0;
215 for ( const wxChar
*pc
= m_label
; ; pc
++ ) {
216 if ( *pc
== wxT('\n') || *pc
== wxT('\0') ) {
218 // we can't use GetTextExtent - it will return 0 for both width
219 // and height and an empty line should count in height
221 if ( !heightLineDefault
)
222 heightLineDefault
= heightLine
;
223 if ( !heightLineDefault
)
224 GetTextExtent(_T("W"), NULL
, &heightLineDefault
);
226 heightTextTotal
+= heightLineDefault
;
229 GetTextExtent(curLine
, &widthLine
, &heightLine
);
230 if ( widthLine
> widthTextMax
)
231 widthTextMax
= widthLine
;
232 heightTextTotal
+= heightLine
;
235 if ( *pc
== wxT('\n') ) {
248 return wxSize(widthTextMax
, heightTextTotal
);
251 void wxStaticText::SetLabel(const wxString
& st
)
255 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )