]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/stattext.cpp
Adding compiling (but not yet working) taskbar implementation for OS X Cocoa, mostly...
[wxWidgets.git] / src / osx / carbon / stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/stattext.cpp
3 // Purpose: wxStaticText
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
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/notebook.h"
27 #include "wx/tabctrl.h"
28
29 #include "wx/osx/private.h"
30
31 #include <stdio.h>
32
33 class wxMacStaticText : public wxMacControl
34 {
35 public:
36 wxMacStaticText( wxWindowMac* peer ) : wxMacControl(peer)
37 {
38 }
39 void SetLabel(const wxString& title, wxFontEncoding encoding)
40 {
41 wxCFStringRef str( title, encoding );
42 OSStatus err = SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, str);
43 verify_noerr( err );
44 }
45 };
46
47 wxSize wxStaticText::DoGetBestSize() const
48 {
49 Point bounds;
50 #if wxOSX_USE_CARBON
51 Rect bestsize = { 0 , 0 , 0 , 0 } ;
52
53 // try the built-in best size if available
54 Boolean former = m_peer->GetData<Boolean>( kControlStaticTextIsMultilineTag);
55 m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
56 m_peer->GetBestRect( &bestsize ) ;
57 m_peer->SetData( kControlStaticTextIsMultilineTag, former );
58 if ( !EmptyRect( &bestsize ) )
59 {
60 bounds.h = bestsize.right - bestsize.left ;
61 bounds.v = bestsize.bottom - bestsize.top ;
62 }
63 else
64 #endif
65 {
66 #if wxOSX_USE_CARBON
67 ControlFontStyleRec controlFont;
68 OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
69 verify_noerr( err );
70
71 wxCFStringRef str( m_label, GetFont().GetEncoding() );
72
73 #if wxOSX_USE_ATSU_TEXT
74 SInt16 baseline;
75 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
76 {
77 err = GetThemeTextDimensions(
78 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
79 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
80 verify_noerr( err );
81 }
82 else
83 #endif
84 #endif
85 {
86 wxClientDC dc(const_cast<wxStaticText*>(this));
87 wxCoord width, height ;
88 dc.GetTextExtent( m_label , &width, &height);
89 bounds.h = width;
90 bounds.v = height;
91 }
92
93 if ( m_label.empty() )
94 bounds.h = 0;
95 }
96 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
97 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
98
99 return wxSize( bounds.h, bounds.v );
100 }
101
102 /*
103 FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
104 to allow correct dynamic ellipsizing of the label
105 */
106
107 wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
108 wxWindowMac* parent,
109 wxWindowID id,
110 const wxString& label,
111 const wxPoint& pos,
112 const wxSize& size,
113 long style,
114 long extraStyle)
115 {
116 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
117
118 wxMacControl* peer = new wxMacStaticText( wxpeer );
119 OSStatus err = CreateStaticTextControl(
120 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
121 &bounds, NULL, NULL, peer->GetControlRefAddr() );
122 verify_noerr( err );
123
124 if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
125 {
126 TruncCode tCode = truncEnd;
127 if ( style & wxST_ELLIPSIZE_MIDDLE )
128 tCode = truncMiddle;
129
130 err = peer->SetData( kControlStaticTextTruncTag, tCode );
131 err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
132 }
133 return peer;
134 }
135
136 #endif //if wxUSE_STATTEXT