Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License. You may obtain a copy of the License at
8 : : * http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * The Initial Developer of the Original Code is
16 : : * Kohei Yoshida <kyoshida@novell.com> (Novell, Inc.)
17 : : * Portions created by the Initial Developer are Copyright (C) 2010 the
18 : : * Initial Developer. All Rights Reserved.
19 : : *
20 : : * Contributor(s):
21 : : *
22 : : * Alternatively, the contents of this file may be used under the terms of
23 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : : * instead of those above.
27 : : */
28 : :
29 : :
30 : : #include "undorangename.hxx"
31 : : #include "globstr.hrc"
32 : : #include "global.hxx"
33 : : #include "docfunc.hxx"
34 : : #include "sc.hrc"
35 : :
36 : : #include "sfx2/app.hxx"
37 : :
38 : : #include <memory>
39 : :
40 : : using ::std::auto_ptr;
41 : :
42 : 0 : ScUndoAllRangeNames::ScUndoAllRangeNames(
43 : : ScDocShell* pDocSh,
44 : : const std::map<rtl::OUString, ScRangeName*>& rOldNames,
45 : : const boost::ptr_map<rtl::OUString, ScRangeName>& rNewNames) :
46 [ # # ][ # # ]: 0 : ScSimpleUndo(pDocSh)
47 : : {
48 : 0 : std::map<rtl::OUString, ScRangeName*>::const_iterator itr, itrEnd;
49 [ # # ]: 0 : for (itr = rOldNames.begin(), itrEnd = rOldNames.end(); itr != itrEnd; ++itr)
50 : : {
51 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
52 [ # # ][ # # ]: 0 : auto_ptr<ScRangeName> p(new ScRangeName(*itr->second));
53 : : SAL_WNODEPRECATED_DECLARATIONS_POP
54 [ # # ][ # # ]: 0 : maOldNames.insert(itr->first, p);
55 [ # # ]: 0 : }
56 : :
57 [ # # ][ # # ]: 0 : boost::ptr_map<rtl::OUString, ScRangeName>::const_iterator it, itEnd;
58 [ # # ][ # # ]: 0 : for (it = rNewNames.begin(), itEnd = rNewNames.end(); it != itEnd; ++it)
[ # # ][ # # ]
[ # # ]
59 : : {
60 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
61 [ # # ][ # # ]: 0 : auto_ptr<ScRangeName> p(new ScRangeName(*it->second));
[ # # ]
62 : : SAL_WNODEPRECATED_DECLARATIONS_POP
63 [ # # ][ # # ]: 0 : maNewNames.insert(it->first, p);
[ # # ]
64 [ # # ]: 0 : }
65 : 0 : }
66 : :
67 [ # # ][ # # ]: 0 : ScUndoAllRangeNames::~ScUndoAllRangeNames()
68 : : {
69 [ # # ]: 0 : }
70 : :
71 : 0 : void ScUndoAllRangeNames::Undo()
72 : : {
73 : 0 : DoChange(maOldNames);
74 : 0 : }
75 : :
76 : 0 : void ScUndoAllRangeNames::Redo()
77 : : {
78 : 0 : DoChange(maNewNames);
79 : 0 : }
80 : :
81 : 0 : void ScUndoAllRangeNames::Repeat(SfxRepeatTarget& /*rTarget*/)
82 : : {
83 : 0 : }
84 : :
85 : 0 : sal_Bool ScUndoAllRangeNames::CanRepeat(SfxRepeatTarget& /*rTarget*/) const
86 : : {
87 : 0 : return sal_False;
88 : : }
89 : :
90 : 0 : rtl::OUString ScUndoAllRangeNames::GetComment() const
91 : : {
92 : 0 : return ScGlobal::GetRscString(STR_UNDO_RANGENAMES);
93 : : }
94 : :
95 : 0 : void ScUndoAllRangeNames::DoChange(const boost::ptr_map<rtl::OUString, ScRangeName>& rNames)
96 : : {
97 : 0 : ScDocument& rDoc = *pDocShell->GetDocument();
98 : :
99 : 0 : rDoc.CompileNameFormula(true);
100 : :
101 : 0 : rDoc.SetAllRangeNames(rNames);
102 : :
103 : 0 : rDoc.CompileNameFormula(true);
104 : :
105 [ # # ][ # # ]: 0 : SFX_APP()->Broadcast(SfxSimpleHint(SC_HINT_AREAS_CHANGED));
106 : 0 : }
107 : :
108 : 0 : ScUndoAddRangeData::ScUndoAddRangeData(ScDocShell* pDocSh, ScRangeData* pRangeData, SCTAB nTab) :
109 : : ScSimpleUndo(pDocSh),
110 [ # # ]: 0 : mpRangeData(new ScRangeData(*pRangeData)),
111 [ # # ]: 0 : mnTab(nTab)
112 : : {
113 : :
114 : 0 : }
115 : :
116 : 0 : ScUndoAddRangeData::~ScUndoAddRangeData()
117 : : {
118 [ # # ][ # # ]: 0 : delete mpRangeData;
119 [ # # ]: 0 : }
120 : :
121 : 0 : void ScUndoAddRangeData::Undo()
122 : : {
123 : 0 : ScDocument* pDoc = pDocShell->GetDocument();
124 : 0 : ScRangeName* pRangeName = NULL;
125 [ # # ]: 0 : if (mnTab == -1)
126 : : {
127 : 0 : pRangeName = pDoc->GetRangeName();
128 : : }
129 : : else
130 : : {
131 : 0 : pRangeName = pDoc->GetRangeName( mnTab );
132 : : }
133 : 0 : pRangeName->erase(*mpRangeData);
134 [ # # ][ # # ]: 0 : SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
135 : :
136 : 0 : }
137 : :
138 : 0 : void ScUndoAddRangeData::Redo()
139 : : {
140 : 0 : ScDocument* pDoc = pDocShell->GetDocument();
141 : 0 : ScRangeName* pRangeName = NULL;
142 [ # # ]: 0 : if (mnTab == -1)
143 : : {
144 : 0 : pRangeName = pDoc->GetRangeName();
145 : : }
146 : : else
147 : : {
148 : 0 : pRangeName = pDoc->GetRangeName( mnTab );
149 : : }
150 [ # # ]: 0 : pRangeName->insert(new ScRangeData(*mpRangeData));
151 [ # # ][ # # ]: 0 : SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
152 : 0 : }
153 : :
154 : 0 : void ScUndoAddRangeData::Repeat(SfxRepeatTarget& /*rTarget*/)
155 : : {
156 : 0 : }
157 : :
158 : 0 : sal_Bool ScUndoAddRangeData::CanRepeat(SfxRepeatTarget& /*rTarget*/) const
159 : : {
160 : 0 : return sal_False;
161 : : }
162 : :
163 : 0 : rtl::OUString ScUndoAddRangeData::GetComment() const
164 : : {
165 : 0 : return ScGlobal::GetRscString(STR_UNDO_RANGENAMES);
166 : : }
167 : :
168 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|