From 75c49172cd8364a3db8527925baedd2820503dfe Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Thu, 26 Dec 2024 19:28:09 +0100 Subject: [PATCH] Fix compile error against wxWidgets with 2.8 compat When wxWidgets is compiled in 2.8 compatibility mode, some function calls become ambiguous. The fix is pretty simple (except for figuring out where to put the BITMAPBUNDLE macro) so let me spend the remaining space here by complaining about how ridiculous the second candidate invocation is. The intended invocation previously only involved a single implicit conversion, from wxBitmap to wxBitmapBundle. The unintended one involves conversions: - from wxString to wxBitmap - from wxString to bool - from wxItemKind (an enum) to wxCoord (typedef'd to int) --- src/libresrc/libresrc.h | 11 +++++++++++ src/toolbar.cpp | 2 +- src/visual_tool_vector_clip.cpp | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libresrc/libresrc.h b/src/libresrc/libresrc.h index ce1f25845a..091c74a55b 100644 --- a/src/libresrc/libresrc.h +++ b/src/libresrc/libresrc.h @@ -18,6 +18,8 @@ #include "bitmap.h" #include "default_config.h" +#include + class wxBitmap; class wxIcon; @@ -28,3 +30,12 @@ wxIcon libresrc_geticon(const unsigned char *image, size_t size); #define GETICON(a) libresrc_geticon(a, sizeof(a)) #define GET_DEFAULT_CONFIG(a) std::string_view(reinterpret_cast(a), sizeof(a)) + +// Compatibility helper: wxWidgets introduced wxBitmapBundle in 3.1.6 and made +// some functions take wxBitmapBundles rather than wxBitmaps, which makes some +// function calls ambiguous. +#if wxCHECK_VERSION(3, 1, 6) +#define BITMAPBUNDLE(b) wxBitmapBundle(b) +#else +#define BITMAPBUNDLE(b) b +#endif diff --git a/src/toolbar.cpp b/src/toolbar.cpp index 6ac2f32424..c88bb0276d 100644 --- a/src/toolbar.cpp +++ b/src/toolbar.cpp @@ -143,7 +143,7 @@ namespace { wxITEM_NORMAL; wxBitmap const& bitmap = command->Icon(icon_size, retina_helper.GetScaleFactor(), GetLayoutDirection()); - AddTool(TOOL_ID_BASE + commands.size(), command->StrDisplay(context), bitmap, GetTooltip(command), kind); + AddTool(TOOL_ID_BASE + commands.size(), command->StrDisplay(context), BITMAPBUNDLE(bitmap), GetTooltip(command), kind); commands.push_back(command); needs_onidle = needs_onidle || flags != cmd::COMMAND_NORMAL; diff --git a/src/visual_tool_vector_clip.cpp b/src/visual_tool_vector_clip.cpp index 38cfed0891..efda24b046 100644 --- a/src/visual_tool_vector_clip.cpp +++ b/src/visual_tool_vector_clip.cpp @@ -54,7 +54,7 @@ void VisualToolVectorClip::SetToolbar(wxToolBar *toolBar) { int icon_size = OPT_GET("App/Toolbar Icon Size")->GetInt(); -#define ICON(name) icon_size == 16 ? GETIMAGE(name ## _16) : GETIMAGE(name ## _24) +#define ICON(name) BITMAPBUNDLE(icon_size == 16 ? GETIMAGE(name ## _16) : GETIMAGE(name ## _24)) toolBar->AddTool(BUTTON_DRAG, _("Drag"), ICON(visual_vector_clip_drag), _("Drag control points"), wxITEM_CHECK); toolBar->AddTool(BUTTON_LINE, _("Line"), ICON(visual_vector_clip_line), _("Appends a line"), wxITEM_CHECK); toolBar->AddTool(BUTTON_BICUBIC, _("Bicubic"), ICON(visual_vector_clip_bicubic), _("Appends a bezier bicubic curve"), wxITEM_CHECK);