diff options
author | B Stack <bgstack15@gmail.com> | 2018-10-16 17:33:51 -0400 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2018-10-16 17:33:51 -0400 |
commit | 878a41d3be13da2a654df74f2a35ea8b295c8a13 (patch) | |
tree | 89b2a018482c164bdd8ecac5c76b19a08f420dec /wx+ | |
parent | Merge branch '10.4' into 'master' (diff) | |
download | FreeFileSync-878a41d3be13da2a654df74f2a35ea8b295c8a13.tar.gz FreeFileSync-878a41d3be13da2a654df74f2a35ea8b295c8a13.tar.bz2 FreeFileSync-878a41d3be13da2a654df74f2a35ea8b295c8a13.zip |
10.5
Diffstat (limited to 'wx+')
-rwxr-xr-x | wx+/async_task.h | 2 | ||||
-rwxr-xr-x | wx+/choice_enum.h | 8 | ||||
-rwxr-xr-x | wx+/context_menu.h | 4 | ||||
-rwxr-xr-x | wx+/dc.h | 1 | ||||
-rwxr-xr-x | wx+/graph.cpp | 4 | ||||
-rwxr-xr-x | wx+/grid.h | 20 | ||||
-rwxr-xr-x | wx+/image_resources.cpp | 13 | ||||
-rwxr-xr-x | wx+/image_tools.cpp | 16 | ||||
-rwxr-xr-x | wx+/zlib_wrap.cpp | 7 |
9 files changed, 44 insertions, 31 deletions
diff --git a/wx+/async_task.h b/wx+/async_task.h index d1f30fec..df4c3ec6 100755 --- a/wx+/async_task.h +++ b/wx+/async_task.h @@ -95,7 +95,7 @@ public: return false; }); - for (auto& task : readyTasks) + for (std::unique_ptr<Task>& task : readyTasks) task->evaluateResult(); } } diff --git a/wx+/choice_enum.h b/wx+/choice_enum.h index 2c424b9f..f2c93927 100755 --- a/wx+/choice_enum.h +++ b/wx+/choice_enum.h @@ -103,11 +103,11 @@ Enum getEnumVal(const EnumDescrList<Enum>& mapping, const wxChoice& ctrl) template <class Enum> void updateTooltipEnumVal(const EnumDescrList<Enum>& mapping, wxChoice& ctrl) { - const Enum value = getEnumVal(mapping, ctrl); + const Enum currentValue = getEnumVal(mapping, ctrl); - for (const auto& item : mapping.descrList) - if (item.first == value) - ctrl.SetToolTip(item.second.second); + for (const auto& [enumValue, textAndTooltip] : mapping.descrList) + if (currentValue == enumValue) + ctrl.SetToolTip(textAndTooltip.second); } } diff --git a/wx+/context_menu.h b/wx+/context_menu.h index 7f459aca..d856db03 100755 --- a/wx+/context_menu.h +++ b/wx+/context_menu.h @@ -72,8 +72,8 @@ public: void popup(wxWindow& wnd, const wxPoint& pos = wxDefaultPosition) //show popup menu + process lambdas { //eventually all events from submenu items will be received by this menu - for (const auto& item : commandList_) - menu_->Connect(item.first, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(ContextMenu::onSelection), new GenericCommand(item.second) /*pass ownership*/, this); + for (const auto& [itemId, command] : commandList_) + menu_->Connect(itemId, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(ContextMenu::onSelection), new GenericCommand(command) /*pass ownership*/, this); wnd.PopupMenu(menu_.get(), pos); wxTheApp->ProcessPendingEvents(); //make sure lambdas are evaluated before going out of scope; @@ -8,6 +8,7 @@ #define DC_H_4987123956832143243214 #include <unordered_map> +#include <optional> #include <zen/basic_math.h> #include <wx/dcbuffer.h> //for macro: wxALWAYS_NATIVE_DOUBLE_BUFFER #include <wx/dcscreen.h> diff --git a/wx+/graph.cpp b/wx+/graph.cpp index 38846523..e00bed86 100755 --- a/wx+/graph.cpp +++ b/wx+/graph.cpp @@ -846,8 +846,8 @@ void Graph2D::render(wxDC& dc) const } //5. draw corner texts - for (const auto& ct : attr_.cornerTexts) - drawCornerText(dc, graphArea, ct.second, ct.first, attr_.backgroundColor); + for (const auto& [cornerPos, text] : attr_.cornerTexts) + drawCornerText(dc, graphArea, text, cornerPos, attr_.backgroundColor); } } } @@ -9,9 +9,11 @@ #include <memory> #include <numeric> +#include <optional> +#include <set> #include <vector> -#include <wx/scrolwin.h> #include <zen/basic_math.h> +#include <wx/scrolwin.h> //a user-friendly, extensible and high-performance grid control @@ -362,10 +364,18 @@ private: template <class ColAttrReal> std::vector<ColAttrReal> makeConsistent(const std::vector<ColAttrReal>& attribs, const std::vector<ColAttrReal>& defaults) { - std::vector<ColAttrReal> output = attribs; - //make sure each type is existing! - output.insert(output.end(), defaults.begin(), defaults.end()); - removeDuplicates(output, [](const ColAttrReal& lhs, const ColAttrReal& rhs) { return lhs.type < rhs.type; }); + using ColTypeReal = decltype(ColAttrReal().type); + std::vector<ColAttrReal> output; + + std::set<ColTypeReal> usedTypes; //remove duplicates + auto appendUnique = [&](const std::vector<ColAttrReal>& attr) + { + std::copy_if(attr.begin(), attr.end(), std::back_inserter(output), + [&](const ColAttrReal& a) { return usedTypes.insert(a.type).second; }); + }; + appendUnique(attribs); + appendUnique(defaults); //make sure each type is existing! + return output; } diff --git a/wx+/image_resources.cpp b/wx+/image_resources.cpp index d0449fe5..d09a188b 100755 --- a/wx+/image_resources.cpp +++ b/wx+/image_resources.cpp @@ -122,14 +122,12 @@ public: result_.access([&](std::vector<std::pair<std::wstring, ImageHolder>>& r) { - for (auto& item : r) + for (auto& [imageName, ih] : r) { - ImageHolder& ih = item.second; - wxImage img(ih.getWidth(), ih.getHeight(), ih.releaseRgb(), false /*static_data*/); //pass ownership img.SetAlpha(ih.releaseAlpha(), false /*static_data*/); - output.emplace(item.first, std::move(img)); + output.emplace(imageName, std::move(img)); } }); return output; @@ -171,7 +169,8 @@ class GlobalBitmaps public: static std::shared_ptr<GlobalBitmaps> instance() { - static Global<GlobalBitmaps> inst(std::make_unique<GlobalBitmaps>()); + static FunStatGlobal<GlobalBitmaps> inst; + inst.initOnce([] { return std::make_unique<GlobalBitmaps>(); }); assert(runningMainThread()); //wxWidgets is not thread-safe! return inst.get(); } @@ -179,7 +178,7 @@ public: GlobalBitmaps() {} ~GlobalBitmaps() { assert(bitmaps_.empty() && anims_.empty()); } //don't leave wxWidgets objects for static destruction! - void init(const Zstring& filepath); + void init(const Zstring& filePath); void cleanup() { bitmaps_.clear(); @@ -239,6 +238,8 @@ void GlobalBitmaps::init(const Zstring& filePath) } else if (endsWith(name, L".gif")) loadAnimFromZip(streamIn, anims_[name]); + else + assert(false); } } } diff --git a/wx+/image_tools.cpp b/wx+/image_tools.cpp index 4748a590..b314e801 100755 --- a/wx+/image_tools.cpp +++ b/wx+/image_tools.cpp @@ -141,10 +141,10 @@ wxImage zen::createImageFromText(const wxString& text, const wxFont& font, const int maxWidth = 0; int lineHeight = 0; - for (const auto& li : lineInfo) + for (const auto& [lineText, lineSize] : lineInfo) { - maxWidth = std::max(maxWidth, li.second.GetWidth()); - lineHeight = std::max(lineHeight, li.second.GetHeight()); //wxWidgets comment "GetTextExtent will return 0 for empty string" + maxWidth = std::max(maxWidth, lineSize.GetWidth()); + lineHeight = std::max(lineHeight, lineSize.GetHeight()); //wxWidgets comment "GetTextExtent will return 0 for empty string" } if (maxWidth == 0 || lineHeight == 0) return wxImage(); @@ -160,19 +160,19 @@ wxImage zen::createImageFromText(const wxString& text, const wxFont& font, const dc.SetFont(font); int posY = 0; - for (const auto& li : lineInfo) + for (const auto& [lineText, lineSize] : lineInfo) { - if (!li.first.empty()) + if (!lineText.empty()) switch (textAlign) { case ImageStackAlignment::LEFT: - dc.DrawText(li.first, wxPoint(0, posY)); + dc.DrawText(lineText, wxPoint(0, posY)); break; case ImageStackAlignment::RIGHT: - dc.DrawText(li.first, wxPoint(maxWidth - li.second.GetWidth(), posY)); + dc.DrawText(lineText, wxPoint(maxWidth - lineSize.GetWidth(), posY)); break; case ImageStackAlignment::CENTER: - dc.DrawText(li.first, wxPoint((maxWidth - li.second.GetWidth()) / 2, posY)); + dc.DrawText(lineText, wxPoint((maxWidth - lineSize.GetWidth()) / 2, posY)); break; } diff --git a/wx+/zlib_wrap.cpp b/wx+/zlib_wrap.cpp index cb6e3083..fbbe2f09 100755 --- a/wx+/zlib_wrap.cpp +++ b/wx+/zlib_wrap.cpp @@ -5,9 +5,10 @@ // ***************************************************************************** #include "zlib_wrap.h" -//include the SAME zlib version that wxWidgets is linking against! - //#include <wx/../../../../../Source/src/zlib/zlib.h> //wxWidgets compiled with: --with-zlib=builtin - #include <zlib.h> //use same library as used by Curl (zlib is required for HTTP) +//Windows: use the SAME zlib version that wxWidgets is linking against! //C:\Data\Projects\wxWidgets\Source\src\zlib\zlib.h +//Linux/macOS: use zlib system header for both wxWidgets and Curl (zlib is required for HTTP) +// => don't compile wxWidgets with: --with-zlib=builtin +#include <zlib.h> using namespace zen; |