diff --git a/include/wx/osx/cocoa/private/markuptoattr.h b/include/wx/osx/cocoa/private/markuptoattr.h index 7ca0722ed4..abcdc8f92b 100644 --- a/include/wx/osx/cocoa/private/markuptoattr.h +++ b/include/wx/osx/cocoa/private/markuptoattr.h @@ -16,17 +16,20 @@ // wxMarkupToAttrString: create NSAttributedString from markup. // ---------------------------------------------------------------------------- -class wxMarkupToAttrString : public wxMarkupParserAttrOutput +class wxMarkupToAttrStringBase : public wxMarkupParserAttrOutput { -public: +protected: // We don't care about the original colours because we never use them but // we do need the correct initial font as we apply modifiers (e.g. create a // font larger than it) to it and so it must be valid. - wxMarkupToAttrString(const wxFont& font, const wxString& markup) - : wxMarkupParserAttrOutput(font, wxColour(), wxColour()) + wxMarkupToAttrStringBase(const wxFont& font) + : wxMarkupParserAttrOutput(font, wxColour(), wxColour()), + m_attrString(NULL) + {} + + void Parse(const wxFont& font, const wxString& markup) { - const wxCFStringRef - label(wxControl::RemoveMnemonics(wxMarkupParser::Strip(markup))); + const wxCFStringRef label(PrepareText(wxMarkupParser::Strip(markup))); m_attrString = [[NSMutableAttributedString alloc] initWithString: label.AsNSString()]; @@ -49,11 +52,16 @@ public: [m_attrString endEditing]; } - ~wxMarkupToAttrString() + ~wxMarkupToAttrStringBase() { - [m_attrString release]; + if ( m_attrString ) + [m_attrString release]; } + // prepare text chunk for display, e.g. strip mnemonics from it + virtual wxString PrepareText(const wxString& text) = 0; + +public: // Accessor for the users of this class. // // We keep ownership of the returned string. @@ -66,7 +74,7 @@ public: // Implement base class pure virtual methods to process markup tags. virtual void OnText(const wxString& text) { - m_pos += wxControl::RemoveMnemonics(text).length(); + m_pos += PrepareText(text).length(); } virtual void OnAttrStart(const Attr& WXUNUSED(attr)) @@ -111,9 +119,46 @@ private: // The positions of starting ranges. wxStack m_rangeStarts; +}; +// for use with labels with mnemonics +class wxMarkupToAttrString : public wxMarkupToAttrStringBase +{ +public: + wxMarkupToAttrString(const wxFont& font, const wxString& markup) + : wxMarkupToAttrStringBase(font) + { + Parse(font, markup); + } + +protected: + virtual wxString PrepareText(const wxString& text) + { + return wxControl::RemoveMnemonics(text); + } + wxDECLARE_NO_COPY_CLASS(wxMarkupToAttrString); }; + +// for raw markup with no mnemonics +class wxItemMarkupToAttrString : public wxMarkupToAttrStringBase +{ +public: + wxItemMarkupToAttrString(const wxFont& font, const wxString& markup) + : wxMarkupToAttrStringBase(font) + { + Parse(font, markup); + } + +protected: + virtual wxString PrepareText(const wxString& text) + { + return text; + } + + wxDECLARE_NO_COPY_CLASS(wxItemMarkupToAttrString); +}; + #endif // _WX_OSX_COCOA_PRIVATE_MARKUPTOATTR_H_ diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index ef7641d1d3..9d8a5d26d4 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2956,7 +2956,7 @@ bool wxDataViewTextRenderer::MacRender() #if wxUSE_MARKUP if ( m_useMarkup ) { - wxMarkupToAttrString toAttr(wxFont([cell font]), GetValue().GetString()); + wxItemMarkupToAttrString toAttr(wxFont([cell font]), GetValue().GetString()); NSMutableAttributedString *str = toAttr.GetNSAttributedString(); if ( [cell lineBreakMode] != NSLineBreakByClipping )