restore ability to paste in Paint

This commit is contained in:
GenevensiS
2026-05-10 09:39:19 +02:00
parent 50b649beca
commit 19b144f37b
8 changed files with 37 additions and 19 deletions
+14 -8
View File
@@ -161,23 +161,29 @@ KeywordP KeywordDataObject::getKeyword(const SetP& set) {
// ----------------------------------------------------------------------------- : Card on clipboard // ----------------------------------------------------------------------------- : Card on clipboard
CardsOnClipboard::CardsOnClipboard(const SetP& set, const String id, const vector<CardP>& cards) { CardsOnClipboard::CardsOnClipboard(const SetP& set, const String id, const vector<CardP>& cards) {
wxBusyCursor busy;
// Conversion to image file // Conversion to image file
if (cards.size() < 6) { if (cards.size() < 6) {
Bitmap bmp;
Image img; Image img;
if (cards.size() == 1) { if (cards.size() == 1) {
img = export_image(set, cards[0]); img = export_image(set, cards[0], true, 1.0, 0.0, 0.0, &bmp);
} }
else { else {
img = export_image(set, cards); img = export_image(set, cards);
bmp = Bitmap(img);
} }
String temp_path = wxFileName::CreateTempFileName(_("mse")) + _(".png"); //wxFileDataObject* fileData = new wxFileDataObject(); // needed for pasting on desktop, but slow
img.SaveFile(temp_path, wxBITMAP_TYPE_PNG); //String temp_path = wxFileName::CreateTempFileName(_("mse")) + _(".png");
wxFileDataObject* fileData = new wxFileDataObject(); //img.SaveFile(temp_path, wxBITMAP_TYPE_PNG);
fileData->AddFile(temp_path); //fileData->AddFile(temp_path);
Add(fileData); //Add(fileData);
wxImageDataObject* imgData = new wxImageDataObject(); wxImageDataObject* imgData = new wxImageDataObject(); // needed for metadata
imgData->SetImage(img); imgData->SetImage(img);
Add(imgData); Add(imgData);
wxBitmapDataObject* bmpData = new wxBitmapDataObject(); // needed for pasting in MSPaint
bmpData->SetBitmap(bmp);
Add(bmpData);
} }
// Conversion to serialized card format // Conversion to serialized card format
Add(new CardsDataObject(set, id, cards), true); Add(new CardsDataObject(set, id, cards), true);
+1 -1
View File
@@ -89,7 +89,7 @@ FileFormatP mtg_editor_file_format();
// ----------------------------------------------------------------------------- : Other ways to export // ----------------------------------------------------------------------------- : Other ways to export
/// Generate a wxImage of one or more cards /// Generate a wxImage of one or more cards
Image export_image(const SetP& set, const CardP& card, bool write_metadata = true, double zoom = 1.0, Radians angle_radians = 0.0, double bleed_pixels = 0.0); Image export_image(const SetP& set, const CardP& card, bool write_metadata = true, double zoom = 1.0, Radians angle_radians = 0.0, double bleed_pixels = 0.0, Bitmap* out_bitmap = nullptr);
Image export_image(const SetP& set, const vector<CardP>& cards, int padding = 2, double global_zoom = 1.0, bool use_zoom_setting = true, bool use_rotation_setting = true, bool use_bleed_setting = false); Image export_image(const SetP& set, const vector<CardP>& cards, int padding = 2, double global_zoom = 1.0, bool use_zoom_setting = true, bool use_rotation_setting = true, bool use_bleed_setting = false);
/// Export the image of one or more cards to a given filename, using the app's zoom, rotation and bleed settings, and including metadata /// Export the image of one or more cards to a given filename, using the app's zoom, rotation and bleed settings, and including metadata
+5 -3
View File
@@ -35,7 +35,7 @@ Rotation ZoomedUnrotatedDataViewer::getRotation() const {
// ----------------------------------------------------------------------------- : wxImage export // ----------------------------------------------------------------------------- : wxImage export
Image export_image(const SetP& set, const CardP& card, bool write_metadata, double zoom, Radians angle_radians, double bleed_pixels) { Image export_image(const SetP& set, const CardP& card, bool write_metadata, double zoom, Radians angle_radians, double bleed_pixels, Bitmap* out_bitmap) {
if (!set) throw Error(_("no set")); if (!set) throw Error(_("no set"));
/// create and zoom /// create and zoom
ZoomedUnrotatedDataViewer viewer = ZoomedUnrotatedDataViewer(zoom); ZoomedUnrotatedDataViewer viewer = ZoomedUnrotatedDataViewer(zoom);
@@ -51,6 +51,9 @@ Image export_image(const SetP& set, const CardP& card, bool write_metadata, doub
viewer.draw(dc); viewer.draw(dc);
dc.SelectObject(wxNullBitmap); dc.SelectObject(wxNullBitmap);
Image img = bitmap.ConvertToImage(); Image img = bitmap.ConvertToImage();
/// return bitmap if needed
if (out_bitmap) *out_bitmap = std::move(bitmap);
/// rotate /// rotate
img = rotate_image(img, angle_radians); img = rotate_image(img, angle_radians);
@@ -218,8 +221,7 @@ void export_image(const SetP& set, const CardP& card, const String& filename) {
img.SaveFile(filename); img.SaveFile(filename);
} }
void export_image(const SetP& set, const vector<CardP>& cards, const String& path, const String& filename_template, FilenameConflicts conflicts) void export_image(const SetP& set, const vector<CardP>& cards, const String& path, const String& filename_template, FilenameConflicts conflicts) {
{
wxBusyCursor busy; wxBusyCursor busy;
// Script // Script
ScriptP filename_script = parse(filename_template, nullptr, true); ScriptP filename_script = parse(filename_template, nullptr, true);
+6 -3
View File
@@ -165,7 +165,8 @@ bool CardListBase::doCopy() {
if (cards_to_copy.empty()) return false; if (cards_to_copy.empty()) return false;
// put on clipboard // put on clipboard
if (!wxTheClipboard->Open()) return false; if (!wxTheClipboard->Open()) return false;
bool ok = wxTheClipboard->SetData(new CardsOnClipboard(set, _(""), cards_to_copy)); // ignore result bool ok = wxTheClipboard->SetData(new CardsOnClipboard(set, _(""), cards_to_copy)); // ignore result
wxTheClipboard->Flush();
wxTheClipboard->Close(); wxTheClipboard->Close();
return ok; return ok;
} }
@@ -191,7 +192,8 @@ bool CardListBase::doCopyCardAndLinkedCards() {
} }
} }
} }
bool ok = wxTheClipboard->SetData(new CardsOnClipboard(set, _(""), cards_to_copy)); // ignore result bool ok = wxTheClipboard->SetData(new CardsOnClipboard(set, _(""), cards_to_copy)); // ignore result
wxTheClipboard->Flush();
wxTheClipboard->Close(); wxTheClipboard->Close();
return ok; return ok;
} }
@@ -199,7 +201,8 @@ bool CardListBase::doCopyCardAndLinkedCards() {
bool CardListBase::doPaste() { bool CardListBase::doPaste() {
if (!canPaste()) return false; if (!canPaste()) return false;
if (!wxTheClipboard->Open()) return false; if (!wxTheClipboard->Open()) return false;
bool ok = wxTheClipboard->GetData(*drop_target->data_object); bool ok = wxTheClipboard->GetData(*drop_target->data_object);
wxTheClipboard->Flush();
wxTheClipboard->Close(); wxTheClipboard->Close();
if (ok) return parseData(false); if (ok) return parseData(false);
return false; return false;
+2
View File
@@ -109,6 +109,7 @@ bool KeywordList::doCopy() {
if (!canCopy()) return false; if (!canCopy()) return false;
if (!wxTheClipboard->Open()) return false; if (!wxTheClipboard->Open()) return false;
bool ok = wxTheClipboard->SetData(new KeywordDataObject(set, getKeyword())); // ignore result bool ok = wxTheClipboard->SetData(new KeywordDataObject(set, getKeyword())); // ignore result
wxTheClipboard->Flush();
wxTheClipboard->Close(); wxTheClipboard->Close();
return ok; return ok;
} }
@@ -125,6 +126,7 @@ bool KeywordList::doPaste() {
if (!wxTheClipboard->Open()) return false; if (!wxTheClipboard->Open()) return false;
KeywordDataObject data; KeywordDataObject data;
bool ok = wxTheClipboard->GetData(data); bool ok = wxTheClipboard->GetData(data);
wxTheClipboard->Flush();
wxTheClipboard->Close(); wxTheClipboard->Close();
if (!ok) return false; if (!ok) return false;
// add keyword to set // add keyword to set
+1
View File
@@ -107,6 +107,7 @@ public:
} else { } else {
ok = wxTheClipboard->SetData(new wxTextDataObject(msg.text)); ok = wxTheClipboard->SetData(new wxTextDataObject(msg.text));
} }
wxTheClipboard->Flush();
wxTheClipboard->Close(); wxTheClipboard->Close();
return ok; return ok;
} }
+4 -2
View File
@@ -92,7 +92,8 @@ bool ImageValueEditor::doCopy() {
if (!image_load_file(image, *image_file)) return false; if (!image_load_file(image, *image_file)) return false;
// set data // set data
if (!wxTheClipboard->Open()) return false; if (!wxTheClipboard->Open()) return false;
bool ok = wxTheClipboard->SetData(new wxBitmapDataObject(image)); bool ok = wxTheClipboard->SetData(new wxBitmapDataObject(image));
wxTheClipboard->Flush();
wxTheClipboard->Close(); wxTheClipboard->Close();
return ok; return ok;
} }
@@ -101,7 +102,8 @@ bool ImageValueEditor::doPaste() {
// get bitmap // get bitmap
if (!wxTheClipboard->Open()) return false; if (!wxTheClipboard->Open()) return false;
wxBitmapDataObject data; wxBitmapDataObject data;
bool ok = wxTheClipboard->GetData(data); bool ok = wxTheClipboard->GetData(data);
wxTheClipboard->Flush();
wxTheClipboard->Close(); wxTheClipboard->Close();
if (!ok) return false; if (!ok) return false;
// slice // slice
+4 -2
View File
@@ -782,7 +782,8 @@ bool TextValueEditor::doPaste() {
// get data // get data
if (!wxTheClipboard->Open()) return false; if (!wxTheClipboard->Open()) return false;
wxTextDataObject data; wxTextDataObject data;
bool ok = wxTheClipboard->GetData(data); bool ok = wxTheClipboard->GetData(data);
wxTheClipboard->Flush();
wxTheClipboard->Close(); wxTheClipboard->Close();
if (!ok) return false; if (!ok) return false;
// paste // paste
@@ -800,7 +801,8 @@ bool TextValueEditor::doCopy() {
if (str.empty()) return false; // no data to copy if (str.empty()) return false; // no data to copy
// set data // set data
if (!wxTheClipboard->Open()) return false; if (!wxTheClipboard->Open()) return false;
bool ok = wxTheClipboard->SetData(new wxTextDataObject(str)); bool ok = wxTheClipboard->SetData(new wxTextDataObject(str));
wxTheClipboard->Flush();
wxTheClipboard->Close(); wxTheClipboard->Close();
return ok; return ok;
} }