Fix handling of & in wxDataViewCtrl markup on wxOSX
Follow up to 60bd6842e4
. Apply equivalent
changes to wxMarkupToAttrString, add a new wxItemMarkupToAttrString
class for mnemonics-less strings and use it in wxDataViewTextRenderer.
This commit is contained in:
parent
f18d14ce77
commit
11f79cda31
@ -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<unsigned> 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_
|
||||
|
@ -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 )
|
||||
|
Loading…
Reference in New Issue
Block a user