summaryrefslogtreecommitdiff
path: root/wx+
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-12-16 21:08:02 -0500
committerB. Stack <bgstack15@gmail.com>2022-12-16 21:08:02 -0500
commitd35a4795f16e51f5773d00dce796f6948f82dae2 (patch)
treeb37279f6f8b354407507cc1a0e44691d6c63ffe8 /wx+
parentadd upstream 11.28 (diff)
downloadFreeFileSync-d35a4795f16e51f5773d00dce796f6948f82dae2.tar.gz
FreeFileSync-d35a4795f16e51f5773d00dce796f6948f82dae2.tar.bz2
FreeFileSync-d35a4795f16e51f5773d00dce796f6948f82dae2.zip
add upstream 11.2911.29
Diffstat (limited to 'wx+')
-rw-r--r--wx+/context_menu.h36
-rw-r--r--wx+/no_flicker.h45
2 files changed, 74 insertions, 7 deletions
diff --git a/wx+/context_menu.h b/wx+/context_menu.h
index 05dd58b8..d1d2bd9f 100644
--- a/wx+/context_menu.h
+++ b/wx+/context_menu.h
@@ -10,8 +10,9 @@
#include <map>
#include <vector>
#include <functional>
-#include <wx/menu.h>
#include <wx/app.h>
+#include <wx/clipbrd.h>
+#include <wx/menu.h>
#include "dc.h"
@@ -123,6 +124,39 @@ void fixMenuIcons(wxMenu& menu)
if (!menu.Insert(pos, menu.Remove(item))) //detach + reinsert
assert(false);
}
+
+
+inline
+void setClipboardText(const wxString& txt)
+{
+ wxClipboard& clip = *wxClipboard::Get();
+ if (clip.Open())
+ {
+ ZEN_ON_SCOPE_EXIT(clip.Close());
+ [[maybe_unused]] const bool rv1 = clip.SetData(new wxTextDataObject(txt)); //ownership passed
+ [[maybe_unused]] const bool rv2 = clip.Flush();
+ assert(rv1 && rv2);
+ }
+ else assert(false);
+}
+
+
+inline
+std::optional<wxString> getClipboardText()
+{
+ wxClipboard& clip = *wxClipboard::Get();
+ if (clip.Open())
+ {
+ ZEN_ON_SCOPE_EXIT(clip.Close());
+
+ //if (clip.IsSupported(wxDF_TEXT or wxDF_UNICODETEXT !???)) - superfluous? already handled by wxClipboard::GetData()!?
+ wxTextDataObject data;
+ if (clip.GetData(data))
+ return data.GetText();
+ }
+ else assert(false);
+ return std::nullopt;
+}
}
#endif //CONTEXT_MENU_H_18047302153418174632141234
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*/);
}
}
}
bgstack15