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/.
11 #include "undorangename.hxx"
12 #include "globstr.hrc"
14 #include "docfunc.hxx"
17 #include "sfx2/app.hxx"
21 using ::std::auto_ptr
;
23 ScUndoAllRangeNames::ScUndoAllRangeNames(
25 const std::map
<OUString
, ScRangeName
*>& rOldNames
,
26 const boost::ptr_map
<OUString
, ScRangeName
>& rNewNames
) :
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()
57 void ScUndoAllRangeNames::Redo()
62 void ScUndoAllRangeNames::Repeat(SfxRepeatTarget
& /*rTarget*/)
66 bool ScUndoAllRangeNames::CanRepeat(SfxRepeatTarget
& /*rTarget*/) const
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
) :
91 mpRangeData(new ScRangeData(*pRangeData
)),
97 ScUndoAddRangeData::~ScUndoAddRangeData()
102 void ScUndoAddRangeData::Undo()
104 ScDocument
* pDoc
= pDocShell
->GetDocument();
105 ScRangeName
* pRangeName
= NULL
;
108 pRangeName
= pDoc
->GetRangeName();
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
;
125 pRangeName
= pDoc
->GetRangeName();
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
144 OUString
ScUndoAddRangeData::GetComment() const
146 return ScGlobal::GetRscString(STR_UNDO_RANGENAMES
);
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */