Skip to content

Commit

Permalink
fix: implement GetDataSize(format) method for clipboard objects (fixes
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
haganbmj committed Aug 16, 2022
1 parent f83a52d commit de9f4ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/data/format/clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ CardsDataObject::CardsDataObject(const SetP& set, const vector<CardP>& 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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -148,6 +165,8 @@ CardsOnClipboard::CardsOnClipboard(const SetP& set, const vector<CardP>& 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);
}
6 changes: 4 additions & 2 deletions src/data/format/clipboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CardP>& out);
bool getCards(const SetP& set, vector<CardP>& out);
size_t GetDataSize(const wxDataFormat& format) const override;
};

// ----------------------------------------------------------------------------- : KeywordDataObject
Expand All @@ -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
Expand Down

0 comments on commit de9f4ba

Please sign in to comment.