summaryrefslogtreecommitdiff
path: root/wx+/context_menu.h
diff options
context:
space:
mode:
Diffstat (limited to 'wx+/context_menu.h')
-rw-r--r--wx+/context_menu.h36
1 files changed, 35 insertions, 1 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
bgstack15