Skip to content

Commit

Permalink
Fix compile error against wxWidgets with 2.8 compat
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
arch1t3cht committed Dec 26, 2024
1 parent dea997a commit 75c4917
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/libresrc/libresrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "bitmap.h"
#include "default_config.h"

#include <wx/version.h>

class wxBitmap;
class wxIcon;

Expand All @@ -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<const char *>(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
2 changes: 1 addition & 1 deletion src/toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/visual_tool_vector_clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 75c4917

Please sign in to comment.