diff --git a/src/mycanvas.h b/src/mycanvas.h index 93bdc99d..60d00134 100644 --- a/src/mycanvas.h +++ b/src/mycanvas.h @@ -1,6 +1,6 @@ struct TSCanvas : public wxScrolledCanvas { MyFrame *frame; - Document *doc {nullptr}; + unique_ptr doc; int mousewheelaccum {0}; bool lastrmbwaswithctrl {false}; wxPoint lastmousepos; @@ -17,10 +17,7 @@ struct TSCanvas : public wxScrolledCanvas { EnableScrolling(false, false); } - ~TSCanvas() { - DELETEP(doc); - frame = nullptr; - } + ~TSCanvas() { frame = nullptr; } void OnPaint(wxPaintEvent &event) { #if defined(__WXMAC__) || defined(__WXGTK__) diff --git a/src/myframe.h b/src/myframe.h index 61d16581..c2742473 100644 --- a/src/myframe.h +++ b/src/myframe.h @@ -742,7 +742,7 @@ struct MyFrame : wxFrame { TSCanvas *NewTab(Document *doc, bool append = false) { TSCanvas *sw = new TSCanvas(this, nb); - sw->doc = doc; + sw->doc.reset(doc); doc->sw = sw; sw->SetScrollRate(1, 1); if (append) @@ -773,7 +773,7 @@ struct MyFrame : wxFrame { TSCanvas *sw = (TSCanvas *)nb->GetPage(nbe.GetSelection()); sw->Status(); SetSearchTextBoxBackgroundColour(false); - sys->TabChange(sw->doc); + sys->TabChange(sw->doc.get()); } void TabsReset() { @@ -1082,7 +1082,7 @@ struct MyFrame : wxFrame { sys->darkennonmatchingcells = searchstring.Len() != 0; sys->searchstring = (sys->casesensitivesearch) ? searchstring : searchstring.Lower(); SetSearchTextBoxBackgroundColour(false); - Document *doc = GetCurTab()->doc; + Document *doc = GetCurTab()->doc.get(); TSCanvas *sw = GetCurTab(); wxClientDC dc(sw); doc->SearchNext(dc, false, false, false); @@ -1275,7 +1275,7 @@ struct MyFrame : wxFrame { if ((event.GetChangeType() & 0xF) == 0 || watcherwaitingforuser || !nb) return; const wxString &modfile = event.GetPath().GetFullPath(); loop(i, nb->GetPageCount()) { - Document *doc = ((TSCanvas *)nb->GetPage(i))->doc; + Document *doc = ((TSCanvas *)nb->GetPage(i))->doc.get(); if (modfile == doc->filename) { wxDateTime modtime = wxFileName(modfile).GetModificationTime(); // Compare with last modified to trigger multiple times. @@ -1307,7 +1307,7 @@ struct MyFrame : wxFrame { if (*msg) { GetCurTab()->Status(msg); } else { - loop(j, nb->GetPageCount()) if (((TSCanvas *)nb->GetPage(j))->doc == doc) + loop(j, nb->GetPageCount()) if (((TSCanvas *)nb->GetPage(j))->doc.get() == doc) nb->DeletePage(j); ::wxRemoveFile(sys->TmpName(modfile)); GetCurTab()->Status( diff --git a/src/mywxtools.h b/src/mywxtools.h index 762d6d95..0cf1c0e4 100644 --- a/src/mywxtools.h +++ b/src/mywxtools.h @@ -23,7 +23,7 @@ struct DropTarget : wxDropTarget { GetData(); TSCanvas *sw = sys->frame->GetCurTab(); sw->SelectClick(x, y, false, 0); - Document *doc = sw->doc; + Document *doc = sw->doc.get(); switch (doc->dndobjc->GetReceivedFormat().GetType()) { case wxDF_BITMAP: doc->PasteOrDrop(*doc->dndobji); break; case wxDF_FILENAME: doc->PasteOrDrop(*doc->dndobjf); break; diff --git a/src/treesheets_impl.h b/src/treesheets_impl.h index dc505c1d..6595cf43 100644 --- a/src/treesheets_impl.h +++ b/src/treesheets_impl.h @@ -7,7 +7,7 @@ struct TreeSheetsScriptImpl : public ScriptInterface { enum { max_new_grid_cells = 256 * 256 }; // Don't allow crazy sizes. void SwitchToCurrentDoc() { - doc = sys->frame->GetCurTab()->doc; + doc = sys->frame->GetCurTab()->doc.get(); cur = doc->rootgrid.get(); doc->AddUndo(cur);