1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include "undorangename.hxx"
11 #include "globstr.hrc"
13 #include "docfunc.hxx"
16 #include <o3tl/ptr_container.hxx>
17 #include <sfx2/app.hxx>
22 using ::std::unique_ptr
;
24 ScUndoAllRangeNames::ScUndoAllRangeNames(
26 const std::map
<OUString
, ScRangeName
*>& rOldNames
,
27 const boost::ptr_map
<OUString
, ScRangeName
>& rNewNames
) :
30 std::map
<OUString
, ScRangeName
*>::const_iterator itr
, itrEnd
;
31 for (itr
= rOldNames
.begin(), itrEnd
= rOldNames
.end(); itr
!= itrEnd
; ++itr
)
33 unique_ptr
<ScRangeName
> p(new ScRangeName(*itr
->second
));
34 o3tl::ptr_container::insert(maOldNames
, itr
->first
, std::move(p
));
37 boost::ptr_map
<OUString
, ScRangeName
>::const_iterator it
, itEnd
;
38 for (it
= rNewNames
.begin(), itEnd
= rNewNames
.end(); it
!= itEnd
; ++it
)
40 unique_ptr
<ScRangeName
> p(new ScRangeName(*it
->second
));
41 o3tl::ptr_container::insert(maNewNames
, it
->first
, std::move(p
));
45 ScUndoAllRangeNames::~ScUndoAllRangeNames()
49 void ScUndoAllRangeNames::Undo()
54 void ScUndoAllRangeNames::Redo()
59 void ScUndoAllRangeNames::Repeat(SfxRepeatTarget
& /*rTarget*/)
63 bool ScUndoAllRangeNames::CanRepeat(SfxRepeatTarget
& /*rTarget*/) const
68 OUString
ScUndoAllRangeNames::GetComment() const
70 return ScGlobal::GetRscString(STR_UNDO_RANGENAMES
);
73 void ScUndoAllRangeNames::DoChange(const boost::ptr_map
<OUString
, ScRangeName
>& rNames
)
75 ScDocument
& rDoc
= pDocShell
->GetDocument();
77 rDoc
.PreprocessRangeNameUpdate();
78 rDoc
.SetAllRangeNames(rNames
);
79 rDoc
.CompileHybridFormula();
81 SfxGetpApp()->Broadcast(SfxSimpleHint(SC_HINT_AREAS_CHANGED
));
84 ScUndoAddRangeData::ScUndoAddRangeData(ScDocShell
* pDocSh
, ScRangeData
* pRangeData
, SCTAB nTab
) :
86 mpRangeData(new ScRangeData(*pRangeData
)),
92 ScUndoAddRangeData::~ScUndoAddRangeData()
97 void ScUndoAddRangeData::Undo()
99 ScDocument
& rDoc
= pDocShell
->GetDocument();
100 ScRangeName
* pRangeName
= NULL
;
103 pRangeName
= rDoc
.GetRangeName();
107 pRangeName
= rDoc
.GetRangeName( mnTab
);
109 pRangeName
->erase(*mpRangeData
);
110 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED
) );
114 void ScUndoAddRangeData::Redo()
116 ScDocument
& rDoc
= pDocShell
->GetDocument();
117 ScRangeName
* pRangeName
= NULL
;
120 pRangeName
= rDoc
.GetRangeName();
124 pRangeName
= rDoc
.GetRangeName( mnTab
);
126 pRangeName
->insert(new ScRangeData(*mpRangeData
));
127 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED
) );
130 void ScUndoAddRangeData::Repeat(SfxRepeatTarget
& /*rTarget*/)
134 bool ScUndoAddRangeData::CanRepeat(SfxRepeatTarget
& /*rTarget*/) const
139 OUString
ScUndoAddRangeData::GetComment() const
141 return ScGlobal::GetRscString(STR_UNDO_RANGENAMES
);
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */