Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / undo / undorangename.cxx
blobbaf39b2f49147e106587ad57267863072019e79d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
11 #include "undorangename.hxx"
12 #include "globstr.hrc"
13 #include "global.hxx"
14 #include "docfunc.hxx"
15 #include "sc.hrc"
17 #include "sfx2/app.hxx"
19 #include <memory>
21 using ::std::auto_ptr;
23 ScUndoAllRangeNames::ScUndoAllRangeNames(
24 ScDocShell* pDocSh,
25 const std::map<OUString, ScRangeName*>& rOldNames,
26 const boost::ptr_map<OUString, ScRangeName>& rNewNames) :
27 ScSimpleUndo(pDocSh)
29 std::map<OUString, ScRangeName*>::const_iterator itr, itrEnd;
30 for (itr = rOldNames.begin(), itrEnd = rOldNames.end(); itr != itrEnd; ++itr)
32 SAL_WNODEPRECATED_DECLARATIONS_PUSH
33 auto_ptr<ScRangeName> p(new ScRangeName(*itr->second));
34 SAL_WNODEPRECATED_DECLARATIONS_POP
35 maOldNames.insert(itr->first, p);
38 boost::ptr_map<OUString, ScRangeName>::const_iterator it, itEnd;
39 for (it = rNewNames.begin(), itEnd = rNewNames.end(); it != itEnd; ++it)
41 SAL_WNODEPRECATED_DECLARATIONS_PUSH
42 auto_ptr<ScRangeName> p(new ScRangeName(*it->second));
43 SAL_WNODEPRECATED_DECLARATIONS_POP
44 maNewNames.insert(it->first, p);
48 ScUndoAllRangeNames::~ScUndoAllRangeNames()
52 void ScUndoAllRangeNames::Undo()
54 DoChange(maOldNames);
57 void ScUndoAllRangeNames::Redo()
59 DoChange(maNewNames);
62 void ScUndoAllRangeNames::Repeat(SfxRepeatTarget& /*rTarget*/)
66 bool ScUndoAllRangeNames::CanRepeat(SfxRepeatTarget& /*rTarget*/) const
68 return false;
71 OUString ScUndoAllRangeNames::GetComment() const
73 return ScGlobal::GetRscString(STR_UNDO_RANGENAMES);
76 void ScUndoAllRangeNames::DoChange(const boost::ptr_map<OUString, ScRangeName>& rNames)
78 ScDocument& rDoc = *pDocShell->GetDocument();
80 rDoc.CompileNameFormula(true);
82 rDoc.SetAllRangeNames(rNames);
84 rDoc.CompileNameFormula(true);
86 SFX_APP()->Broadcast(SfxSimpleHint(SC_HINT_AREAS_CHANGED));
89 ScUndoAddRangeData::ScUndoAddRangeData(ScDocShell* pDocSh, ScRangeData* pRangeData, SCTAB nTab) :
90 ScSimpleUndo(pDocSh),
91 mpRangeData(new ScRangeData(*pRangeData)),
92 mnTab(nTab)
97 ScUndoAddRangeData::~ScUndoAddRangeData()
99 delete mpRangeData;
102 void ScUndoAddRangeData::Undo()
104 ScDocument* pDoc = pDocShell->GetDocument();
105 ScRangeName* pRangeName = NULL;
106 if (mnTab == -1)
108 pRangeName = pDoc->GetRangeName();
110 else
112 pRangeName = pDoc->GetRangeName( mnTab );
114 pRangeName->erase(*mpRangeData);
115 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
119 void ScUndoAddRangeData::Redo()
121 ScDocument* pDoc = pDocShell->GetDocument();
122 ScRangeName* pRangeName = NULL;
123 if (mnTab == -1)
125 pRangeName = pDoc->GetRangeName();
127 else
129 pRangeName = pDoc->GetRangeName( mnTab );
131 pRangeName->insert(new ScRangeData(*mpRangeData));
132 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
135 void ScUndoAddRangeData::Repeat(SfxRepeatTarget& /*rTarget*/)
139 bool ScUndoAddRangeData::CanRepeat(SfxRepeatTarget& /*rTarget*/) const
141 return false;
144 OUString ScUndoAddRangeData::GetComment() const
146 return ScGlobal::GetRscString(STR_UNDO_RANGENAMES);
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */