Add wxWithImages::GetImageLogicalSize() helper too

This is similar to the just added GetImageBitmapFor() and works both
when using legacy wxImageList and wxBitmapBundle.

Use the new function in wxGenericTreeCtrl code.
This commit is contained in:
Vadim Zeitlin 2022-10-18 18:03:18 +02:00
parent 306a982e9a
commit 65e4be6f82
2 changed files with 38 additions and 7 deletions

View file

@ -129,6 +129,37 @@ public:
return m_imageList;
}
// Return logical size of the image to use or (0, 0) if there are none.
wxSize GetImageLogicalSize(const wxWindow* window, int iconIndex) const
{
wxSize size;
if ( iconIndex != NO_IMAGE )
{
if ( !m_images.empty() )
{
size = m_images.at(iconIndex).GetPreferredLogicalSizeFor(window);
}
else if ( m_imageList )
{
// All images in the image list are of the same size.
size = m_imageList->GetSize();
}
}
return size;
}
// Overload provided to facilitate transition from the existing code using
// wxImageList::GetSize() -- don't use it in the new code.
void GetImageLogicalSize(const wxWindow* window, int iconIndex,
int& width, int& height) const
{
const wxSize size = GetImageLogicalSize(window, iconIndex);
width = size.x;
height = size.y;
}
// Return the bitmap to use at the current DPI of the given window.
//
// If index == NO_IMAGE, just returns wxNullBitmap.

View file

@ -714,7 +714,7 @@ wxGenericTreeItem *wxGenericTreeItem::HitTest(const wxPoint& point,
if ( (GetImage() != NO_IMAGE) && theCtrl->HasImages() )
{
int image_h;
theCtrl->GetImageList()->GetSize(GetImage(),
theCtrl->GetImageLogicalSize(theCtrl, GetImage(),
image_w, image_h);
}
@ -851,7 +851,7 @@ wxGenericTreeItem::DoCalculateSize(wxGenericTreeCtrl* control,
int image = GetCurrentImage();
if ( image != NO_IMAGE && control->HasImages() )
{
control->GetImageList()->GetSize(image, image_w, image_h);
control->GetImageLogicalSize(control, image, image_w, image_h);
image_w += MARGIN_BETWEEN_IMAGE_AND_TEXT;
}
@ -2385,7 +2385,7 @@ void wxGenericTreeCtrl::CalculateLineHeight()
for (int i = 0; i < n ; i++)
{
int width = 0, height = 0;
GetImageList()->GetSize(i, width, height);
GetImageLogicalSize(this, i, width, height);
if (height > m_lineHeight) m_lineHeight = height;
}
}
@ -2399,7 +2399,7 @@ void wxGenericTreeCtrl::CalculateLineHeight()
for (int i = 0; i < n ; i++)
{
int width = 0, height = 0;
m_imagesState.GetImageList()->GetSize(i, width, height);
m_imagesState.GetImageLogicalSize(this, i, width, height);
if (height > m_lineHeight) m_lineHeight = height;
}
}
@ -2413,7 +2413,7 @@ void wxGenericTreeCtrl::CalculateLineHeight()
for (int i = 0; i < n ; i++)
{
int width = 0, height = 0;
m_imagesButtons.GetImageList()->GetSize(i, width, height);
m_imagesButtons.GetImageLogicalSize(this, i, width, height);
if (height > m_lineHeight) m_lineHeight = height;
}
}
@ -2517,7 +2517,7 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
{
if ( HasImages() )
{
GetImageList()->GetSize(image, image_w, image_h);
GetImageLogicalSize(this, image, image_w, image_h);
image_w += MARGIN_BETWEEN_IMAGE_AND_TEXT;
}
else
@ -3446,7 +3446,7 @@ bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId& item,
if ( image != NO_IMAGE && HasImages() )
{
int image_h;
GetImageList()->GetSize( image, image_w, image_h );
GetImageLogicalSize( this, image, image_w, image_h );
image_w += MARGIN_BETWEEN_IMAGE_AND_TEXT;
}