X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/292e5e1f17af67a5885f1fdaa8c45a8a5a2a3ca5..8ba4faba4de4af7613911d83263b9470e5bb1207:/src/osx/carbon/stattext.cpp diff --git a/src/osx/carbon/stattext.cpp b/src/osx/carbon/stattext.cpp index 10873f3c22..67be74dbb4 100644 --- a/src/osx/carbon/stattext.cpp +++ b/src/osx/carbon/stattext.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/stattext.cpp +// Name: src/osx/carbon/stattext.cpp // Purpose: wxStaticText // Author: Stefan Csomor // Modified by: @@ -23,87 +23,69 @@ #include "wx/settings.h" #endif // WX_PRECOMP -#include "wx/notebook.h" -#include "wx/tabctrl.h" - -#include "wx/osx/uma.h" +#include "wx/osx/private.h" #include -IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) - - -bool wxStaticText::Create( wxWindow *parent, - wxWindowID id, - const wxString& label, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name ) +class wxMacStaticText : public wxMacControl { - m_macIsUserPane = false; - - if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) - return false; - - Rect bounds = wxMacGetBoundsForControl( this, pos, size ); - - m_peer = new wxMacControl( this ); - OSStatus err = CreateStaticTextControl( - MAC_WXHWND(parent->MacGetTopLevelWindowRef()), - &bounds, NULL, NULL, m_peer->GetControlRefAddr() ); - verify_noerr( err ); - - if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) ) +public: + wxMacStaticText( wxWindowMac* peer ) : wxMacControl(peer) { - TruncCode tCode = truncEnd; - if ( style & wxST_ELLIPSIZE_MIDDLE ) - tCode = truncMiddle; - - err = m_peer->SetData( kControlStaticTextTruncTag, tCode ); - err = m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); } - - MacPostControlCreate( pos, size ); - - SetLabel(label); - - return true; -} + void SetLabel(const wxString& title, wxFontEncoding encoding) + { + wxCFStringRef str( title, encoding ); + OSStatus err = SetData(kControlEntireControl, kControlStaticTextCFStringTag, str); + verify_noerr( err ); + } +}; wxSize wxStaticText::DoGetBestSize() const { - Rect bestsize = { 0 , 0 , 0 , 0 } ; Point bounds; +#if wxOSX_USE_CARBON + Rect bestsize = { 0 , 0 , 0 , 0 } ; // try the built-in best size if available - Boolean former = m_peer->GetData( kControlStaticTextIsMultilineTag); - m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); - m_peer->GetBestRect( &bestsize ) ; - m_peer->SetData( kControlStaticTextIsMultilineTag, former ); + Boolean former = GetPeer()->GetData( kControlStaticTextIsMultilineTag); + GetPeer()->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); + GetPeer()->GetBestRect( &bestsize ) ; + GetPeer()->SetData( kControlStaticTextIsMultilineTag, former ); + if ( !EmptyRect( &bestsize ) ) { bounds.h = bestsize.right - bestsize.left ; bounds.v = bestsize.bottom - bestsize.top ; } else +#endif { +#if wxOSX_USE_CARBON ControlFontStyleRec controlFont; - OSStatus err = m_peer->GetData( kControlEntireControl, kControlFontStyleTag, &controlFont ); + OSStatus err = GetPeer()->GetData( kControlEntireControl, kControlFontStyleTag, &controlFont ); verify_noerr( err ); - wxCFStringRef str( m_label, GetFont().GetEncoding() ); - #if wxOSX_USE_ATSU_TEXT SInt16 baseline; if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) { + // GetThemeTextDimensions will cache strings and the documentation + // says not to use the NoCopy string creation calls. + // This also means that we can't use CFSTR without + // -fno-constant-cfstrings if the library might be unloaded, + // as GetThemeTextDimensions may cache a pointer to our + // unloaded segment. + wxCFStringRef str( !m_label.empty() ? m_label : wxString(" "), + GetFont().GetEncoding() ); + err = GetThemeTextDimensions( - (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), + (CFStringRef)str, m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline ); verify_noerr( err ); } else +#endif #endif { wxClientDC dc(const_cast(this)); @@ -122,76 +104,38 @@ wxSize wxStaticText::DoGetBestSize() const return wxSize( bounds.h, bounds.v ); } -void wxStaticText::SetLabel(const wxString& label) -{ - m_labelOrig = label; +/* + FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set + to allow correct dynamic ellipsizing of the label +*/ - // middle/end ellipsization is handled by the OS: - if ( HasFlag(wxST_ELLIPSIZE_END) || HasFlag(wxST_ELLIPSIZE_MIDDLE) ) - { - // remove markup - wxString str(label); - if (HasFlag(wxST_MARKUP)) - str = RemoveMarkup(label); +wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID WXUNUSED(id), + const wxString& WXUNUSED(label), + const wxPoint& pos, + const wxSize& size, + long style, + long WXUNUSED(extraStyle)) +{ + Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); - // and leave ellipsization to the OS - DoSetLabel(str); - } - else // not supported natively - { - DoSetLabel(GetEllipsizedLabelWithoutMarkup()); - } + wxMacControl* peer = new wxMacStaticText( wxpeer ); + OSStatus err = CreateStaticTextControl( + MAC_WXHWND(parent->MacGetTopLevelWindowRef()), + &bounds, NULL, NULL, peer->GetControlRefAddr() ); + verify_noerr( err ); - if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) && - !IsEllipsized() ) // don't resize if we adjust to current size + if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) ) { - InvalidateBestSize(); - SetSize( GetBestSize() ); - } - - Refresh(); - - // we shouldn't need forced updates - // Update(); -} - -bool wxStaticText::SetFont(const wxFont& font) -{ - bool ret = wxControl::SetFont( font ); + TruncCode tCode = truncEnd; + if ( style & wxST_ELLIPSIZE_MIDDLE ) + tCode = truncMiddle; - if ( ret ) - { - if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) - { - InvalidateBestSize(); - SetSize( GetBestSize() ); - } + err = peer->SetData( kControlStaticTextTruncTag, tCode ); + err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); } - - return ret; -} - - -// for wxST_ELLIPSIZE_* support: - -void wxStaticText::DoSetLabel(const wxString& label) -{ - m_labelOrig = label; - m_label = RemoveMnemonics(label); - - wxCFStringRef str( m_label, GetFont().GetEncoding() ); - OSStatus err = m_peer->SetData(kControlEntireControl, kControlStaticTextCFStringTag, str); - verify_noerr( err ); + return peer; } -wxString wxStaticText::DoGetLabel() const -{ - return m_label; -} - -/* - FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set - to allow correct dynamic ellipsizing of the label -*/ - #endif //if wxUSE_STATTEXT