X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f0c8f31f407ecfce909060464c0ea655221cdab..b3b17ee74390803c2743455f5f3c744a2dd392ea:/src/osx/carbon/stattext.cpp diff --git a/src/osx/carbon/stattext.cpp b/src/osx/carbon/stattext.cpp index 6763b3afee..90765430e8 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,58 +23,29 @@ #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); @@ -87,23 +58,33 @@ wxSize wxStaticText::DoGetBestSize() const bounds.v = bestsize.bottom - bestsize.top ; } else +#endif { +#if wxOSX_USE_CARBON ControlFontStyleRec controlFont; OSStatus err = m_peer->GetData( kControlEntireControl, kControlFontStyleTag, &controlFont ); verify_noerr( err ); - wxCFStringRef str( m_label, GetFont().GetEncoding() ); - -#if wxMAC_USE_ATSU_TEXT +#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 +103,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