From d299ddd2f27a437f0fc0cb49abdfd6dd8e3d94f8 Mon Sep 17 00:00:00 2001 From: B Stack Date: Tue, 2 Feb 2021 11:44:31 -0500 Subject: add upstream 11.6 --- wx+/no_flicker.h | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'wx+/no_flicker.h') diff --git a/wx+/no_flicker.h b/wx+/no_flicker.h index 53e47bb5..a84a7228 100644 --- a/wx+/no_flicker.h +++ b/wx+/no_flicker.h @@ -79,28 +79,28 @@ void setTextWithUrls(wxRichTextCtrl& richCtrl, const wxString& newText) richCtrl.Clear(); + wxRichTextAttr urlStyle; + urlStyle.SetTextColour(*wxBLUE); + urlStyle.SetFontUnderlined(true); + + for (const auto& [type, text] : blocks) + switch (type) + { + case BlockType::text: + richCtrl.WriteText(text); + break; + + case BlockType::url: + richCtrl.BeginStyle(urlStyle); + ZEN_ON_SCOPE_EXIT(richCtrl.EndStyle()); + richCtrl.BeginURL(text); + ZEN_ON_SCOPE_EXIT(richCtrl.EndURL()); + richCtrl.WriteText(text); + break; + } + if (std::any_of(blocks.begin(), blocks.end(), [](const auto& item) { return item.first == BlockType::url; })) { - wxRichTextAttr urlStyle; - urlStyle.SetTextColour(*wxBLUE); - urlStyle.SetFontUnderlined(true); - - for (const auto& [type, text] : blocks) - switch (type) - { - case BlockType::text: - richCtrl.WriteText(text); - break; - - case BlockType::url: - richCtrl.BeginStyle(urlStyle); - ZEN_ON_SCOPE_EXIT(richCtrl.EndStyle()); - richCtrl.BeginURL(text); - ZEN_ON_SCOPE_EXIT(richCtrl.EndURL()); - richCtrl.WriteText(text); - break; - } - //register only once! => use a global function pointer, so that Unbind() works correctly: using LaunchUrlFun = void(*)(wxTextUrlEvent& event); static const LaunchUrlFun launchUrl = [](wxTextUrlEvent& event) { wxLaunchDefaultBrowser(event.GetString()); }; @@ -108,8 +108,6 @@ void setTextWithUrls(wxRichTextCtrl& richCtrl, const wxString& newText) [[maybe_unused]] const bool unbindOk = richCtrl.Unbind(wxEVT_TEXT_URL, launchUrl); richCtrl.Bind(wxEVT_TEXT_URL, launchUrl); } - else - richCtrl.WriteText(newText); } } } -- cgit