From c438af62380a13ab7155ba3301f212ee583ddd8a Mon Sep 17 00:00:00 2001 From: Tobias Predel Date: Fri, 29 Mar 2024 16:58:20 +0100 Subject: [PATCH] Put clipboard data on the system stack (#617) The clipboard data structures are created by the first document on the heap and then are subsequently overridden by other documents. It can be a better design to put the clipboard data into one central place on the stack of `System` as it is available during the lifetime of the program. --- src/document.h | 30 +++++++++--------------------- src/myframe.h | 2 +- src/system.h | 12 ++++++++++++ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/document.h b/src/document.h index 85a35730..cb0d7c91 100755 --- a/src/document.h +++ b/src/document.h @@ -28,12 +28,6 @@ struct Document { wxString filename; long lastmodsinceautosave, undolistsizeatfullsave, lastsave; bool modified, tmpsavesuccess; - wxDataObjectComposite *dataobjc; - wxTextDataObject *dataobjt; - wxBitmapDataObject *dataobji; - wxFileDataObject *dataobjf; - //wxHTMLDataObject *dataobjh; - //wxRichTextBufferDataObject *dataobjr; struct MyPrintout : wxPrintout { Document *doc; @@ -118,12 +112,6 @@ struct Document { currentviewscale(1), searchfilter(false), editfilter(0) { - dataobjc = new wxDataObjectComposite(); // deleted by DropTarget - dataobjc->Add(dataobji = new wxBitmapDataObject()); - dataobjc->Add(dataobjt = new wxTextDataObject()); - dataobjc->Add(dataobjf = new wxFileDataObject()); - //dataobjc->Add(dataobjh = new wxHTMLDataObject(), true); // Prefer HTML over text, doesn't seem to work. - //dataobjc->Add(dataobjr = new wxRichTextBufferDataObject()); ResetFont(); pageSetupData = printData; pageSetupData.SetMarginTopLeft(wxPoint(15, 15)); @@ -1582,7 +1570,7 @@ struct Document { case A_PASTE: if (!(c = selected.ThinExpand(this))) return OneCell(); if (wxTheClipboard->Open()) { - wxTheClipboard->GetData(*dataobjc); + wxTheClipboard->GetData(sys->dataobjc); PasteOrDrop(); wxTheClipboard->Close(); } else if (sys->cellclipboard) { @@ -2099,9 +2087,9 @@ struct Document { Cell *c = selected.ThinExpand(this); if (!c) return; wxBusyCursor wait; - switch (dataobjc->GetReceivedFormat().GetType()) { + switch (sys->dataobjc.GetReceivedFormat().GetType()) { case wxDF_FILENAME: { - const wxArrayString &as = dataobjf->GetFilenames(); + const wxArrayString &as = sys->dataobjf.GetFilenames(); if (as.size()) { if (as.size() > 1) sw->Status(_(L"Cannot drag & drop more than 1 file.")); c->AddUndo(this); @@ -2116,12 +2104,12 @@ struct Document { #ifdef __WXMSW__ case wxDF_PNG: #endif - if (dataobji->GetBitmap().GetRefData() != wxNullBitmap.GetRefData()) { + if (sys->dataobji.GetBitmap().GetRefData() != wxNullBitmap.GetRefData()) { c->AddUndo(this); - wxImage im = dataobji->GetBitmap().ConvertToImage(); + wxImage im = sys->dataobji.GetBitmap().ConvertToImage(); vector idv = ConvertWxImageToBuffer(im, wxBITMAP_TYPE_PNG); SetImageBM(c, std::move(idv), sys->frame->csf); - dataobji->SetBitmap(wxNullBitmap); + sys->dataobji.SetBitmap(wxNullBitmap); c->Reset(); Refresh(); } @@ -2138,8 +2126,8 @@ struct Document { } */ default: // several text formats - if (dataobjt->GetText() != wxEmptyString) { - wxString s = dataobjt->GetText(); + if (sys->dataobjt.GetText() != wxEmptyString) { + wxString s = sys->dataobjt.GetText(); if ((sys->clipboardcopy == s) && sys->cellclipboard) { c->Paste(this, sys->cellclipboard.get(), selected); Refresh(); @@ -2161,7 +2149,7 @@ struct Document { Refresh(); } } - dataobjt->SetText(wxEmptyString); + sys->dataobjt.SetText(wxEmptyString); } break; } diff --git a/src/myframe.h b/src/myframe.h index 54b4854d..55a6d269 100755 --- a/src/myframe.h +++ b/src/myframe.h @@ -789,7 +789,7 @@ struct MyFrame : wxFrame { nb->AddPage(sw, _(L""), true, wxNullBitmap); else nb->InsertPage(0, sw, _(L""), true, wxNullBitmap); - sw->SetDropTarget(new DropTarget(doc->dataobjc)); + sw->SetDropTarget(new DropTarget(&sys->dataobjc)); sw->SetFocus(); return sw; } diff --git a/src/system.h b/src/system.h index 361c631c..9337304e 100755 --- a/src/system.h +++ b/src/system.h @@ -81,6 +81,12 @@ struct System { uint lastcellcolor = 0xFFFFFF; uint lasttextcolor = 0; uint lastbordcolor = 0xA0A0A0; + wxDataObjectComposite dataobjc; + wxTextDataObject dataobjt; + wxBitmapDataObject dataobji; + wxFileDataObject dataobjf; + //wxHTMLDataObject dataobjh; + //wxRichTextBufferDataObject dataobjr; System(bool portable) : defaultfont( @@ -141,6 +147,12 @@ struct System { // fsw.Connect(wxID_ANY, wxID_ANY, wxEVT_FSWATCHER, // wxFileSystemWatcherEventHandler(System::OnFileChanged)); + + dataobjc.Add(&dataobji); + dataobjc.Add(&dataobjt); + dataobjc.Add(&dataobjf); + //dataobjc.Add(dataobjh, true); // Prefer HTML over text, doesn't seem to work. + //dataobjc.Add(dataobjr); } ~System() {