Fix handling of ampersands in wxDataViewCtrl markup
Handle "&" in exactly the same way as "&" in wxMarkupParser, i.e. do not map the former to "&&" to prevent it from being interpreted as a mnemonic as this is incompatible with using markup for anything but the control labels, e.g. for wxDataViewCtrl items text, in which mnemonics are not recognized. And even when using markup for control labels, it was a questionable decision as it's really not clear at all why should the XML entity and the raw character itself be handled differently. Also split wxMarkupText into two classes, wxMarkupText that handles mnemonics in the markup (which is typically a label) and a very similar, but not derived, wxItemMarkupText that handles mnemonics-less markup for list etc. items, uses DrawItemText() and supports ellipsizing. Illustrate the use of ampersands in the dataview sample.
This commit is contained in:
committed by
Václav Slavík
parent
0e2f6f6ec0
commit
60bd6842e4
@@ -66,10 +66,8 @@ public:
|
||||
const wxSize& GetSize() const { return m_size; }
|
||||
|
||||
|
||||
virtual void OnText(const wxString& text_) wxOVERRIDE
|
||||
virtual void OnText(const wxString& text) wxOVERRIDE
|
||||
{
|
||||
const wxString text(wxControl::RemoveMnemonics(text_));
|
||||
|
||||
// TODO-MULTILINE-MARKUP: Must use GetMultiLineTextExtent().
|
||||
const wxSize size = m_dc.GetTextExtent(text);
|
||||
|
||||
@@ -253,10 +251,8 @@ public:
|
||||
m_ellipsizeMode = ellipsizeMode == wxELLIPSIZE_NONE ? wxELLIPSIZE_NONE : wxELLIPSIZE_END;
|
||||
}
|
||||
|
||||
virtual void OnText(const wxString& text_) wxOVERRIDE
|
||||
virtual void OnText(const wxString& text) wxOVERRIDE
|
||||
{
|
||||
const wxString text(wxControl::RemoveMnemonics(text_));
|
||||
|
||||
wxRect rect(m_rect);
|
||||
rect.x = m_pos;
|
||||
rect.SetRight(m_rect.GetRight());
|
||||
@@ -315,16 +311,11 @@ private:
|
||||
// wxMarkupText implementation
|
||||
// ============================================================================
|
||||
|
||||
void wxMarkupText::SetMarkupText(const wxString& markup)
|
||||
{
|
||||
m_markup = wxControl::EscapeMnemonics(markup);
|
||||
}
|
||||
|
||||
wxSize wxMarkupText::Measure(wxDC& dc, int *visibleHeight) const
|
||||
wxSize wxMarkupTextBase::Measure(wxDC& dc, int *visibleHeight) const
|
||||
{
|
||||
wxMarkupParserMeasureOutput out(dc, visibleHeight);
|
||||
wxMarkupParser parser(out);
|
||||
if ( !parser.Parse(m_markup) )
|
||||
if ( !parser.Parse(GetMarkupForMeasuring()) )
|
||||
{
|
||||
wxFAIL_MSG( "Invalid markup" );
|
||||
return wxDefaultSize;
|
||||
@@ -333,6 +324,11 @@ wxSize wxMarkupText::Measure(wxDC& dc, int *visibleHeight) const
|
||||
return out.GetSize();
|
||||
}
|
||||
|
||||
wxString wxMarkupText::GetMarkupForMeasuring() const
|
||||
{
|
||||
return wxControl::RemoveMnemonics(m_markup);
|
||||
}
|
||||
|
||||
void wxMarkupText::Render(wxDC& dc, const wxRect& rect, int flags)
|
||||
{
|
||||
// We want to center the above-baseline parts of the letter vertically, so
|
||||
@@ -347,11 +343,16 @@ void wxMarkupText::Render(wxDC& dc, const wxRect& rect, int flags)
|
||||
parser.Parse(m_markup);
|
||||
}
|
||||
|
||||
void wxMarkupText::RenderItemText(wxWindow *win,
|
||||
wxDC& dc,
|
||||
const wxRect& rect,
|
||||
int rendererFlags,
|
||||
wxEllipsizeMode ellipsizeMode)
|
||||
|
||||
// ============================================================================
|
||||
// wxItemMarkupText implementation
|
||||
// ============================================================================
|
||||
|
||||
void wxItemMarkupText::Render(wxWindow *win,
|
||||
wxDC& dc,
|
||||
const wxRect& rect,
|
||||
int rendererFlags,
|
||||
wxEllipsizeMode ellipsizeMode)
|
||||
{
|
||||
wxMarkupParserRenderItemOutput out(win, dc, rect, rendererFlags, ellipsizeMode);
|
||||
wxMarkupParser parser(out);
|
||||
|
Reference in New Issue
Block a user