diff options
author | B. Stack <bgstack15@gmail.com> | 2022-04-18 13:48:31 +0000 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2022-04-18 13:48:31 +0000 |
commit | 8a551d2eff24bdd23bc25caeb8d17207409aae38 (patch) | |
tree | 84e67ca0a1fb045a12d015fcffca9cd8087c9332 /wx+/context_menu.h | |
parent | Merge branch 'b11.18' into 'master' (diff) | |
parent | add upstream 11.20 (diff) | |
download | FreeFileSync-8a551d2eff24bdd23bc25caeb8d17207409aae38.tar.gz FreeFileSync-8a551d2eff24bdd23bc25caeb8d17207409aae38.tar.bz2 FreeFileSync-8a551d2eff24bdd23bc25caeb8d17207409aae38.zip |
Merge branch 'b11.20' into 'master'11.20
add upstream 11.20
See merge request opensource-tracking/FreeFileSync!43
Diffstat (limited to 'wx+/context_menu.h')
-rw-r--r-- | wx+/context_menu.h | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/wx+/context_menu.h b/wx+/context_menu.h index c53cec39..728da173 100644 --- a/wx+/context_menu.h +++ b/wx+/context_menu.h @@ -12,6 +12,10 @@ #include <functional> #include <wx/menu.h> #include <wx/app.h> +#include "dc.h" + +warn_static("remove after test") +#include "image_tools.h" /* A context menu supporting lambda callbacks! @@ -23,6 +27,13 @@ namespace zen { +inline +void setImage(wxMenuItem& menuItem, const wxImage& img) +{ + menuItem.SetBitmap(toBitmapBundle(img)); +} + + class ContextMenu : private wxEvtHandler { public: @@ -32,7 +43,7 @@ public: { wxMenuItem* newItem = new wxMenuItem(menu_.get(), wxID_ANY, label); //menu owns item! if (img.IsOk()) - newItem->SetBitmap(img); //do not set AFTER appending item! wxWidgets screws up for yet another crappy reason + setImage(*newItem, img); //do not set AFTER appending item! wxWidgets screws up for yet another crappy reason menu_->Append(newItem); if (!enabled) newItem->Enable(false); //do not enable BEFORE appending item! wxWidgets screws up for yet another crappy reason @@ -69,7 +80,7 @@ public: wxMenuItem* newItem = new wxMenuItem(menu_.get(), wxID_ANY, label, L"", wxITEM_NORMAL, submenu.menu_.release()); //menu owns item, item owns submenu! if (img.IsOk()) - newItem->SetBitmap(img); //do not set AFTER appending item! wxWidgets screws up for yet another crappy reason + setImage(*newItem, img); //do not set AFTER appending item! wxWidgets screws up for yet another crappy reason menu_->Append(newItem); if (!enabled) newItem->Enable(false); @@ -93,6 +104,27 @@ private: std::unique_ptr<wxMenu> menu_ = std::make_unique<wxMenu>(); std::map<int /*item id*/, std::function<void()> /*command*/> commandList_; }; + + +//GTK: image must be set *before* adding wxMenuItem to menu or it won't show => workaround: +inline //also needed on Windows + macOS since wxWidgets 3.1.6 (thanks?) +void fixMenuIcons(wxMenu& menu) +{ + std::vector<std::pair<wxMenuItem*, size_t /*pos*/>> itemsWithBmp; + { + size_t pos = 0; + for (wxMenuItem* item : menu.GetMenuItems()) + { + if (item->GetBitmap().IsOk()) + itemsWithBmp.emplace_back(item, pos); + ++pos; + } + } + + for (const auto& [item, pos] : itemsWithBmp) + if (!menu.Insert(pos, menu.Remove(item))) //detach + reinsert + assert(false); +} } #endif //CONTEXT_MENU_H_18047302153418174632141234 |