Support ellipsizing of markup text in wxDVC
Fix wxDataViewTextRenderer to at least partially respect ellipsize mode when using markup text. Generic implementation only supports wxELLIPSIZE_END and wxELLIPSIZE_NONE at the moment, but the wxOSX and wxGTK ones have full support.
This commit is contained in:
parent
92a1f643ba
commit
58fc33d7c2
@ -11,9 +11,9 @@
|
||||
#define _WX_GENERIC_PRIVATE_MARKUPTEXT_H_
|
||||
|
||||
#include "wx/defs.h"
|
||||
#include "wx/gdicmn.h"
|
||||
|
||||
class WXDLLIMPEXP_FWD_CORE wxDC;
|
||||
class WXDLLIMPEXP_FWD_CORE wxRect;
|
||||
|
||||
class wxMarkupParserOutput;
|
||||
|
||||
@ -84,10 +84,14 @@ public:
|
||||
// The meaning of the flags here is different than in the overload above:
|
||||
// they're passed to DrawItemText() and Render_ShowAccels is not supported
|
||||
// here.
|
||||
//
|
||||
// Currently the only supported ellipsize modes are wxELLIPSIZE_NONE and
|
||||
// wxELLIPSIZE_END, the others are treated as wxELLIPSIZE_END.
|
||||
void RenderItemText(wxWindow *win,
|
||||
wxDC& dc,
|
||||
const wxRect& rect,
|
||||
int rendererFlags);
|
||||
int rendererFlags,
|
||||
wxEllipsizeMode ellipsizeMode);
|
||||
|
||||
private:
|
||||
wxString m_markup;
|
||||
|
@ -1095,7 +1095,7 @@ bool wxDataViewTextRenderer::Render(wxRect rect, wxDC *dc, int state)
|
||||
int flags = 0;
|
||||
if ( state & wxDATAVIEW_CELL_SELECTED )
|
||||
flags |= wxCONTROL_SELECTED;
|
||||
m_markupText->RenderItemText(GetView(), *dc, rect, flags);
|
||||
m_markupText->RenderItemText(GetView(), *dc, rect, flags, GetEllipsizeMode());
|
||||
}
|
||||
else
|
||||
#endif // wxUSE_MARKUP
|
||||
|
@ -237,18 +237,22 @@ public:
|
||||
wxMarkupParserRenderItemOutput(wxWindow *win,
|
||||
wxDC& dc,
|
||||
const wxRect& rect,
|
||||
int rendererFlags)
|
||||
int rendererFlags,
|
||||
wxEllipsizeMode ellipsizeMode)
|
||||
: wxMarkupParserRenderOutput(dc, rect, wxMarkupText::Render_Default),
|
||||
m_win(win),
|
||||
m_rendererFlags(rendererFlags),
|
||||
m_renderer(&wxRendererNative::Get())
|
||||
{
|
||||
// TODO: Support all ellipsizing modes
|
||||
m_ellipsizeMode = ellipsizeMode == wxELLIPSIZE_NONE ? wxELLIPSIZE_NONE : wxELLIPSIZE_END;
|
||||
}
|
||||
|
||||
virtual void OnText(const wxString& text) wxOVERRIDE
|
||||
{
|
||||
wxRect rect(m_rect);
|
||||
rect.x = m_pos;
|
||||
rect.SetRight(m_rect.GetRight());
|
||||
|
||||
m_renderer->DrawItemText(m_win,
|
||||
m_dc,
|
||||
@ -256,7 +260,7 @@ public:
|
||||
rect,
|
||||
wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL,
|
||||
m_rendererFlags,
|
||||
wxELLIPSIZE_NONE);
|
||||
m_ellipsizeMode);
|
||||
|
||||
m_pos += m_dc.GetTextExtent(text).x;
|
||||
}
|
||||
@ -264,6 +268,7 @@ public:
|
||||
private:
|
||||
wxWindow* const m_win;
|
||||
int const m_rendererFlags;
|
||||
wxEllipsizeMode m_ellipsizeMode;
|
||||
wxRendererNative* const m_renderer;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxMarkupParserRenderItemOutput);
|
||||
@ -310,9 +315,10 @@ void wxMarkupText::Render(wxDC& dc, const wxRect& rect, int flags)
|
||||
void wxMarkupText::RenderItemText(wxWindow *win,
|
||||
wxDC& dc,
|
||||
const wxRect& rect,
|
||||
int rendererFlags)
|
||||
int rendererFlags,
|
||||
wxEllipsizeMode ellipsizeMode)
|
||||
{
|
||||
wxMarkupParserRenderItemOutput out(win, dc, rect, rendererFlags);
|
||||
wxMarkupParserRenderItemOutput out(win, dc, rect, rendererFlags, ellipsizeMode);
|
||||
wxMarkupParser parser(out);
|
||||
parser.Parse(m_markup);
|
||||
}
|
||||
|
@ -2825,17 +2825,29 @@ void wxDataViewTextRenderer::EnableMarkup(bool enable)
|
||||
|
||||
bool wxDataViewTextRenderer::MacRender()
|
||||
{
|
||||
NSCell *cell = GetNativeData()->GetItemCell();
|
||||
#if wxUSE_MARKUP
|
||||
if ( m_useMarkup )
|
||||
{
|
||||
wxMarkupToAttrString toAttr(GetView(), GetValue().GetString());
|
||||
NSMutableAttributedString *str = toAttr.GetNSAttributedString();
|
||||
|
||||
[GetNativeData()->GetItemCell() setAttributedStringValue:toAttr.GetNSAttributedString()];
|
||||
if ( [cell lineBreakMode] != NSLineBreakByClipping )
|
||||
{
|
||||
NSMutableParagraphStyle *par = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
|
||||
[par setLineBreakMode:[cell lineBreakMode]];
|
||||
[str addAttribute:NSParagraphStyleAttributeName
|
||||
value:par
|
||||
range:NSMakeRange(0, [str length])];
|
||||
[par release];
|
||||
}
|
||||
|
||||
[cell setAttributedStringValue:str];
|
||||
return true;
|
||||
}
|
||||
#endif // wxUSE_MARKUP
|
||||
|
||||
[GetNativeData()->GetItemCell() setObjectValue:wxCFStringRef(GetValue().GetString()).AsNSString()];
|
||||
[cell setObjectValue:wxCFStringRef(GetValue().GetString()).AsNSString()];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user