From de9f4baa7d05854c7e6d17f6b425fddb8fed43b0 Mon Sep 17 00:00:00 2001 From: Brendan Hagan Date: Mon, 15 Aug 2022 21:46:14 -0400 Subject: [PATCH] fix: implement GetDataSize(format) method for clipboard objects (fixes #46) Both are wxTextDataObject, which looks to have a default implementation on Windows at least. Unclear how it's resolving on Linux, so hoping that this ensures the behavior. --- src/data/format/clipboard.cpp | 21 ++++++++++++++++++++- src/data/format/clipboard.hpp | 6 ++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/data/format/clipboard.cpp b/src/data/format/clipboard.cpp index 7f6a1031..49bdd808 100644 --- a/src/data/format/clipboard.cpp +++ b/src/data/format/clipboard.cpp @@ -79,6 +79,14 @@ CardsDataObject::CardsDataObject(const SetP& set, const vector& cards) { } SetFormat(format); delete [] has_styling; +} + +size_t CardsDataObject::GetDataSize(const wxDataFormat& f) const { + if (f == format) { + return GetText().size(); + } else { + wxASSERT_MSG(f == format, _("Unexpected format")); + } } CardsDataObject::CardsDataObject() { @@ -124,6 +132,15 @@ KeywordDataObject::KeywordDataObject(const SetP& set, const KeywordP& keyword) { WrappedKeyword data = { set->game.get(), set->game->name(), keyword }; SetText(serialize_for_clipboard(*set, data)); SetFormat(format); +} + +size_t KeywordDataObject::GetDataSize(const wxDataFormat& f) const { + if (f == format) { + return GetText().size(); + } + else { + wxASSERT_MSG(f == format, _("Unexpected format")); + } } KeywordDataObject::KeywordDataObject() { @@ -148,6 +165,8 @@ CardsOnClipboard::CardsOnClipboard(const SetP& set, const vector& cards) if (cards.size() == 1) { Add(new wxBitmapDataObject(export_bitmap(set, cards[0]))); } - // Conversion to serialized card format + // Conversion to serialized card format + auto c = new CardsDataObject(set, cards); + auto s = c->GetDataSize(CardsDataObject::format); Add(new CardsDataObject(set, cards), true); } diff --git a/src/data/format/clipboard.hpp b/src/data/format/clipboard.hpp index 3bdf0353..908ef801 100644 --- a/src/data/format/clipboard.hpp +++ b/src/data/format/clipboard.hpp @@ -29,7 +29,8 @@ class CardsDataObject : public wxTextDataObject { /// Retrieve the cards, only if it is made with the same game as set /** Return true if the cards are correctly retrieved, and there is at least one card */ - bool getCards(const SetP& set, vector& out); + bool getCards(const SetP& set, vector& out); + size_t GetDataSize(const wxDataFormat& format) const override; }; // ----------------------------------------------------------------------------- : KeywordDataObject @@ -45,7 +46,8 @@ class KeywordDataObject : public wxTextDataObject { KeywordDataObject(const SetP& set, const KeywordP& card); /// Retrieve a keyword, only if it is made with the same game as set - KeywordP getKeyword(const SetP& set); + KeywordP getKeyword(const SetP& set); + size_t GetDataSize(const wxDataFormat& format) const override; }; // ----------------------------------------------------------------------------- : Card on clipboard