Skip to content

Commit

Permalink
Revert "Use unique_ptr for Document in TSCanvas (#780)"
Browse files Browse the repository at this point in the history
This reverts commit e3d4602.
  • Loading branch information
tobiolo committed Jan 16, 2025
1 parent a1ef51f commit a402d73
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/mycanvas.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct TSCanvas : public wxScrolledCanvas {
MyFrame *frame;
unique_ptr<Document> doc;
Document *doc {nullptr};
int mousewheelaccum {0};
bool lastrmbwaswithctrl {false};
wxPoint lastmousepos;
Expand All @@ -17,7 +17,10 @@ struct TSCanvas : public wxScrolledCanvas {
EnableScrolling(false, false);
}

~TSCanvas() { frame = nullptr; }
~TSCanvas() {
DELETEP(doc);
frame = nullptr;
}

void OnPaint(wxPaintEvent &event) {
#if defined(__WXMAC__) || defined(__WXGTK__)
Expand Down
10 changes: 5 additions & 5 deletions src/myframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ struct MyFrame : wxFrame {

TSCanvas *NewTab(Document *doc, bool append = false) {
TSCanvas *sw = new TSCanvas(this, nb);
sw->doc.reset(doc);
sw->doc = doc;
doc->sw = sw;
sw->SetScrollRate(1, 1);
if (append)
Expand Down Expand Up @@ -784,7 +784,7 @@ struct MyFrame : wxFrame {
TSCanvas *sw = (TSCanvas *)nb->GetPage(nbe.GetSelection());
sw->Status();
SetSearchTextBoxBackgroundColour(false);
sys->TabChange(sw->doc.get());
sys->TabChange(sw->doc);
}

void TabsReset() {
Expand Down Expand Up @@ -1093,7 +1093,7 @@ struct MyFrame : wxFrame {
sys->darkennonmatchingcells = searchstring.Len() != 0;
sys->searchstring = (sys->casesensitivesearch) ? searchstring : searchstring.Lower();
SetSearchTextBoxBackgroundColour(false);
Document *doc = GetCurTab()->doc.get();
Document *doc = GetCurTab()->doc;
TSCanvas *sw = GetCurTab();
wxClientDC dc(sw);
doc->SearchNext(dc, false, false, false);
Expand Down Expand Up @@ -1286,7 +1286,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.get();
Document *doc = ((TSCanvas *)nb->GetPage(i))->doc;
if (modfile == doc->filename) {
wxDateTime modtime = wxFileName(modfile).GetModificationTime();
// Compare with last modified to trigger multiple times.
Expand Down Expand Up @@ -1318,7 +1318,7 @@ struct MyFrame : wxFrame {
if (*msg) {
GetCurTab()->Status(msg);
} else {
loop(j, nb->GetPageCount()) if (((TSCanvas *)nb->GetPage(j))->doc.get() == doc)
loop(j, nb->GetPageCount()) if (((TSCanvas *)nb->GetPage(j))->doc == doc)
nb->DeletePage(j);
::wxRemoveFile(sys->TmpName(modfile));
GetCurTab()->Status(
Expand Down
2 changes: 1 addition & 1 deletion src/mywxtools.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct DropTarget : wxDropTarget {
GetData();
TSCanvas *sw = sys->frame->GetCurTab();
sw->SelectClick(x, y, false, 0);
Document *doc = sw->doc.get();
Document *doc = sw->doc;
switch (doc->dndobjc->GetReceivedFormat().GetType()) {
case wxDF_BITMAP: doc->PasteOrDrop(*doc->dndobji); break;
case wxDF_FILENAME: doc->PasteOrDrop(*doc->dndobjf); break;
Expand Down
1 change: 0 additions & 1 deletion src/treesheets_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ struct TreeSheetsScriptImpl : public ScriptInterface {
void SwitchToCurrentDoc() {
doc = sys->frame->GetCurTab()->doc;
cur = doc->rootgrid;

doc->AddUndo(cur);
}

Expand Down

0 comments on commit a402d73

Please sign in to comment.