From dc90e92110c5e844c821bf0ae970b594a8ead6a5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 May 2022 15:54:51 +0100 Subject: [PATCH 1/8] Add wxBitmapBundle::Clear() This is just a convenient helper for resetting the bundle contents which seems more readable than assigning an empty bundle to it. --- include/wx/bmpbndl.h | 3 +++ interface/wx/bmpbndl.h | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/wx/bmpbndl.h b/include/wx/bmpbndl.h index 312b978c5c..2f2f099680 100644 --- a/include/wx/bmpbndl.h +++ b/include/wx/bmpbndl.h @@ -108,6 +108,9 @@ public: // Check if bitmap bundle is non-empty. bool IsOk() const { return m_impl.get() != NULL; } + // Clear the bundle contents, IsOk() will return false after doing this. + void Clear() { m_impl.reset(NULL); } + // Get the size of the bitmap represented by this bundle when using the // default DPI, i.e. 100% scaling. Returns invalid size for empty bundle. wxSize GetDefaultSize() const; diff --git a/interface/wx/bmpbndl.h b/interface/wx/bmpbndl.h index e78c900f2e..901b56d20b 100644 --- a/interface/wx/bmpbndl.h +++ b/interface/wx/bmpbndl.h @@ -288,6 +288,18 @@ public: */ static wxBitmapBundle FromSVGResource(const wxString& name, const wxSize& sizeDef); + /** + Clear the existing bundle contents. + + After calling this function IsOk() returns @false. + + This is the same as assigning a default-constructed bitmap bundle to + this object but slightly more explicit. + + @since 3.1.7 + */ + void Clear(); + /** Check if bitmap bundle is non-empty. From eb361a182af45d0d8dafa3137e9d126e3d5c4c63 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 May 2022 15:55:34 +0100 Subject: [PATCH 2/8] Use a single wxBitmapBundle in wxDataViewBitmapRenderer Instead of using either a wxBitmap or a wxIcon, always use the same wxBitmapBundle object to store whatever we are rendering. This slightly simplifies the code and prepares for further changes, but nothing real changes yet. --- include/wx/generic/dvrenderers.h | 3 +-- src/generic/datavgen.cpp | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/wx/generic/dvrenderers.h b/include/wx/generic/dvrenderers.h index 1f23fdee3a..52f6220ba6 100644 --- a/include/wx/generic/dvrenderers.h +++ b/include/wx/generic/dvrenderers.h @@ -112,8 +112,7 @@ public: virtual wxSize GetSize() const wxOVERRIDE; private: - wxIcon m_icon; - wxBitmap m_bitmap; + wxBitmapBundle m_bitmapBundle; protected: wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer); diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index b2be0be0d0..a395660b78 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -1319,16 +1319,19 @@ bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value ) { if (value.GetType() == wxT("wxBitmap")) { - m_bitmap << value; + wxBitmap bitmap; + bitmap << value; + m_bitmapBundle = wxBitmapBundle(bitmap); } else if (value.GetType() == wxT("wxIcon")) { - m_icon << value; + wxIcon icon; + icon << value; + m_bitmapBundle = wxBitmapBundle(icon); } else { - m_icon = wxNullIcon; - m_bitmap = wxNullBitmap; + m_bitmapBundle.Clear(); } return true; @@ -1348,20 +1351,20 @@ wxString wxDataViewBitmapRenderer::GetAccessibleDescription() const bool wxDataViewBitmapRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) ) { - if (m_bitmap.IsOk()) - dc->DrawBitmap( m_bitmap, cell.x, cell.y, true /* use mask */ ); - else if (m_icon.IsOk()) - dc->DrawIcon( m_icon, cell.x, cell.y ); + if (m_bitmapBundle.IsOk()) + { + dc->DrawBitmap( m_bitmapBundle.GetBitmapFor(GetView()), + cell.x, cell.y, + true /* use mask */ ); + } return true; } wxSize wxDataViewBitmapRenderer::GetSize() const { - if (m_bitmap.IsOk()) - return wxSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() ); - else if (m_icon.IsOk()) - return wxSize( m_icon.GetWidth(), m_icon.GetHeight() ); + if (m_bitmapBundle.IsOk()) + return m_bitmapBundle.GetPreferredBitmapSizeFor(GetView()); return GetView()->FromDIP(wxSize(wxDVC_DEFAULT_RENDERER_SIZE, wxDVC_DEFAULT_RENDERER_SIZE)); From 23e815bcf6e98334cc4da9e5043f549ccd51b56e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 May 2022 18:32:46 +0100 Subject: [PATCH 3/8] Allow relaxing the check for variant type in wxDataViewRenderer Instead of checking for the exact variant type match, call the new IsCompatibleVariantType() virtual function, which still does the same check by default, but can be overridden to allow other types as well if they're accepted by the renderer. This will be soon used to allow accepting both wxBitmap (which must still be accepted for compatibility) and wxBitmapBundle (which is the simplest way to support high DPI) in wxDataViewBitmapRenderer at once. --- include/wx/dvrenderers.h | 14 ++++++++++++-- interface/wx/dataview.h | 13 +++++++++++++ src/common/datavcmn.cpp | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/wx/dvrenderers.h b/include/wx/dvrenderers.h index 4de42f3b14..f1b3fc1c04 100644 --- a/include/wx/dvrenderers.h +++ b/include/wx/dvrenderers.h @@ -155,6 +155,15 @@ public: wxString GetVariantType() const { return m_variantType; } + // Check if the given variant type is compatible with the type expected by + // this renderer: by default, just compare it with GetVariantType(), but + // can be overridden to accept other types that can be converted to the + // type needed by the renderer. + virtual bool IsCompatibleVariantType(const wxString& variantType) const + { + return variantType == GetVariantType(); + } + // Prepare for rendering the value of the corresponding item in the given // column taken from the provided non-null model. // @@ -163,8 +172,9 @@ public: // it and should probably be removed in the future. // // Return true if this cell is non-empty or false otherwise (and also if - // the model returned a value of the wrong, i.e. different from our - // GetVariantType(), type, in which case a debug error is also logged). + // the model returned a value of the wrong type, i.e. such that our + // IsCompatibleVariantType() returned false for it, in which case a debug + // error is also logged). bool PrepareForItem(const wxDataViewModel *model, const wxDataViewItem& item, unsigned column); diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index fa26279b2c..563a6ad1b4 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -2064,6 +2064,19 @@ public: */ wxString GetVariantType() const; + /** + Check if the given variant type is compatible with the type expected by + this renderer. + + The base class implementation just compares @a variantType with the + value returned by GetVariantType(), but this function can be overridden + to accept other types that can be converted to the type needed by the + renderer. + + @since 3.1.7 + */ + virtual bool IsCompatibleVariantType(const wxString& variantType) const; + /** Sets the alignment of the renderer's content. The default value of @c wxDVR_DEFAULT_ALIGNMENT indicates that the content diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index db60a89eda..10ce375710 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -861,7 +861,7 @@ wxDataViewRendererBase::CheckedGetValue(const wxDataViewModel* model, // We always allow the cell to be null, regardless of the renderer type. if ( !value.IsNull() ) { - if ( value.GetType() != GetVariantType() ) + if ( !IsCompatibleVariantType(value.GetType()) ) { // If you're seeing this message, this indicates that either your // renderer is using the wrong type, or your model returns values From d8abdfbdeec834e5be8aa9a69bf7921421a4cbf8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 May 2022 18:35:55 +0100 Subject: [PATCH 4/8] Accept either bitmaps or icons in wxDataViewBitmapRenderer Allow using either wxBitmap or wxIcon in wxDataViewBitmapRenderer independently of the type the renderer was created with because this is convenient and there is no real danger in allowing to mix and match bitmaps and icons together. Override the just added IsCompatibleVariantType() to implement this. --- include/wx/generic/dvrenderers.h | 4 ++++ include/wx/gtk/dvrenderers.h | 3 +++ include/wx/osx/dvrenderers.h | 3 +++ include/wx/qt/dvrenderers.h | 2 ++ src/generic/datavgen.cpp | 8 ++++++++ src/gtk/dataview.cpp | 8 ++++++++ src/osx/cocoa/dataview.mm | 8 ++++++++ src/qt/dvrenderers.cpp | 7 +++++++ 8 files changed, 43 insertions(+) diff --git a/include/wx/generic/dvrenderers.h b/include/wx/generic/dvrenderers.h index 52f6220ba6..a02a1a5b28 100644 --- a/include/wx/generic/dvrenderers.h +++ b/include/wx/generic/dvrenderers.h @@ -104,6 +104,10 @@ public: virtual bool SetValue( const wxVariant &value ) wxOVERRIDE; virtual bool GetValue( wxVariant &value ) const wxOVERRIDE; + + virtual + bool IsCompatibleVariantType(const wxString& variantType) const wxOVERRIDE; + #if wxUSE_ACCESSIBILITY virtual wxString GetAccessibleDescription() const wxOVERRIDE; #endif // wxUSE_ACCESSIBILITY diff --git a/include/wx/gtk/dvrenderers.h b/include/wx/gtk/dvrenderers.h index e81a5b5a63..1deadc3b33 100644 --- a/include/wx/gtk/dvrenderers.h +++ b/include/wx/gtk/dvrenderers.h @@ -90,6 +90,9 @@ public: bool SetValue( const wxVariant &value ) wxOVERRIDE; bool GetValue( wxVariant &value ) const wxOVERRIDE; + virtual + bool IsCompatibleVariantType(const wxString& variantType) const wxOVERRIDE; + protected: wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer); }; diff --git a/include/wx/osx/dvrenderers.h b/include/wx/osx/dvrenderers.h index a854a3f112..832d789d33 100644 --- a/include/wx/osx/dvrenderers.h +++ b/include/wx/osx/dvrenderers.h @@ -110,6 +110,9 @@ public: wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align = wxDVR_DEFAULT_ALIGNMENT); + virtual + bool IsCompatibleVariantType(const wxString& variantType) const wxOVERRIDE; + virtual bool MacRender() wxOVERRIDE; private: diff --git a/include/wx/qt/dvrenderers.h b/include/wx/qt/dvrenderers.h index 6ae3e527a6..b156b4425d 100644 --- a/include/wx/qt/dvrenderers.h +++ b/include/wx/qt/dvrenderers.h @@ -42,6 +42,8 @@ public: bool SetValue( const wxVariant &value ); bool GetValue( wxVariant &value ) const; + + bool IsCompatibleVariantType(const wxString& variantType) const; }; // --------------------------------------------------------- diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index a395660b78..88f6ff1a0d 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -1342,6 +1342,14 @@ bool wxDataViewBitmapRenderer::GetValue( wxVariant& WXUNUSED(value) ) const return false; } +bool +wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const +{ + // We can accept values of any types checked by SetValue(). + return variantType == wxS("wxBitmap") + || variantType == wxS("wxIcon"); +} + #if wxUSE_ACCESSIBILITY wxString wxDataViewBitmapRenderer::GetAccessibleDescription() const { diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 22f7f25cc3..e537ba10d7 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -2595,6 +2595,14 @@ bool wxDataViewBitmapRenderer::GetValue( wxVariant &WXUNUSED(value) ) const return false; } +bool +wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const +{ + // We can accept values of any types checked by SetValue(). + return variantType == wxS("wxBitmap") + || variantType == wxS("wxIcon"); +} + // --------------------------------------------------------- // wxDataViewToggleRenderer // --------------------------------------------------------- diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 095ff20a12..d2b8f14d11 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2999,6 +2999,14 @@ bool wxDataViewBitmapRenderer::MacRender() return true; } +bool +wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const +{ + // We can accept values of any types checked by SetValue(). + return variantType == wxS("wxBitmap") + || variantType == wxS("wxIcon"); +} + wxIMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewRenderer); // ------------------------------------- diff --git a/src/qt/dvrenderers.cpp b/src/qt/dvrenderers.cpp index c552325f83..66f70541be 100644 --- a/src/qt/dvrenderers.cpp +++ b/src/qt/dvrenderers.cpp @@ -54,6 +54,13 @@ bool wxDataViewBitmapRenderer::GetValue( wxVariant &value ) const return false; } +bool +wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const +{ + return variantType == wxS("wxBitmap") + || variantType == wxS("wxIcon"); +} + //============================================================================== wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &variantType, wxDataViewCellMode mode, From 5556ea8429c5a619547d26bcd553372fee1bb4fb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 May 2022 18:30:23 +0100 Subject: [PATCH 5/8] Add support for storing wxBitmapBundle in a wxVariant Define wxBitmapBundleVariantData without using the standard macros that only work for wxObject-derived classes, but using more or less what they expand into. This will allow using wxBitmapBundle with wxDataViewCustomRenderer subclasses in the upcoming commit. --- include/wx/bmpbndl.h | 15 ++++++++++ src/common/bmpbndl.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/include/wx/bmpbndl.h b/include/wx/bmpbndl.h index 2f2f099680..d379c1e770 100644 --- a/include/wx/bmpbndl.h +++ b/include/wx/bmpbndl.h @@ -245,4 +245,19 @@ public: virtual wxBitmap GetBitmap(const wxSize& size) = 0; }; +// ---------------------------------------------------------------------------- +// Allow using wxBitmapBundle in wxVariant +// ---------------------------------------------------------------------------- + +#if wxUSE_VARIANT + +class WXDLLIMPEXP_FWD_BASE wxVariant; + +WXDLLIMPEXP_CORE +wxBitmapBundle& operator<<(wxBitmapBundle& value, const wxVariant& variant); +WXDLLIMPEXP_CORE +wxVariant& operator<<(wxVariant& variant, const wxBitmapBundle& value); + +#endif // wxUSE_VARIANT + #endif // _WX_BMPBNDL_H_ diff --git a/src/common/bmpbndl.cpp b/src/common/bmpbndl.cpp index 03ce1dd5b9..7b9d532b74 100644 --- a/src/common/bmpbndl.cpp +++ b/src/common/bmpbndl.cpp @@ -36,6 +36,71 @@ #include "wx/osx/private.h" #endif +#if wxUSE_VARIANT + +#include "wx/variant.h" + +// We can't use the macros from wx/variant.h because they only work for +// wxObject-derived classes, so define our own wxVariantData. + +class wxBitmapBundleVariantData: public wxVariantData +{ +public: + explicit wxBitmapBundleVariantData(const wxBitmapBundle& value) + : m_value(value) + { + } + + virtual bool Eq(wxVariantData& data) const wxOVERRIDE + { + // We're only called with the objects of the same type, so the cast is + // safe. + return static_cast(data).m_value.IsSameAs(m_value); + } + + virtual wxString GetType() const wxOVERRIDE + { + return wxASCII_STR("wxBitmapBundle"); + } + + virtual wxClassInfo* GetValueClassInfo() wxOVERRIDE + { + return NULL; + } + + virtual wxVariantData* Clone() const wxOVERRIDE + { + return new wxBitmapBundleVariantData(m_value); + } + + wxBitmapBundle m_value; + + DECLARE_WXANY_CONVERSION() +}; + +IMPLEMENT_TRIVIAL_WXANY_CONVERSION(wxBitmapBundle, wxBitmapBundleVariantData) + +WXDLLIMPEXP_CORE +wxBitmapBundle& operator<<(wxBitmapBundle& value, const wxVariant& variant) +{ + wxASSERT( variant.GetType() == wxASCII_STR("wxBitmapBundle") ); + + wxBitmapBundleVariantData* const + data = static_cast(variant.GetData()); + + value = data->m_value; + return value; +} + +WXDLLIMPEXP_CORE +wxVariant& operator<<(wxVariant& variant, const wxBitmapBundle& value) +{ + variant.SetData(new wxBitmapBundleVariantData(value)); + return variant; +} + +#endif // wxUSE_VARIANT + // ---------------------------------------------------------------------------- // private helpers // ---------------------------------------------------------------------------- From 8d3e7fd3469fe644b7a17e02fa28edc3b987dd7f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 May 2022 18:37:00 +0100 Subject: [PATCH 6/8] 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. --- src/generic/datavgen.cpp | 9 +++++++-- src/gtk/dataview.cpp | 23 +++++++++++++++++------ src/osx/cocoa/dataview.mm | 13 ++++++++++++- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 88f6ff1a0d..111d77dd8b 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -1317,7 +1317,11 @@ wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, 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; bitmap << value; @@ -1346,7 +1350,8 @@ bool wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const { // We can accept values of any types checked by SetValue(). - return variantType == wxS("wxBitmap") + return variantType == wxS("wxBitmapBundle") + || variantType == wxS("wxBitmap") || variantType == wxS("wxIcon"); } diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index e537ba10d7..ce309b61d1 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -2569,22 +2569,32 @@ wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value ) { - wxBitmap bitmap; - if (value.GetType() == wxS("wxBitmap")) + wxBitmapBundle bitmapBundle; + if (value.GetType() == wxS("wxBitmapBundle")) { + bitmapBundle << value; + } + else if (value.GetType() == wxS("wxBitmap")) + { + wxBitmap bitmap; bitmap << value; + bitmapBundle = wxBitmapBundle(bitmap); } else if (value.GetType() == wxS("wxIcon")) { wxIcon icon; icon << value; - bitmap.CopyFromIcon(icon); + bitmapBundle = wxBitmapBundle(icon); } #ifdef __WXGTK3__ - WX_CELL_RENDERER_PIXBUF(m_renderer)->Set(bitmap); + WX_CELL_RENDERER_PIXBUF(m_renderer)->Set(bitmapBundle); #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 return true; @@ -2599,7 +2609,8 @@ bool wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const { // We can accept values of any types checked by SetValue(). - return variantType == wxS("wxBitmap") + return variantType == wxS("wxBitmapBundle") + || variantType == wxS("wxBitmap") || variantType == wxS("wxIcon"); } diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index d2b8f14d11..524c998d08 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -28,6 +28,9 @@ #include "wx/osx/private/available.h" #include "wx/osx/private/datatransfer.h" #include "wx/osx/cocoa/dataview.h" + +#include "wx/private/bmpbndl.h" + #include "wx/renderer.h" #include "wx/stopwatch.h" #include "wx/dcgraph.h" @@ -2983,6 +2986,13 @@ wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(const wxString& varianttype, bool wxDataViewBitmapRenderer::MacRender() { 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; bitmap << GetValue(); @@ -3003,7 +3013,8 @@ bool wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const { // We can accept values of any types checked by SetValue(). - return variantType == wxS("wxBitmap") + return variantType == wxS("wxBitmapBundle") + || variantType == wxS("wxBitmap") || variantType == wxS("wxIcon"); } From 1b82a9fe0435eb64514250854560d3af9e972e57 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 May 2022 18:45:14 +0100 Subject: [PATCH 7/8] Use wxBitmapBundle as default type in wxDataViewBitmapRenderer The default type doesn't really matter after the previous commits, as the renderer accepts both wxBitmap and wxBitmapBundle (and also wxIcon) in any case anyhow, but it seems better to use the preferred type as the default one. Also make the documentation more useful, although an example is still lacking. --- include/wx/generic/dvrenderers.h | 2 +- include/wx/gtk/dvrenderers.h | 2 +- include/wx/osx/dvrenderers.h | 2 +- include/wx/qt/dvrenderers.h | 2 +- interface/wx/dataview.h | 12 +++++++++++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/wx/generic/dvrenderers.h b/include/wx/generic/dvrenderers.h index a02a1a5b28..17d963ecdb 100644 --- a/include/wx/generic/dvrenderers.h +++ b/include/wx/generic/dvrenderers.h @@ -96,7 +96,7 @@ private: class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer { public: - static wxString GetDefaultType() { return wxS("wxBitmap"); } + static wxString GetDefaultType() { return wxS("wxBitmapBundle"); } wxDataViewBitmapRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, diff --git a/include/wx/gtk/dvrenderers.h b/include/wx/gtk/dvrenderers.h index 1deadc3b33..e8a65c37b1 100644 --- a/include/wx/gtk/dvrenderers.h +++ b/include/wx/gtk/dvrenderers.h @@ -81,7 +81,7 @@ protected: class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer { public: - static wxString GetDefaultType() { return wxS("wxBitmap"); } + static wxString GetDefaultType() { return wxS("wxBitmapBundle"); } wxDataViewBitmapRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, diff --git a/include/wx/osx/dvrenderers.h b/include/wx/osx/dvrenderers.h index 832d789d33..218ce08d8c 100644 --- a/include/wx/osx/dvrenderers.h +++ b/include/wx/osx/dvrenderers.h @@ -104,7 +104,7 @@ private: class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer { public: - static wxString GetDefaultType() { return wxS("wxBitmap"); } + static wxString GetDefaultType() { return wxS("wxBitmapBundle"); } wxDataViewBitmapRenderer(const wxString& varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, diff --git a/include/wx/qt/dvrenderers.h b/include/wx/qt/dvrenderers.h index b156b4425d..dc57dc349c 100644 --- a/include/wx/qt/dvrenderers.h +++ b/include/wx/qt/dvrenderers.h @@ -34,7 +34,7 @@ public: class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer { public: - static wxString GetDefaultType() { return wxS("wxBitmap"); } + static wxString GetDefaultType() { return wxS("wxBitmapBundle"); } wxDataViewBitmapRenderer( const wxString &varianttype = GetDefaultType(), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index 563a6ad1b4..e47d101f3e 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -2730,7 +2730,12 @@ protected: /** @class wxDataViewBitmapRenderer - This class is used by wxDataViewCtrl to render bitmap controls. + This class is used by wxDataViewCtrl to render bitmaps. + + This renderer accepts wxVariant objects storing wxBitmap, wxIcon or + wxBitmapBundle inside them, with the latter being preferred as it allows + the renderer to automatically select the bitmap of the best matching size + depending on the current DPI. @library{wxcore} @category{dvc} @@ -2741,6 +2746,11 @@ public: /** Returns the wxVariant type used with this renderer. + Note that the value returned by this function has changed from + "wxBitmap" to "wxBitmapBundle" in wxWidgets 3.1.7, however the exact + value shouldn't matter, as it is only supposed to be used as the value + for the first constructor argument. + @since 3.1.0 */ static wxString GetDefaultType(); From 140b88af4a7aca1ae2a2c6c421280b03fc1921b1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 11 May 2022 17:23:56 +0200 Subject: [PATCH 8/8] Improve wxDataViewRenderer variant type documentation Explain what it is in the ctor documentation and link to the new IsCompatibleVariantType() in GetVariantType() docs. --- interface/wx/dataview.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index e47d101f3e..dde618e8cf 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -1981,6 +1981,15 @@ class wxDataViewRenderer : public wxObject public: /** Constructor. + + The @a varianttype parameter is the main type of wxVariant objects + supported by this renderer, i.e. those that can be passed to its + SetValue(), e.g. "string" for wxDataViewTextRenderer. The value of this + parameter is returned by GetVariantType(). + + When deriving a custom renderer, either an existing variant type or a + new custom one can be used, see wxVariant documentation for more + details. */ wxDataViewRenderer(const wxString& varianttype, wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, @@ -2061,6 +2070,11 @@ public: /** Returns a string with the type of the wxVariant supported by this renderer. + + Note that a renderer may support more than one variant type, in which + case it needs to override IsCompatibleVariantType() to return @a true + for all types it supports. But by default only the type returned by + this function is supported. */ wxString GetVariantType() const;