Accept wxBitmapBundle in wxDataViewBitmapRenderer too

This allows returning the entire bundle from the model GetValue()
function to let the renderer itself to select the best matching bitmap
to use.
This commit is contained in:
Vadim Zeitlin
2022-05-08 18:37:00 +01:00
parent 5556ea8429
commit 8d3e7fd346
3 changed files with 36 additions and 9 deletions

View File

@@ -1317,7 +1317,11 @@ wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype,
bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value ) bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value )
{ {
if (value.GetType() == wxT("wxBitmap")) if (value.GetType() == wxT("wxBitmapBundle"))
{
m_bitmapBundle << value;
}
else if (value.GetType() == wxT("wxBitmap"))
{ {
wxBitmap bitmap; wxBitmap bitmap;
bitmap << value; bitmap << value;
@@ -1346,7 +1350,8 @@ bool
wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const
{ {
// We can accept values of any types checked by SetValue(). // We can accept values of any types checked by SetValue().
return variantType == wxS("wxBitmap") return variantType == wxS("wxBitmapBundle")
|| variantType == wxS("wxBitmap")
|| variantType == wxS("wxIcon"); || variantType == wxS("wxIcon");
} }

View File

@@ -2569,22 +2569,32 @@ wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype,
bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value ) bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value )
{ {
wxBitmap bitmap; wxBitmapBundle bitmapBundle;
if (value.GetType() == wxS("wxBitmap")) if (value.GetType() == wxS("wxBitmapBundle"))
{ {
bitmapBundle << value;
}
else if (value.GetType() == wxS("wxBitmap"))
{
wxBitmap bitmap;
bitmap << value; bitmap << value;
bitmapBundle = wxBitmapBundle(bitmap);
} }
else if (value.GetType() == wxS("wxIcon")) else if (value.GetType() == wxS("wxIcon"))
{ {
wxIcon icon; wxIcon icon;
icon << value; icon << value;
bitmap.CopyFromIcon(icon); bitmapBundle = wxBitmapBundle(icon);
} }
#ifdef __WXGTK3__ #ifdef __WXGTK3__
WX_CELL_RENDERER_PIXBUF(m_renderer)->Set(bitmap); WX_CELL_RENDERER_PIXBUF(m_renderer)->Set(bitmapBundle);
#else #else
g_object_set(G_OBJECT(m_renderer), "pixbuf", bitmap.IsOk() ? bitmap.GetPixbuf() : NULL, NULL); g_object_set(G_OBJECT(m_renderer),
"pixbuf",
bitmapBundle.IsOk() ? bitmapBundle.GetBitmap(wxDefaultSize).GetPixbuf()
: NULL,
NULL);
#endif #endif
return true; return true;
@@ -2599,7 +2609,8 @@ bool
wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const
{ {
// We can accept values of any types checked by SetValue(). // We can accept values of any types checked by SetValue().
return variantType == wxS("wxBitmap") return variantType == wxS("wxBitmapBundle")
|| variantType == wxS("wxBitmap")
|| variantType == wxS("wxIcon"); || variantType == wxS("wxIcon");
} }

View File

@@ -28,6 +28,9 @@
#include "wx/osx/private/available.h" #include "wx/osx/private/available.h"
#include "wx/osx/private/datatransfer.h" #include "wx/osx/private/datatransfer.h"
#include "wx/osx/cocoa/dataview.h" #include "wx/osx/cocoa/dataview.h"
#include "wx/private/bmpbndl.h"
#include "wx/renderer.h" #include "wx/renderer.h"
#include "wx/stopwatch.h" #include "wx/stopwatch.h"
#include "wx/dcgraph.h" #include "wx/dcgraph.h"
@@ -2983,6 +2986,13 @@ wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(const wxString& varianttype,
bool wxDataViewBitmapRenderer::MacRender() bool wxDataViewBitmapRenderer::MacRender()
{ {
if (GetValue().GetType() == wxS("wxBitmap")) if (GetValue().GetType() == wxS("wxBitmap"))
{
wxBitmapBundle bundle;
bundle << GetValue();
if (bundle.IsOk())
[GetNativeData()->GetItemCell() setObjectValue:wxOSXGetImageFromBundle(bundle)];
}
else if (GetValue().GetType() == wxS("wxBitmap"))
{ {
wxBitmap bitmap; wxBitmap bitmap;
bitmap << GetValue(); bitmap << GetValue();
@@ -3003,7 +3013,8 @@ bool
wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const
{ {
// We can accept values of any types checked by SetValue(). // We can accept values of any types checked by SetValue().
return variantType == wxS("wxBitmap") return variantType == wxS("wxBitmapBundle")
|| variantType == wxS("wxBitmap")
|| variantType == wxS("wxIcon"); || variantType == wxS("wxIcon");
} }