Use wxBitmapBundle in wxDataViewCtrl-related classes

Extend the existing use of wxIcon in wxDataViewIconText,
wxDataViewCheckIconText, the corresponding renderers and
wxDataViewTreeCtrl to wxBitmapBundle.

As with the other classes, the existing setters have been preserved as
they remain almost entirely compatible with the existing code and the
return type of the existing getters was preserved, with new getters
being introduced for returning wxBitmapBundle only where they're really
required.

Update the sample to use wxBitmapBundle with its wxDataViewTreeCtrl.
This commit is contained in:
Vadim Zeitlin
2022-01-23 00:52:45 +00:00
parent 90bbde8777
commit 4073f3b9bf
10 changed files with 173 additions and 174 deletions

View File

@@ -1553,11 +1553,13 @@ bool wxDataViewIconTextRenderer::Render(wxRect rect, wxDC *dc, int state)
{
int xoffset = 0;
const wxIcon& icon = m_value.GetIcon();
if ( icon.IsOk() )
const wxBitmapBundle& bb = m_value.GetBitmapBundle();
if ( bb.IsOk() )
{
dc->DrawIcon(icon, rect.x, rect.y + (rect.height - icon.GetHeight())/2);
xoffset = icon.GetWidth() + GetView()->FromDIP(4);
wxWindow* const dvc = GetView();
const wxIcon& icon = bb.GetIconFor(dvc);
dc->DrawIcon(icon, rect.x, rect.y + (rect.height - icon.GetLogicalHeight())/2);
xoffset = icon.GetLogicalWidth() + dvc->FromDIP(4);
}
RenderText(m_value.GetText(), xoffset, rect, dc, state);
@@ -1573,8 +1575,9 @@ wxSize wxDataViewIconTextRenderer::GetSize() const
{
wxSize size = GetTextExtent(m_value.GetText());
if (m_value.GetIcon().IsOk())
size.x += m_value.GetIcon().GetWidth() + dvc->FromDIP(4);
const wxBitmapBundle& bb = m_value.GetBitmapBundle();
if (bb.IsOk())
size.x += bb.GetPreferredSizeFor(dvc).x + dvc->FromDIP(4);
return size;
}
return dvc->FromDIP(wxSize(80,20));
@@ -1588,11 +1591,12 @@ wxWindow* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect
wxString text = iconText.GetText();
// adjust the label rect to take the width of the icon into account
if (iconText.GetIcon().IsOk())
const wxBitmapBundle& bb = iconText.GetBitmapBundle();
if (bb.IsOk())
{
wxWindow* const dvc = GetView();
int w = iconText.GetIcon().GetWidth() + dvc->FromDIP(4);
int w = bb.GetPreferredSizeFor(dvc).x + dvc->FromDIP(4);
labelRect.x += w;
labelRect.width -= w;
}