]> git.saurik.com Git - wxWidgets.git/blob - src/osx/iphone/stattext.mm
Implement setFont on the iOS port of wxStaticText.
[wxWidgets.git] / src / osx / iphone / stattext.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/iphone/stattext.mm
3 // Purpose: wxStaticText
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #if wxUSE_STATTEXT
14
15 #include "wx/stattext.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/app.h"
19 #include "wx/utils.h"
20 #include "wx/dc.h"
21 #include "wx/dcclient.h"
22 #include "wx/settings.h"
23 #endif // WX_PRECOMP
24
25 #include "wx/osx/private.h"
26
27 #include <stdio.h>
28
29 @interface wxUILabel : UILabel
30 {
31 }
32 @end
33
34 @implementation wxUILabel
35
36 + (void)initialize
37 {
38 static BOOL initialized = NO;
39 if (!initialized)
40 {
41 initialized = YES;
42 wxOSXIPhoneClassAddWXMethods( self );
43 }
44 }
45
46 @end
47
48 class wxStaticTextIPhoneImpl : public wxWidgetIPhoneImpl
49 {
50 public:
51 wxStaticTextIPhoneImpl( wxWindowMac* peer , WXWidget w ) : wxWidgetIPhoneImpl(peer, w)
52 {
53 }
54
55 virtual void SetFont( const wxFont & font , const wxColour& WXUNUSED(foreground) , long WXUNUSED(windowStyle), bool WXUNUSED(ignoreBlack) )
56 {
57 wxUILabel* v = (wxUILabel*)GetWXWidget();
58 [v setFont: font.OSXGetUIFont()];
59 }
60
61 virtual void SetLabel(const wxString& title, wxFontEncoding encoding)
62 {
63 wxUILabel* v = (wxUILabel*)GetWXWidget();
64 wxCFStringRef text( title , encoding );
65
66 [v setText:text.AsNSString()];
67 }
68 private :
69 };
70
71 wxSize wxStaticText::DoGetBestSize() const
72 {
73 return wxWindowMac::DoGetBestSize() ;
74 }
75
76 wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
77 wxWindowMac* WXUNUSED(parent),
78 wxWindowID WXUNUSED(id),
79 const wxString& WXUNUSED(label),
80 const wxPoint& pos,
81 const wxSize& size,
82 long style,
83 long WXUNUSED(extraStyle))
84 {
85 CGRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
86 wxUILabel* v = [[wxUILabel alloc] initWithFrame:r];
87 v.backgroundColor = [UIColor clearColor];
88
89 UILineBreakMode linebreak = UILineBreakModeWordWrap;
90 if ( ((wxStaticText*)wxpeer)->IsEllipsized() )
91 {
92 if ( style & wxST_ELLIPSIZE_MIDDLE )
93 linebreak = UILineBreakModeMiddleTruncation;
94 else if (style & wxST_ELLIPSIZE_END )
95 linebreak = UILineBreakModeTailTruncation;
96 else if (style & wxST_ELLIPSIZE_START )
97 linebreak = UILineBreakModeHeadTruncation;
98 }
99 [v setLineBreakMode:linebreak];
100
101 if (style & wxALIGN_CENTER)
102 [v setTextAlignment: UITextAlignmentCenter];
103 else if (style & wxALIGN_RIGHT)
104 [v setTextAlignment: UITextAlignmentRight];
105
106 wxWidgetIPhoneImpl* c = new wxStaticTextIPhoneImpl( wxpeer, v );
107 return c;
108 }
109
110 #endif //if wxUSE_STATTEXT