Get SetLabel working again for wxStaticText by overriding SetLabel so that we can respect alignment. Also add a couple more sizing tweaks.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59477 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -98,7 +98,7 @@ public :
|
|||||||
|
|
||||||
void SetDefaultButton( bool isDefault );
|
void SetDefaultButton( bool isDefault );
|
||||||
void PerformClick();
|
void PerformClick();
|
||||||
void SetLabel(const wxString& title, wxFontEncoding encoding);
|
virtual void SetLabel(const wxString& title, wxFontEncoding encoding);
|
||||||
|
|
||||||
void SetCursor( const wxCursor & cursor );
|
void SetCursor( const wxCursor & cursor );
|
||||||
void CaptureMouse();
|
void CaptureMouse();
|
||||||
|
@@ -58,10 +58,31 @@
|
|||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
class wxStaticTextCocoaImpl : public wxWidgetCocoaImpl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxStaticTextCocoaImpl( wxWindowMac* peer , WXWidget w ) : wxWidgetCocoaImpl(peer, w)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void SetLabel(const wxString& title, wxFontEncoding encoding)
|
||||||
|
{
|
||||||
|
wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget();
|
||||||
|
wxWindow* wxpeer = GetWXPeer();
|
||||||
|
[v setString: wxCFStringRef( title , wxpeer->GetFont().GetEncoding() ).AsNSString()];
|
||||||
|
|
||||||
|
int style = wxpeer->GetWindowStyleFlag();
|
||||||
|
NSRange allText = NSMakeRange(0, title.length());
|
||||||
|
if (style & wxALIGN_CENTER)
|
||||||
|
[v setAlignment: NSCenterTextAlignment range: allText];
|
||||||
|
else if (style & wxALIGN_RIGHT)
|
||||||
|
[v setAlignment: NSRightTextAlignment range: allText];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
wxSize wxStaticText::DoGetBestSize() const
|
wxSize wxStaticText::DoGetBestSize() const
|
||||||
{
|
{
|
||||||
Point bounds;
|
Point bounds;
|
||||||
|
|
||||||
#if wxOSX_USE_ATSU_TEXT
|
#if wxOSX_USE_ATSU_TEXT
|
||||||
OSStatus err = noErr;
|
OSStatus err = noErr;
|
||||||
@@ -81,11 +102,10 @@ Point bounds;
|
|||||||
wxClientDC dc(const_cast<wxStaticText*>(this));
|
wxClientDC dc(const_cast<wxStaticText*>(this));
|
||||||
wxCoord width, height ;
|
wxCoord width, height ;
|
||||||
dc.GetMultiLineTextExtent( m_label , &width, &height);
|
dc.GetMultiLineTextExtent( m_label , &width, &height);
|
||||||
// FIXME: Some labels seem to have their last characters
|
// FIXME: The calculations returned by this function are too small
|
||||||
// stripped out. Adding 12 pixels seems to be enough to fix this.
|
// for some strings, so we adjust manually.
|
||||||
// Perhaps m_label is not being synced properly...
|
|
||||||
bounds.h = width+12;
|
bounds.h = width+12;
|
||||||
bounds.v = height;
|
bounds.v = height+4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_label.empty() )
|
if ( m_label.empty() )
|
||||||
@@ -119,15 +139,8 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
|
|||||||
[v setEditable:NO];
|
[v setEditable:NO];
|
||||||
[v setDrawsBackground:NO];
|
[v setDrawsBackground:NO];
|
||||||
[v setSelectable: NO];
|
[v setSelectable: NO];
|
||||||
[v setString: wxCFStringRef( label , wxpeer->GetFont().GetEncoding() ).AsNSString()];
|
|
||||||
|
|
||||||
NSRange allText = NSMakeRange(0, label.length());
|
wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v );
|
||||||
if (style & wxALIGN_CENTER)
|
|
||||||
[v setAlignment: NSCenterTextAlignment range: allText];
|
|
||||||
else if (style & wxALIGN_RIGHT)
|
|
||||||
[v setAlignment: NSRightTextAlignment range: allText];
|
|
||||||
|
|
||||||
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
|
|
||||||
return c;
|
return c;
|
||||||
/*
|
/*
|
||||||
Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
|
Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
|
||||||
|
Reference in New Issue
Block a user