diff options
Diffstat (limited to 'wx+/no_flicker.h')
-rw-r--r-- | wx+/no_flicker.h | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/wx+/no_flicker.h b/wx+/no_flicker.h index 7fa4ae23..185ee052 100644 --- a/wx+/no_flicker.h +++ b/wx+/no_flicker.h @@ -107,15 +107,48 @@ void setTextWithUrls(wxRichTextCtrl& richCtrl, const wxString& newText) 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()); }; + + [[maybe_unused]] const bool unbindOk1 = richCtrl.Unbind(wxEVT_TEXT_URL, launchUrl); if (std::any_of(blocks.begin(), blocks.end(), [](const auto& item) { return item.first == BlockType::url; })) + /**/richCtrl.Bind(wxEVT_TEXT_URL, launchUrl); + + struct UserData : public wxObject + { + explicit UserData(wxRichTextCtrl& rtc) : richCtrl(rtc) {} + wxRichTextCtrl& richCtrl; + }; + using KeyEventsFun = void(*)(wxKeyEvent& event); + static const KeyEventsFun onKeyEvents = [](wxKeyEvent& event) { - //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()); }; + wxRichTextCtrl& richCtrl = dynamic_cast<UserData*>(event.GetEventUserData())->richCtrl; //unclear if we can rely on event.GetEventObject() == richCtrl - [[maybe_unused]] const bool unbindOk = richCtrl.Unbind(wxEVT_TEXT_URL, launchUrl); - richCtrl.Bind(wxEVT_TEXT_URL, launchUrl); - } + //CTRL/SHIFT + INS is broken for wxRichTextCtrl on Windows/Linux (apparently never was a thing on macOS) + if (event.ControlDown()) + switch (event.GetKeyCode()) + { + case WXK_INSERT: + case WXK_NUMPAD_INSERT: + assert(richCtrl.CanCopy()); //except when no selection + richCtrl.Copy(); + return; + } + + if (event.ShiftDown()) + switch (event.GetKeyCode()) + { + case WXK_INSERT: + case WXK_NUMPAD_INSERT: + assert(richCtrl.CanPaste()); //except wxTE_READONLY + richCtrl.Paste(); + return; + } + event.Skip(); + }; + [[maybe_unused]] const bool unbindOk2 = richCtrl.Unbind(wxEVT_KEY_DOWN, onKeyEvents); + /**/ richCtrl. Bind(wxEVT_KEY_DOWN, onKeyEvents, wxID_ANY, wxID_ANY, new UserData(richCtrl) /*pass ownership*/); } } } |