Account for text attrs in generic wxDataViewCtrl's renderers.

When determining cell content's size, GetSize() measured the text using
wxDataViewCtrl's font, even though it could be renderer in bold or
italics.

Corrected by setting the attributes - and not only the value - prior to
GetSize() calls, and by using the right font in GetTextExtent() calls.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65949 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2010-10-30 15:57:49 +00:00
parent d0154e3a5a
commit 86755098f5
4 changed files with 83 additions and 31 deletions

View File

@@ -69,6 +69,24 @@ private:
} // anonymous namespace
// ---------------------------------------------------------
// wxDataViewItemAttr
// ---------------------------------------------------------
wxFont wxDataViewItemAttr::GetEffectiveFont(const wxFont& font) const
{
if ( !HasFont() )
return font;
wxFont f(font);
if ( GetBold() )
f.MakeBold();
if ( GetItalic() )
f.MakeItalic();
return f;
}
// ---------------------------------------------------------
// wxDataViewModelNotifier
// ---------------------------------------------------------
@@ -826,19 +844,28 @@ wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell, wxDC *dc, int state)
wxDCFontChanger changeFont(*dc);
if ( m_attr.HasFont() )
{
wxFont font(dc->GetFont());
if ( m_attr.GetBold() )
font.MakeBold();
if ( m_attr.GetItalic() )
font.MakeItalic();
changeFont.Set(font);
}
changeFont.Set(m_attr.GetEffectiveFont(dc->GetFont()));
Render(rectItem, dc, state);
}
wxSize wxDataViewCustomRendererBase::GetTextExtent(const wxString& str) const
{
const wxDataViewCtrl *view = GetView();
if ( m_attr.HasFont() )
{
wxFont font(m_attr.GetEffectiveFont(view->GetFont()));
wxSize size;
view->GetTextExtent(str, &size.x, &size.y, NULL, NULL, &font);
return size;
}
else
{
return view->GetTextExtent(str);
}
}
void
wxDataViewCustomRendererBase::RenderText(const wxString& text,
int xoffset,