]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/stattext.mm
detect adding too many items to a grid sizer sooner and don't crash if this happens
[wxWidgets.git] / src / osx / cocoa / stattext.mm
CommitLineData
f033830e
SC
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
f033830e
SC
26#include "wx/osx/private.h"
27
28#include <stdio.h>
29
c2a4d428
KO
30@interface wxNSStaticTextView : NSTextView
31{
32 wxWidgetCocoaImpl* impl;
33}
34
35- (void) setImplementation:(wxWidgetCocoaImpl*) item;
36- (wxWidgetCocoaImpl*) implementation;
37@end
38@implementation wxNSStaticTextView
39
40+ (void)initialize
41{
42 static BOOL initialized = NO;
43 if (!initialized)
44 {
45 initialized = YES;
46 wxOSXCocoaClassAddWXMethods( self );
47 }
48}
49
50- (wxWidgetCocoaImpl*) implementation
51{
52 return impl;
53}
54
55- (void) setImplementation:(wxWidgetCocoaImpl*) item
56{
57 impl = item;
58}
59@end
60
61
f033830e
SC
62wxSize wxStaticText::DoGetBestSize() const
63{
4850cc8b 64Point bounds;
f033830e 65
4850cc8b
SC
66#if wxOSX_USE_ATSU_TEXT
67 OSStatus err = noErr;
68 wxCFStringRef str( m_label, GetFont().GetEncoding() );
69
70 SInt16 baseline;
71 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
f033830e 72 {
4850cc8b
SC
73 err = GetThemeTextDimensions(
74 (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
75 m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
76 verify_noerr( err );
f033830e
SC
77 }
78 else
79#endif
80 {
4850cc8b
SC
81 wxClientDC dc(const_cast<wxStaticText*>(this));
82 wxCoord width, height ;
16747764 83 dc.GetMultiLineTextExtent( m_label , &width, &height);
c2a4d428
KO
84 // FIXME: Some labels seem to have their last characters
85 // stripped out. Adding 12 pixels seems to be enough to fix this.
86 // Perhaps m_label is not being synced properly...
87 bounds.h = width+12;
4850cc8b
SC
88 bounds.v = height;
89 }
f033830e 90
4850cc8b
SC
91 if ( m_label.empty() )
92 bounds.h = 0;
f033830e 93
f033830e
SC
94 bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
95 bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
96
97 return wxSize( bounds.h, bounds.v );
98}
99
100// for wxST_ELLIPSIZE_* support:
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
6e7a89af
FM
107wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
108 wxWindowMac* parent,
109 wxWindowID id,
f033830e 110 const wxString& label,
6e7a89af 111 const wxPoint& pos,
f033830e 112 const wxSize& size,
6e7a89af
FM
113 long style,
114 long extraStyle)
f033830e 115{
dbeddfb9 116 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
c2a4d428 117 wxNSStaticTextView* v = [[wxNSStaticTextView alloc] initWithFrame:r];
f033830e 118
f033830e
SC
119 [v setEditable:NO];
120 [v setDrawsBackground:NO];
c2a4d428
KO
121 [v setString: wxCFStringRef( label , wxpeer->GetFont().GetEncoding() ).AsNSString()];
122
123 NSRange allText = NSMakeRange(0, label.length());
124 if (style & wxALIGN_CENTER)
125 [v setAlignment: NSCenterTextAlignment range: allText];
126 else if (style & wxALIGN_RIGHT)
127 [v setAlignment: NSRightTextAlignment range: allText];
6e7a89af 128
f033830e 129 wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
f033830e
SC
130 return c;
131/*
132 Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
133
134 wxMacControl* peer = new wxMacControl( wxpeer );
135 OSStatus err = CreateStaticTextControl(
136 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
137 &bounds, NULL, NULL, peer->GetControlRefAddr() );
138 verify_noerr( err );
139
140 if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
141 {
142 TruncCode tCode = truncEnd;
143 if ( style & wxST_ELLIPSIZE_MIDDLE )
144 tCode = truncMiddle;
145
146 err = peer->SetData( kControlStaticTextTruncTag, tCode );
147 err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
148 }
149 return peer;
150 */
151}
152
153#endif //if wxUSE_STATTEXT