]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/stattext.mm
Sheet support for wxDirDialog.
[wxWidgets.git] / src / osx / cocoa / stattext.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/stattext.mm
3 // Purpose: wxStaticText
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id: stattext.cpp 54845 2008-07-30 14:52:41Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_STATTEXT
15
16 #include "wx/stattext.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #include "wx/utils.h"
21 #include "wx/dc.h"
22 #include "wx/dcclient.h"
23 #include "wx/settings.h"
24 #endif // WX_PRECOMP
25
26 #include "wx/osx/private.h"
27
28 #include <stdio.h>
29
30 wxSize wxStaticText::DoGetBestSize() const
31 {
32 Point bounds;
33
34 #if wxOSX_USE_ATSU_TEXT
35 OSStatus err = noErr;
36 wxCFStringRef str( m_label, GetFont().GetEncoding() );
37
38 SInt16 baseline;
39 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
40 {
41 err = GetThemeTextDimensions(
42 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
43 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
44 verify_noerr( err );
45 }
46 else
47 #endif
48 {
49 wxClientDC dc(const_cast<wxStaticText*>(this));
50 wxCoord width, height ;
51 dc.GetMultiLineTextExtent( m_label , &width, &height);
52 // Some labels seem to have their last characters
53 // stripped out. Adding 4 pixels seems to be enough to fix this.
54 bounds.h = width+4;
55 bounds.v = height;
56 }
57
58 if ( m_label.empty() )
59 bounds.h = 0;
60
61 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
62 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
63
64 return wxSize( bounds.h, bounds.v );
65 }
66
67 // for wxST_ELLIPSIZE_* support:
68
69 /*
70 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
71 to allow correct dynamic ellipsizing of the label
72 */
73
74 wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
75 wxWindowMac* parent,
76 wxWindowID id,
77 const wxString& label,
78 const wxPoint& pos,
79 const wxSize& size,
80 long style,
81 long extraStyle)
82 {
83 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
84 wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
85
86 [v setBezeled:NO];
87 [v setEditable:NO];
88 [v setDrawsBackground:NO];
89
90 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
91 return c;
92 /*
93 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
94
95 wxMacControl* peer = new wxMacControl( wxpeer );
96 OSStatus err = CreateStaticTextControl(
97 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
98 &bounds, NULL, NULL, peer->GetControlRefAddr() );
99 verify_noerr( err );
100
101 if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
102 {
103 TruncCode tCode = truncEnd;
104 if ( style & wxST_ELLIPSIZE_MIDDLE )
105 tCode = truncMiddle;
106
107 err = peer->SetData( kControlStaticTextTruncTag, tCode );
108 err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
109 }
110 return peer;
111 */
112 }
113
114 #endif //if wxUSE_STATTEXT