Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "scitems.hxx"
21 : #include <svx/algitem.hxx>
22 : #include <editeng/boxitem.hxx>
23 : #include <editeng/justifyitem.hxx>
24 : #include <svl/srchitem.hxx>
25 : #include <sfx2/linkmgr.hxx>
26 : #include <sfx2/bindings.hxx>
27 : #include <vcl/virdev.hxx>
28 : #include <sfx2/app.hxx>
29 :
30 : #include "undoblk.hxx"
31 : #include "sc.hrc"
32 : #include "globstr.hrc"
33 : #include "global.hxx"
34 : #include "rangenam.hxx"
35 : #include "arealink.hxx"
36 : #include "patattr.hxx"
37 : #include "target.hxx"
38 : #include "document.hxx"
39 : #include "docpool.hxx"
40 : #include "table.hxx"
41 : #include "docsh.hxx"
42 : #include "tabvwsh.hxx"
43 : #include "undoolk.hxx"
44 : #include "undoutil.hxx"
45 : #include "chgtrack.hxx"
46 : #include "dociter.hxx"
47 : #include "formulacell.hxx"
48 : #include "paramisc.hxx"
49 : #include "postit.hxx"
50 : #include "docuno.hxx"
51 : #include "progress.hxx"
52 : #include "editutil.hxx"
53 : #include "editdataarray.hxx"
54 :
55 : // STATIC DATA ---------------------------------------------------------------
56 :
57 0 : TYPEINIT1(ScUndoDeleteContents, SfxUndoAction);
58 0 : TYPEINIT1(ScUndoFillTable, SfxUndoAction);
59 0 : TYPEINIT1(ScUndoSelectionAttr, SfxUndoAction);
60 0 : TYPEINIT1(ScUndoAutoFill, SfxUndoAction);
61 0 : TYPEINIT1(ScUndoMerge, SfxUndoAction);
62 0 : TYPEINIT1(ScUndoAutoFormat, SfxUndoAction);
63 0 : TYPEINIT1(ScUndoReplace, SfxUndoAction);
64 0 : TYPEINIT1(ScUndoTabOp, SfxUndoAction);
65 0 : TYPEINIT1(ScUndoConversion, SfxUndoAction);
66 0 : TYPEINIT1(ScUndoRefConversion, SfxUndoAction);
67 0 : TYPEINIT1(ScUndoRefreshLink, SfxUndoAction);
68 0 : TYPEINIT1(ScUndoInsertAreaLink, SfxUndoAction);
69 0 : TYPEINIT1(ScUndoRemoveAreaLink, SfxUndoAction);
70 0 : TYPEINIT1(ScUndoUpdateAreaLink, SfxUndoAction);
71 :
72 : // TODO:
73 : /*A*/ // SetOptimalHeight on Document, when no View
74 :
75 75 : ScUndoDeleteContents::ScUndoDeleteContents(
76 : ScDocShell* pNewDocShell,
77 : const ScMarkData& rMark, const ScRange& rRange,
78 : ScDocument* pNewUndoDoc, sal_Bool bNewMulti,
79 : sal_uInt16 nNewFlags, sal_Bool bObjects )
80 : : ScSimpleUndo( pNewDocShell ),
81 : aRange ( rRange ),
82 : aMarkData ( rMark ),
83 : pUndoDoc ( pNewUndoDoc ),
84 : pDrawUndo ( NULL ),
85 : nFlags ( nNewFlags ),
86 75 : bMulti ( bNewMulti ) // unnecessary
87 : {
88 75 : if (bObjects)
89 3 : pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
90 :
91 75 : if ( !(aMarkData.IsMarked() || aMarkData.IsMultiMarked()) ) // if no cell is selected:
92 0 : aMarkData.SetMarkArea( aRange ); // select cell under cursor
93 :
94 75 : SetChangeTrack();
95 75 : }
96 :
97 225 : ScUndoDeleteContents::~ScUndoDeleteContents()
98 : {
99 75 : delete pUndoDoc;
100 75 : DeleteSdrUndoAction( pDrawUndo );
101 150 : }
102 :
103 75 : OUString ScUndoDeleteContents::GetComment() const
104 : {
105 75 : return ScGlobal::GetRscString( STR_UNDO_DELETECONTENTS ); // "Delete"
106 : }
107 :
108 75 : void ScUndoDeleteContents::SetChangeTrack()
109 : {
110 75 : ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
111 75 : if ( pChangeTrack && (nFlags & IDF_CONTENTS) )
112 : pChangeTrack->AppendContentRange( aRange, pUndoDoc,
113 0 : nStartChangeAction, nEndChangeAction );
114 : else
115 75 : nStartChangeAction = nEndChangeAction = 0;
116 75 : }
117 :
118 0 : void ScUndoDeleteContents::DoChange( const sal_Bool bUndo )
119 : {
120 0 : ScDocument* pDoc = pDocShell->GetDocument();
121 :
122 0 : SetViewMarkData( aMarkData );
123 :
124 0 : sal_uInt16 nExtFlags = 0;
125 :
126 0 : if (bUndo) // only Undo
127 : {
128 0 : sal_uInt16 nUndoFlags = IDF_NONE; // copy either all or none of the content
129 0 : if (nFlags & IDF_CONTENTS) // (Only the correct ones have been copied into UndoDoc)
130 0 : nUndoFlags |= IDF_CONTENTS;
131 0 : if (nFlags & IDF_ATTRIB)
132 0 : nUndoFlags |= IDF_ATTRIB;
133 0 : if (nFlags & IDF_EDITATTR) // Edit-Engine attribute
134 0 : nUndoFlags |= IDF_STRING; // -> Cells will be changed
135 : // do not create clones of note captions, they will be restored via drawing undo
136 0 : nUndoFlags |= IDF_NOCAPTIONS;
137 :
138 0 : ScRange aCopyRange = aRange;
139 0 : SCTAB nTabCount = pDoc->GetTableCount();
140 0 : aCopyRange.aStart.SetTab(0);
141 0 : aCopyRange.aEnd.SetTab(nTabCount-1);
142 :
143 0 : pUndoDoc->CopyToDocument( aCopyRange, nUndoFlags, bMulti, pDoc, &aMarkData );
144 :
145 0 : DoSdrUndoAction( pDrawUndo, pDoc );
146 :
147 0 : ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
148 0 : if ( pChangeTrack )
149 0 : pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
150 :
151 0 : pDocShell->UpdatePaintExt( nExtFlags, aRange ); // content after the change
152 : }
153 : else // only Redo
154 : {
155 0 : pDocShell->UpdatePaintExt( nExtFlags, aRange ); // content before the change
156 :
157 0 : aMarkData.MarkToMulti();
158 0 : RedoSdrUndoAction( pDrawUndo );
159 : // do not delete objects and note captions, they have been removed via drawing undo
160 0 : sal_uInt16 nRedoFlags = (nFlags & ~IDF_OBJECTS) | IDF_NOCAPTIONS;
161 0 : pDoc->DeleteSelection( nRedoFlags, aMarkData );
162 0 : aMarkData.MarkToSimple();
163 :
164 0 : SetChangeTrack();
165 : }
166 :
167 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
168 0 : if ( !( (pViewShell) && pViewShell->AdjustRowHeight(
169 0 : aRange.aStart.Row(), aRange.aEnd.Row() ) ) )
170 0 : /*A*/ pDocShell->PostPaint( aRange, PAINT_GRID | PAINT_EXTRAS, nExtFlags );
171 :
172 0 : pDocShell->PostDataChanged();
173 0 : if (pViewShell)
174 0 : pViewShell->CellContentChanged();
175 :
176 0 : ShowTable( aRange );
177 0 : }
178 :
179 0 : void ScUndoDeleteContents::Undo()
180 : {
181 0 : BeginUndo();
182 0 : DoChange( sal_True );
183 0 : EndUndo();
184 :
185 : // #i97876# Spreadsheet data changes are not notified
186 0 : ScModelObj* pModelObj = ScModelObj::getImplementation( pDocShell->GetModel() );
187 0 : if ( pModelObj && pModelObj->HasChangesListeners() )
188 : {
189 0 : ScRangeList aChangeRanges;
190 0 : aChangeRanges.Append( aRange );
191 0 : pModelObj->NotifyChanges( OUString( "cell-change" ), aChangeRanges );
192 : }
193 0 : }
194 :
195 0 : void ScUndoDeleteContents::Redo()
196 : {
197 0 : BeginRedo();
198 0 : DoChange( false );
199 0 : EndRedo();
200 :
201 : // #i97876# Spreadsheet data changes are not notified
202 0 : ScModelObj* pModelObj = ScModelObj::getImplementation( pDocShell->GetModel() );
203 0 : if ( pModelObj && pModelObj->HasChangesListeners() )
204 : {
205 0 : ScRangeList aChangeRanges;
206 0 : aChangeRanges.Append( aRange );
207 0 : pModelObj->NotifyChanges( OUString( "cell-change" ), aChangeRanges );
208 : }
209 0 : }
210 :
211 0 : void ScUndoDeleteContents::Repeat(SfxRepeatTarget& rTarget)
212 : {
213 0 : if (rTarget.ISA(ScTabViewTarget))
214 0 : ((ScTabViewTarget&)rTarget).GetViewShell()->DeleteContents( nFlags, sal_True );
215 0 : }
216 :
217 0 : bool ScUndoDeleteContents::CanRepeat(SfxRepeatTarget& rTarget) const
218 : {
219 0 : return rTarget.ISA(ScTabViewTarget);
220 : }
221 :
222 0 : ScUndoFillTable::ScUndoFillTable( ScDocShell* pNewDocShell,
223 : const ScMarkData& rMark,
224 : SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
225 : SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
226 : ScDocument* pNewUndoDoc, sal_Bool bNewMulti, SCTAB nSrc,
227 : sal_uInt16 nFlg, sal_uInt16 nFunc, sal_Bool bSkip, sal_Bool bLink )
228 : : ScSimpleUndo( pNewDocShell ),
229 : aRange ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
230 : aMarkData ( rMark ),
231 : pUndoDoc ( pNewUndoDoc ),
232 : nFlags ( nFlg ),
233 : nFunction ( nFunc ),
234 : nSrcTab ( nSrc ),
235 : bMulti ( bNewMulti ),
236 : bSkipEmpty ( bSkip ),
237 0 : bAsLink ( bLink )
238 : {
239 0 : SetChangeTrack();
240 0 : }
241 :
242 0 : ScUndoFillTable::~ScUndoFillTable()
243 : {
244 0 : delete pUndoDoc;
245 0 : }
246 :
247 0 : OUString ScUndoFillTable::GetComment() const
248 : {
249 0 : return ScGlobal::GetRscString( STR_FILL_TAB );
250 : }
251 :
252 0 : void ScUndoFillTable::SetChangeTrack()
253 : {
254 0 : ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
255 0 : if ( pChangeTrack )
256 : {
257 0 : SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount();
258 0 : ScRange aWorkRange(aRange);
259 0 : nStartChangeAction = 0;
260 : sal_uLong nTmpAction;
261 0 : ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
262 0 : for (; itr != itrEnd && *itr < nTabCount; ++itr)
263 : {
264 0 : if (*itr != nSrcTab)
265 : {
266 0 : aWorkRange.aStart.SetTab(*itr);
267 0 : aWorkRange.aEnd.SetTab(*itr);
268 : pChangeTrack->AppendContentRange( aWorkRange, pUndoDoc,
269 0 : nTmpAction, nEndChangeAction );
270 0 : if ( !nStartChangeAction )
271 0 : nStartChangeAction = nTmpAction;
272 : }
273 : }
274 : }
275 : else
276 0 : nStartChangeAction = nEndChangeAction = 0;
277 0 : }
278 :
279 0 : void ScUndoFillTable::DoChange( const sal_Bool bUndo )
280 : {
281 0 : ScDocument* pDoc = pDocShell->GetDocument();
282 :
283 0 : SetViewMarkData( aMarkData );
284 :
285 0 : if (bUndo) // only Undo
286 : {
287 0 : SCTAB nTabCount = pDoc->GetTableCount();
288 0 : ScRange aWorkRange(aRange);
289 0 : ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
290 0 : for (; itr != itrEnd && *itr < nTabCount; ++itr)
291 0 : if (*itr != nSrcTab)
292 : {
293 0 : aWorkRange.aStart.SetTab(*itr);
294 0 : aWorkRange.aEnd.SetTab(*itr);
295 0 : if (bMulti)
296 0 : pDoc->DeleteSelectionTab( *itr, IDF_ALL, aMarkData );
297 : else
298 0 : pDoc->DeleteAreaTab( aWorkRange, IDF_ALL );
299 0 : pUndoDoc->CopyToDocument( aWorkRange, IDF_ALL, bMulti, pDoc, &aMarkData );
300 : }
301 :
302 0 : ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
303 0 : if ( pChangeTrack )
304 0 : pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
305 : }
306 : else // only Redo
307 : {
308 0 : aMarkData.MarkToMulti();
309 0 : pDoc->FillTabMarked( nSrcTab, aMarkData, nFlags, nFunction, bSkipEmpty, bAsLink );
310 0 : aMarkData.MarkToSimple();
311 0 : SetChangeTrack();
312 : }
313 :
314 0 : pDocShell->PostPaint(0,0,0,MAXCOL,MAXROW,MAXTAB, PAINT_GRID|PAINT_EXTRAS);
315 0 : pDocShell->PostDataChanged();
316 :
317 : // CellContentChanged comes with the selection
318 :
319 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
320 0 : if (pViewShell)
321 : {
322 0 : SCTAB nTab = pViewShell->GetViewData()->GetTabNo();
323 0 : if ( !aMarkData.GetTableSelect(nTab) )
324 0 : pViewShell->SetTabNo( nSrcTab );
325 :
326 0 : pViewShell->DoneBlockMode(); // causes problems otherwise since selection is on the wrong sheet.
327 : }
328 0 : }
329 :
330 0 : void ScUndoFillTable::Undo()
331 : {
332 0 : BeginUndo();
333 0 : DoChange( sal_True );
334 0 : EndUndo();
335 0 : }
336 :
337 0 : void ScUndoFillTable::Redo()
338 : {
339 0 : BeginRedo();
340 0 : DoChange( false );
341 0 : EndRedo();
342 0 : }
343 :
344 0 : void ScUndoFillTable::Repeat(SfxRepeatTarget& rTarget)
345 : {
346 0 : if (rTarget.ISA(ScTabViewTarget))
347 0 : ((ScTabViewTarget&)rTarget).GetViewShell()->FillTab( nFlags, nFunction, bSkipEmpty, bAsLink );
348 0 : }
349 :
350 0 : bool ScUndoFillTable::CanRepeat(SfxRepeatTarget& rTarget) const
351 : {
352 0 : return rTarget.ISA(ScTabViewTarget);
353 : }
354 :
355 470 : ScUndoSelectionAttr::ScUndoSelectionAttr( ScDocShell* pNewDocShell,
356 : const ScMarkData& rMark,
357 : SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
358 : SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
359 : ScDocument* pNewUndoDoc, sal_Bool bNewMulti,
360 : const ScPatternAttr* pNewApply,
361 : const SvxBoxItem* pNewOuter, const SvxBoxInfoItem* pNewInner )
362 : : ScSimpleUndo( pNewDocShell ),
363 : aMarkData ( rMark ),
364 : aRange ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
365 470 : mpDataArray(new ScEditDataArray),
366 : pUndoDoc ( pNewUndoDoc ),
367 940 : bMulti ( bNewMulti )
368 : {
369 470 : ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
370 470 : pApplyPattern = (ScPatternAttr*) &pPool->Put( *pNewApply );
371 470 : pLineOuter = pNewOuter ? (SvxBoxItem*) &pPool->Put( *pNewOuter ) : NULL;
372 470 : pLineInner = pNewInner ? (SvxBoxInfoItem*) &pPool->Put( *pNewInner ) : NULL;
373 470 : }
374 :
375 1410 : ScUndoSelectionAttr::~ScUndoSelectionAttr()
376 : {
377 470 : ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
378 470 : pPool->Remove(*pApplyPattern);
379 470 : if (pLineOuter)
380 0 : pPool->Remove(*pLineOuter);
381 470 : if (pLineInner)
382 0 : pPool->Remove(*pLineInner);
383 :
384 470 : delete pUndoDoc;
385 940 : }
386 :
387 506 : OUString ScUndoSelectionAttr::GetComment() const
388 : {
389 : //"Attribute" "/Lines"
390 506 : return ScGlobal::GetRscString( pLineOuter ? STR_UNDO_SELATTRLINES : STR_UNDO_SELATTR );
391 : }
392 :
393 0 : ScEditDataArray* ScUndoSelectionAttr::GetDataArray()
394 : {
395 0 : return mpDataArray.get();
396 : }
397 :
398 0 : void ScUndoSelectionAttr::DoChange( const sal_Bool bUndo )
399 : {
400 0 : ScDocument* pDoc = pDocShell->GetDocument();
401 :
402 0 : SetViewMarkData( aMarkData );
403 :
404 0 : ScRange aEffRange( aRange );
405 0 : if ( pDoc->HasAttrib( aEffRange, HASATTR_MERGED ) ) // merged cells?
406 0 : pDoc->ExtendMerge( aEffRange );
407 :
408 0 : sal_uInt16 nExtFlags = 0;
409 0 : pDocShell->UpdatePaintExt( nExtFlags, aEffRange );
410 :
411 0 : ChangeEditData(bUndo);
412 :
413 0 : if (bUndo) // only for Undo
414 : {
415 0 : ScRange aCopyRange = aRange;
416 0 : SCTAB nTabCount = pDoc->GetTableCount();
417 0 : aCopyRange.aStart.SetTab(0);
418 0 : aCopyRange.aEnd.SetTab(nTabCount-1);
419 0 : pUndoDoc->CopyToDocument( aCopyRange, IDF_ATTRIB, bMulti, pDoc, &aMarkData );
420 : }
421 : else // only for Redo
422 : {
423 0 : aMarkData.MarkToMulti();
424 0 : pDoc->ApplySelectionPattern( *pApplyPattern, aMarkData );
425 0 : aMarkData.MarkToSimple();
426 :
427 0 : if (pLineOuter)
428 0 : pDoc->ApplySelectionFrame( aMarkData, pLineOuter, pLineInner );
429 : }
430 :
431 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
432 0 : if ( !( (pViewShell) && pViewShell->AdjustBlockHeight() ) )
433 0 : /*A*/ pDocShell->PostPaint( aEffRange, PAINT_GRID | PAINT_EXTRAS, nExtFlags );
434 :
435 0 : ShowTable( aRange );
436 0 : }
437 :
438 0 : void ScUndoSelectionAttr::ChangeEditData( const bool bUndo )
439 : {
440 0 : ScDocument* pDoc = pDocShell->GetDocument();
441 0 : for (const ScEditDataArray::Item* pItem = mpDataArray->First(); pItem; pItem = mpDataArray->Next())
442 : {
443 0 : ScAddress aPos(pItem->GetCol(), pItem->GetRow(), pItem->GetTab());
444 0 : if (pDoc->GetCellType(aPos) != CELLTYPE_EDIT)
445 0 : continue;
446 :
447 0 : if (bUndo)
448 : {
449 0 : if (pItem->GetOldData())
450 0 : pDoc->SetEditText(aPos, *pItem->GetOldData(), NULL);
451 : else
452 0 : pDoc->SetEmptyCell(aPos);
453 : }
454 : else
455 : {
456 0 : if (pItem->GetNewData())
457 0 : pDoc->SetEditText(aPos, *pItem->GetNewData(), NULL);
458 : else
459 0 : pDoc->SetEmptyCell(aPos);
460 : }
461 : }
462 0 : }
463 :
464 0 : void ScUndoSelectionAttr::Undo()
465 : {
466 0 : BeginUndo();
467 0 : DoChange( sal_True );
468 0 : EndUndo();
469 0 : }
470 :
471 0 : void ScUndoSelectionAttr::Redo()
472 : {
473 0 : BeginRedo();
474 0 : DoChange( false );
475 0 : EndRedo();
476 0 : }
477 :
478 0 : void ScUndoSelectionAttr::Repeat(SfxRepeatTarget& rTarget)
479 : {
480 0 : if (rTarget.ISA(ScTabViewTarget))
481 : {
482 0 : ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
483 0 : if (pLineOuter)
484 0 : rViewShell.ApplyPatternLines( *pApplyPattern, pLineOuter, pLineInner, sal_True );
485 : else
486 0 : rViewShell.ApplySelectionPattern( *pApplyPattern, sal_True );
487 : }
488 0 : }
489 :
490 18 : bool ScUndoSelectionAttr::CanRepeat(SfxRepeatTarget& rTarget) const
491 : {
492 18 : return rTarget.ISA(ScTabViewTarget);
493 : }
494 :
495 15 : ScUndoAutoFill::ScUndoAutoFill( ScDocShell* pNewDocShell,
496 : const ScRange& rRange, const ScRange& rSourceArea,
497 : ScDocument* pNewUndoDoc, const ScMarkData& rMark,
498 : FillDir eNewFillDir, FillCmd eNewFillCmd, FillDateCmd eNewFillDateCmd,
499 : double fNewStartValue, double fNewStepValue, double fNewMaxValue )
500 : : ScBlockUndo( pNewDocShell, rRange, SC_UNDO_AUTOHEIGHT ),
501 : aSource ( rSourceArea ),
502 : aMarkData ( rMark ),
503 : pUndoDoc ( pNewUndoDoc ),
504 : eFillDir ( eNewFillDir ),
505 : eFillCmd ( eNewFillCmd ),
506 : eFillDateCmd ( eNewFillDateCmd ),
507 : fStartValue ( fNewStartValue ),
508 : fStepValue ( fNewStepValue ),
509 15 : fMaxValue ( fNewMaxValue )
510 : {
511 15 : SetChangeTrack();
512 15 : }
513 :
514 45 : ScUndoAutoFill::~ScUndoAutoFill()
515 : {
516 15 : delete pUndoDoc;
517 30 : }
518 :
519 15 : OUString ScUndoAutoFill::GetComment() const
520 : {
521 15 : return ScGlobal::GetRscString( STR_UNDO_AUTOFILL ); //"Fill"
522 : }
523 :
524 15 : void ScUndoAutoFill::SetChangeTrack()
525 : {
526 15 : ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
527 15 : if ( pChangeTrack )
528 : pChangeTrack->AppendContentRange( aBlockRange, pUndoDoc,
529 0 : nStartChangeAction, nEndChangeAction );
530 : else
531 15 : nStartChangeAction = nEndChangeAction = 0;
532 15 : }
533 :
534 0 : void ScUndoAutoFill::Undo()
535 : {
536 0 : BeginUndo();
537 :
538 0 : ScDocument* pDoc = pDocShell->GetDocument();
539 :
540 0 : SCTAB nTabCount = pDoc->GetTableCount();
541 0 : ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
542 0 : for (; itr != itrEnd && *itr < nTabCount; ++itr)
543 : {
544 0 : ScRange aWorkRange = aBlockRange;
545 0 : aWorkRange.aStart.SetTab(*itr);
546 0 : aWorkRange.aEnd.SetTab(*itr);
547 :
548 0 : sal_uInt16 nExtFlags = 0;
549 0 : pDocShell->UpdatePaintExt( nExtFlags, aWorkRange );
550 0 : pDoc->DeleteAreaTab( aWorkRange, IDF_AUTOFILL );
551 0 : pUndoDoc->CopyToDocument( aWorkRange, IDF_AUTOFILL, false, pDoc );
552 :
553 0 : pDoc->ExtendMerge( aWorkRange, sal_True );
554 0 : pDocShell->PostPaint( aWorkRange, PAINT_GRID, nExtFlags );
555 : }
556 0 : pDocShell->PostDataChanged();
557 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
558 0 : if (pViewShell)
559 0 : pViewShell->CellContentChanged();
560 :
561 0 : ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
562 0 : if ( pChangeTrack )
563 0 : pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
564 :
565 0 : EndUndo();
566 0 : }
567 :
568 0 : void ScUndoAutoFill::Redo()
569 : {
570 0 : BeginRedo();
571 :
572 : //! Select sheet
573 :
574 0 : SCCOLROW nCount = 0;
575 0 : switch (eFillDir)
576 : {
577 : case FILL_TO_BOTTOM:
578 0 : nCount = aBlockRange.aEnd.Row() - aSource.aEnd.Row();
579 0 : break;
580 : case FILL_TO_RIGHT:
581 0 : nCount = aBlockRange.aEnd.Col() - aSource.aEnd.Col();
582 0 : break;
583 : case FILL_TO_TOP:
584 0 : nCount = aSource.aStart.Row() - aBlockRange.aStart.Row();
585 0 : break;
586 : case FILL_TO_LEFT:
587 0 : nCount = aSource.aStart.Col() - aBlockRange.aStart.Col();
588 0 : break;
589 : }
590 :
591 0 : ScDocument* pDoc = pDocShell->GetDocument();
592 0 : if ( fStartValue != MAXDOUBLE )
593 : {
594 0 : SCCOL nValX = (eFillDir == FILL_TO_LEFT) ? aSource.aEnd.Col() : aSource.aStart.Col();
595 0 : SCROW nValY = (eFillDir == FILL_TO_TOP ) ? aSource.aEnd.Row() : aSource.aStart.Row();
596 0 : SCTAB nTab = aSource.aStart.Tab();
597 0 : pDoc->SetValue( nValX, nValY, nTab, fStartValue );
598 : }
599 : sal_uLong nProgCount;
600 0 : if (eFillDir == FILL_TO_BOTTOM || eFillDir == FILL_TO_TOP)
601 0 : nProgCount = aSource.aEnd.Col() - aSource.aStart.Col() + 1;
602 : else
603 0 : nProgCount = aSource.aEnd.Row() - aSource.aStart.Row() + 1;
604 0 : nProgCount *= nCount;
605 : ScProgress aProgress( pDoc->GetDocumentShell(),
606 0 : ScGlobal::GetRscString(STR_FILL_SERIES_PROGRESS), nProgCount );
607 :
608 0 : pDoc->Fill( aSource.aStart.Col(), aSource.aStart.Row(),
609 0 : aSource.aEnd.Col(), aSource.aEnd.Row(), &aProgress,
610 : aMarkData, nCount,
611 : eFillDir, eFillCmd, eFillDateCmd,
612 0 : fStepValue, fMaxValue );
613 :
614 0 : SetChangeTrack();
615 :
616 0 : pDocShell->PostPaint( aBlockRange, PAINT_GRID );
617 0 : pDocShell->PostDataChanged();
618 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
619 0 : if (pViewShell)
620 0 : pViewShell->CellContentChanged();
621 :
622 0 : EndRedo();
623 0 : }
624 :
625 0 : void ScUndoAutoFill::Repeat(SfxRepeatTarget& rTarget)
626 : {
627 0 : if (rTarget.ISA(ScTabViewTarget))
628 : {
629 0 : ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
630 0 : if (eFillCmd==FILL_SIMPLE)
631 0 : rViewShell.FillSimple( eFillDir, sal_True );
632 : else
633 : rViewShell.FillSeries( eFillDir, eFillCmd, eFillDateCmd,
634 0 : fStartValue, fStepValue, fMaxValue, sal_True );
635 : }
636 0 : }
637 :
638 0 : bool ScUndoAutoFill::CanRepeat(SfxRepeatTarget& rTarget) const
639 : {
640 0 : return rTarget.ISA(ScTabViewTarget);
641 : }
642 :
643 4 : ScUndoMerge::ScUndoMerge( ScDocShell* pNewDocShell, const ScCellMergeOption& rOption,
644 : bool bMergeContents, ScDocument* pUndoDoc, SdrUndoAction* pDrawUndo )
645 : : ScSimpleUndo( pNewDocShell ),
646 : maOption(rOption),
647 : mbMergeContents( bMergeContents ),
648 : mpUndoDoc( pUndoDoc ),
649 4 : mpDrawUndo( pDrawUndo )
650 : {
651 4 : }
652 :
653 9 : ScUndoMerge::~ScUndoMerge()
654 : {
655 3 : delete mpUndoDoc;
656 3 : DeleteSdrUndoAction( mpDrawUndo );
657 6 : }
658 :
659 4 : OUString ScUndoMerge::GetComment() const
660 : {
661 4 : return ScGlobal::GetRscString( STR_UNDO_MERGE );
662 : }
663 :
664 0 : void ScUndoMerge::DoChange( bool bUndo ) const
665 : {
666 : using ::std::set;
667 :
668 0 : if (maOption.maTabs.empty())
669 : // Nothing to do.
670 0 : return;
671 :
672 0 : ScDocument* pDoc = pDocShell->GetDocument();
673 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
674 :
675 0 : ScRange aCurRange = maOption.getSingleRange(pDocShell->GetCurTab());
676 0 : ScUndoUtil::MarkSimpleBlock(pDocShell, aCurRange);
677 :
678 0 : for (set<SCTAB>::const_iterator itr = maOption.maTabs.begin(), itrEnd = maOption.maTabs.end();
679 : itr != itrEnd; ++itr)
680 : {
681 0 : SCTAB nTab = *itr;
682 0 : ScRange aRange = maOption.getSingleRange(nTab);
683 :
684 0 : if (bUndo)
685 : // remove merge (contents are copied back below from undo document)
686 0 : pDoc->RemoveMerge( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aStart.Tab() );
687 : else
688 : {
689 : // repeat merge, but do not remove note captions (will be done by drawing redo below)
690 0 : pDoc->DoMerge( aRange.aStart.Tab(),
691 0 : aRange.aStart.Col(), aRange.aStart.Row(),
692 0 : aRange.aEnd.Col(), aRange.aEnd.Row(), false );
693 :
694 0 : if (maOption.mbCenter)
695 : {
696 0 : pDoc->ApplyAttr( aRange.aStart.Col(), aRange.aStart.Row(),
697 0 : aRange.aStart.Tab(),
698 0 : SvxHorJustifyItem( SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY ) );
699 0 : pDoc->ApplyAttr( aRange.aStart.Col(), aRange.aStart.Row(),
700 0 : aRange.aStart.Tab(),
701 0 : SvxVerJustifyItem( SVX_VER_JUSTIFY_CENTER, ATTR_VER_JUSTIFY ) );
702 : }
703 : }
704 :
705 : // undo -> copy back deleted contents
706 0 : if (bUndo && mpUndoDoc)
707 : {
708 0 : pDoc->DeleteAreaTab( aRange, IDF_CONTENTS|IDF_NOCAPTIONS );
709 0 : mpUndoDoc->CopyToDocument( aRange, IDF_ALL|IDF_NOCAPTIONS, false, pDoc );
710 : }
711 :
712 : // redo -> merge contents again
713 0 : else if (!bUndo && mbMergeContents)
714 : {
715 0 : pDoc->DoMergeContents( aRange.aStart.Tab(),
716 0 : aRange.aStart.Col(), aRange.aStart.Row(),
717 0 : aRange.aEnd.Col(), aRange.aEnd.Row() );
718 : }
719 :
720 0 : if (bUndo)
721 0 : DoSdrUndoAction( mpDrawUndo, pDoc );
722 : else
723 0 : RedoSdrUndoAction( mpDrawUndo );
724 :
725 0 : bool bDidPaint = false;
726 0 : if ( pViewShell )
727 : {
728 0 : pViewShell->SetTabNo(nTab);
729 0 : bDidPaint = pViewShell->AdjustRowHeight(maOption.mnStartRow, maOption.mnEndRow);
730 : }
731 :
732 0 : if (!bDidPaint)
733 0 : ScUndoUtil::PaintMore(pDocShell, aRange);
734 : }
735 :
736 0 : ShowTable(aCurRange);
737 : }
738 :
739 0 : void ScUndoMerge::Undo()
740 : {
741 0 : BeginUndo();
742 0 : DoChange( true );
743 0 : EndUndo();
744 0 : }
745 :
746 0 : void ScUndoMerge::Redo()
747 : {
748 0 : BeginRedo();
749 0 : DoChange( false );
750 0 : EndRedo();
751 0 : }
752 :
753 0 : void ScUndoMerge::Repeat(SfxRepeatTarget& rTarget)
754 : {
755 0 : if (rTarget.ISA(ScTabViewTarget))
756 : {
757 0 : ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
758 0 : sal_Bool bCont = false;
759 0 : rViewShell.MergeCells( false, bCont, sal_True );
760 : }
761 0 : }
762 :
763 0 : bool ScUndoMerge::CanRepeat(SfxRepeatTarget& rTarget) const
764 : {
765 0 : return rTarget.ISA(ScTabViewTarget);
766 : }
767 :
768 0 : ScUndoAutoFormat::ScUndoAutoFormat( ScDocShell* pNewDocShell,
769 : const ScRange& rRange, ScDocument* pNewUndoDoc,
770 : const ScMarkData& rMark, sal_Bool bNewSize, sal_uInt16 nNewFormatNo )
771 : : ScBlockUndo( pNewDocShell, rRange, bNewSize ? SC_UNDO_MANUALHEIGHT : SC_UNDO_AUTOHEIGHT ),
772 : pUndoDoc ( pNewUndoDoc ),
773 : aMarkData ( rMark ),
774 : bSize ( bNewSize ),
775 0 : nFormatNo ( nNewFormatNo )
776 : {
777 0 : }
778 :
779 0 : ScUndoAutoFormat::~ScUndoAutoFormat()
780 : {
781 0 : delete pUndoDoc;
782 0 : }
783 :
784 0 : OUString ScUndoAutoFormat::GetComment() const
785 : {
786 0 : return ScGlobal::GetRscString( STR_UNDO_AUTOFORMAT ); //"Auto-Format"
787 : }
788 :
789 0 : void ScUndoAutoFormat::Undo()
790 : {
791 0 : BeginUndo();
792 :
793 0 : ScDocument* pDoc = pDocShell->GetDocument();
794 :
795 0 : SCTAB nTabCount = pDoc->GetTableCount();
796 0 : pDoc->DeleteArea( aBlockRange.aStart.Col(), aBlockRange.aStart.Row(),
797 0 : aBlockRange.aEnd.Col(), aBlockRange.aEnd.Row(),
798 0 : aMarkData, IDF_ATTRIB );
799 0 : ScRange aCopyRange = aBlockRange;
800 0 : aCopyRange.aStart.SetTab(0);
801 0 : aCopyRange.aEnd.SetTab(nTabCount-1);
802 0 : pUndoDoc->CopyToDocument( aCopyRange, IDF_ATTRIB, false, pDoc, &aMarkData );
803 :
804 : // cell heights and widths (IDF_NONE)
805 0 : if (bSize)
806 : {
807 0 : SCCOL nStartX = aBlockRange.aStart.Col();
808 0 : SCROW nStartY = aBlockRange.aStart.Row();
809 0 : SCTAB nStartZ = aBlockRange.aStart.Tab();
810 0 : SCCOL nEndX = aBlockRange.aEnd.Col();
811 0 : SCROW nEndY = aBlockRange.aEnd.Row();
812 0 : SCTAB nEndZ = aBlockRange.aEnd.Tab();
813 :
814 : pUndoDoc->CopyToDocument( nStartX, 0, 0, nEndX, MAXROW, nTabCount-1,
815 0 : IDF_NONE, false, pDoc, &aMarkData );
816 : pUndoDoc->CopyToDocument( 0, nStartY, 0, MAXCOL, nEndY, nTabCount-1,
817 0 : IDF_NONE, false, pDoc, &aMarkData );
818 : pDocShell->PostPaint( 0, 0, nStartZ, MAXCOL, MAXROW, nEndZ,
819 0 : PAINT_GRID | PAINT_LEFT | PAINT_TOP, SC_PF_LINES );
820 : }
821 : else
822 0 : pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES );
823 :
824 0 : EndUndo();
825 0 : }
826 :
827 0 : void ScUndoAutoFormat::Redo()
828 : {
829 0 : BeginRedo();
830 :
831 0 : ScDocument* pDoc = pDocShell->GetDocument();
832 :
833 0 : SCCOL nStartX = aBlockRange.aStart.Col();
834 0 : SCROW nStartY = aBlockRange.aStart.Row();
835 0 : SCTAB nStartZ = aBlockRange.aStart.Tab();
836 0 : SCCOL nEndX = aBlockRange.aEnd.Col();
837 0 : SCROW nEndY = aBlockRange.aEnd.Row();
838 0 : SCTAB nEndZ = aBlockRange.aEnd.Tab();
839 :
840 0 : pDoc->AutoFormat( nStartX, nStartY, nEndX, nEndY, nFormatNo, aMarkData );
841 :
842 0 : if (bSize)
843 : {
844 0 : VirtualDevice aVirtDev;
845 0 : Fraction aZoomX(1,1);
846 0 : Fraction aZoomY = aZoomX;
847 : double nPPTX,nPPTY;
848 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
849 0 : if (pViewShell)
850 : {
851 0 : ScViewData* pData = pViewShell->GetViewData();
852 0 : nPPTX = pData->GetPPTX();
853 0 : nPPTY = pData->GetPPTY();
854 0 : aZoomX = pData->GetZoomX();
855 0 : aZoomY = pData->GetZoomY();
856 : }
857 : else
858 : {
859 : // Keep zoom at 100
860 0 : nPPTX = ScGlobal::nScreenPPTX;
861 0 : nPPTY = ScGlobal::nScreenPPTY;
862 : }
863 :
864 0 : sal_Bool bFormula = false; // remember
865 :
866 0 : for (SCTAB nTab=nStartZ; nTab<=nEndZ; nTab++)
867 : {
868 0 : ScMarkData aDestMark;
869 0 : aDestMark.SelectOneTable( nTab );
870 0 : aDestMark.SetMarkArea( ScRange( nStartX, nStartY, nTab, nEndX, nEndY, nTab ) );
871 0 : aDestMark.MarkToMulti();
872 :
873 : // as SC_SIZE_VISOPT
874 0 : for (SCROW nRow=nStartY; nRow<=nEndY; nRow++)
875 : {
876 0 : sal_uInt8 nOld = pDoc->GetRowFlags(nRow,nTab);
877 0 : bool bHidden = pDoc->RowHidden(nRow, nTab);
878 0 : if ( !bHidden && ( nOld & CR_MANUALSIZE ) )
879 0 : pDoc->SetRowFlags( nRow, nTab, nOld & ~CR_MANUALSIZE );
880 : }
881 : pDoc->SetOptimalHeight( nStartY, nEndY, nTab, 0, &aVirtDev,
882 0 : nPPTX, nPPTY, aZoomX, aZoomY, false );
883 :
884 0 : for (SCCOL nCol=nStartX; nCol<=nEndX; nCol++)
885 0 : if (!pDoc->ColHidden(nCol, nTab))
886 : {
887 : sal_uInt16 nThisSize = STD_EXTRA_WIDTH + pDoc->GetOptimalColWidth( nCol, nTab,
888 : &aVirtDev, nPPTX, nPPTY, aZoomX, aZoomY, bFormula,
889 0 : &aDestMark );
890 0 : pDoc->SetColWidth( nCol, nTab, nThisSize );
891 0 : pDoc->ShowCol( nCol, nTab, sal_True );
892 : }
893 0 : }
894 :
895 : pDocShell->PostPaint( 0, 0, nStartZ,
896 : MAXCOL, MAXROW, nEndZ,
897 0 : PAINT_GRID | PAINT_LEFT | PAINT_TOP, SC_PF_LINES);
898 : }
899 : else
900 0 : pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES );
901 :
902 0 : EndRedo();
903 0 : }
904 :
905 0 : void ScUndoAutoFormat::Repeat(SfxRepeatTarget& rTarget)
906 : {
907 0 : if (rTarget.ISA(ScTabViewTarget))
908 0 : ((ScTabViewTarget&)rTarget).GetViewShell()->AutoFormat( nFormatNo, sal_True );
909 0 : }
910 :
911 0 : bool ScUndoAutoFormat::CanRepeat(SfxRepeatTarget& rTarget) const
912 : {
913 0 : return rTarget.ISA(ScTabViewTarget);
914 : }
915 :
916 22 : ScUndoReplace::ScUndoReplace( ScDocShell* pNewDocShell, const ScMarkData& rMark,
917 : SCCOL nCurX, SCROW nCurY, SCTAB nCurZ,
918 : const String& rNewUndoStr, ScDocument* pNewUndoDoc,
919 : const SvxSearchItem* pItem )
920 : : ScSimpleUndo( pNewDocShell ),
921 : aCursorPos ( nCurX, nCurY, nCurZ ),
922 : aMarkData ( rMark ),
923 : aUndoStr ( rNewUndoStr ),
924 22 : pUndoDoc ( pNewUndoDoc )
925 : {
926 22 : pSearchItem = new SvxSearchItem( *pItem );
927 22 : SetChangeTrack();
928 22 : }
929 :
930 60 : ScUndoReplace::~ScUndoReplace()
931 : {
932 20 : delete pUndoDoc;
933 20 : delete pSearchItem;
934 40 : }
935 :
936 22 : void ScUndoReplace::SetChangeTrack()
937 : {
938 22 : ScDocument* pDoc = pDocShell->GetDocument();
939 22 : ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
940 22 : if ( pChangeTrack )
941 : {
942 0 : if ( pUndoDoc )
943 : { //! UndoDoc includes only the changed cells,
944 : // that is why an Iterator can be used
945 : pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc,
946 0 : nStartChangeAction, nEndChangeAction );
947 : }
948 : else
949 : {
950 0 : nStartChangeAction = pChangeTrack->GetActionMax() + 1;
951 : ScChangeActionContent* pContent = new ScChangeActionContent(
952 0 : ScRange( aCursorPos) );
953 0 : ScCellValue aCell;
954 0 : aCell.assign(*pDoc, aCursorPos);
955 0 : pContent->SetOldValue( aUndoStr, pDoc );
956 0 : pContent->SetNewValue(aCell, pDoc);
957 0 : pChangeTrack->Append( pContent );
958 0 : nEndChangeAction = pChangeTrack->GetActionMax();
959 : }
960 : }
961 : else
962 22 : nStartChangeAction = nEndChangeAction = 0;
963 22 : }
964 :
965 22 : OUString ScUndoReplace::GetComment() const
966 : {
967 22 : return ScGlobal::GetRscString( STR_UNDO_REPLACE ); // "Replace"
968 : }
969 :
970 0 : void ScUndoReplace::Undo()
971 : {
972 0 : BeginUndo();
973 :
974 0 : ScDocument* pDoc = pDocShell->GetDocument();
975 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
976 :
977 0 : ShowTable( aCursorPos.Tab() );
978 :
979 0 : if (pUndoDoc) // only for ReplaceAll !!
980 : {
981 : OSL_ENSURE(pSearchItem->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL,
982 : "ScUndoReplace:: Wrong Mode");
983 :
984 0 : SetViewMarkData( aMarkData );
985 :
986 : //! selected sheet
987 : //! select range ?
988 :
989 : // Undo document has no row/column information, thus copy with
990 : // bColRowFlags = FALSE to not destroy Outline groups
991 :
992 0 : sal_uInt16 nUndoFlags = (pSearchItem->GetPattern()) ? IDF_ATTRIB : IDF_CONTENTS;
993 : pUndoDoc->CopyToDocument( 0, 0, 0,
994 : MAXCOL, MAXROW, MAXTAB,
995 0 : nUndoFlags, false, pDoc, NULL, false ); // without row flags
996 0 : pDocShell->PostPaintGridAll();
997 : }
998 0 : else if (pSearchItem->GetPattern() &&
999 0 : pSearchItem->GetCommand() == SVX_SEARCHCMD_REPLACE)
1000 : {
1001 0 : String aTempStr = pSearchItem->GetSearchString(); // toggle
1002 0 : pSearchItem->SetSearchString(pSearchItem->GetReplaceString());
1003 0 : pSearchItem->SetReplaceString(aTempStr);
1004 : pDoc->ReplaceStyle( *pSearchItem,
1005 0 : aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(),
1006 0 : aMarkData, sal_True);
1007 0 : pSearchItem->SetReplaceString(pSearchItem->GetSearchString());
1008 0 : pSearchItem->SetSearchString(aTempStr);
1009 0 : if (pViewShell)
1010 0 : pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1011 0 : SC_FOLLOW_JUMP, false, false );
1012 0 : pDocShell->PostPaintGridAll();
1013 : }
1014 0 : else if (pSearchItem->GetCellType() == SVX_SEARCHIN_NOTE)
1015 : {
1016 0 : ScPostIt* pNote = pDoc->GetNotes( aCursorPos.Tab() )->findByAddress( aCursorPos );
1017 : OSL_ENSURE( pNote, "ScUndoReplace::Undo - cell does not contain a note" );
1018 0 : if (pNote)
1019 0 : pNote->SetText( aCursorPos, aUndoStr );
1020 0 : if (pViewShell)
1021 0 : pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1022 0 : SC_FOLLOW_JUMP, false, false );
1023 : }
1024 : else
1025 : {
1026 : // aUndoStr may contain line breaks
1027 0 : if ( aUndoStr.Search('\n') != STRING_NOTFOUND )
1028 : {
1029 0 : ScFieldEditEngine& rEngine = pDoc->GetEditEngine();
1030 0 : rEngine.SetText(aUndoStr);
1031 0 : pDoc->SetEditText(aCursorPos, rEngine.CreateTextObject());
1032 : }
1033 : else
1034 0 : pDoc->SetString( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aUndoStr );
1035 0 : if (pViewShell)
1036 0 : pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1037 0 : SC_FOLLOW_JUMP, false, false );
1038 0 : pDocShell->PostPaintGridAll();
1039 : }
1040 :
1041 0 : ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
1042 0 : if ( pChangeTrack )
1043 0 : pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
1044 :
1045 0 : EndUndo();
1046 0 : }
1047 :
1048 0 : void ScUndoReplace::Redo()
1049 : {
1050 0 : BeginRedo();
1051 :
1052 0 : ScDocument* pDoc = pDocShell->GetDocument();
1053 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1054 :
1055 0 : if (pViewShell)
1056 0 : pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1057 0 : SC_FOLLOW_JUMP, false, false );
1058 0 : if (pUndoDoc)
1059 : {
1060 0 : if (pViewShell)
1061 : {
1062 0 : SetViewMarkData( aMarkData );
1063 :
1064 0 : pViewShell->SearchAndReplace( pSearchItem, false, sal_True );
1065 : }
1066 : }
1067 0 : else if (pSearchItem->GetPattern() &&
1068 0 : pSearchItem->GetCommand() == SVX_SEARCHCMD_REPLACE)
1069 : {
1070 : pDoc->ReplaceStyle( *pSearchItem,
1071 0 : aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(),
1072 0 : aMarkData, sal_True);
1073 0 : pDocShell->PostPaintGridAll();
1074 : }
1075 : else
1076 0 : if (pViewShell)
1077 0 : pViewShell->SearchAndReplace( pSearchItem, false, sal_True );
1078 :
1079 0 : SetChangeTrack();
1080 :
1081 0 : EndRedo();
1082 0 : }
1083 :
1084 0 : void ScUndoReplace::Repeat(SfxRepeatTarget& rTarget)
1085 : {
1086 0 : if (rTarget.ISA(ScTabViewTarget))
1087 0 : ((ScTabViewTarget&)rTarget).GetViewShell()->SearchAndReplace( pSearchItem, sal_True, false );
1088 0 : }
1089 :
1090 0 : bool ScUndoReplace::CanRepeat(SfxRepeatTarget& rTarget) const
1091 : {
1092 0 : return rTarget.ISA(ScTabViewTarget);
1093 : }
1094 :
1095 : // multi-operation (only simple blocks)
1096 3 : ScUndoTabOp::ScUndoTabOp( ScDocShell* pNewDocShell,
1097 : SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
1098 : SCCOL nEndX, SCROW nEndY, SCTAB nEndZ, ScDocument* pNewUndoDoc,
1099 : const ScRefAddress& rFormulaCell,
1100 : const ScRefAddress& rFormulaEnd,
1101 : const ScRefAddress& rRowCell,
1102 : const ScRefAddress& rColCell,
1103 : sal_uInt8 nMd )
1104 : : ScSimpleUndo( pNewDocShell ),
1105 : aRange ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
1106 : pUndoDoc ( pNewUndoDoc ),
1107 : theFormulaCell ( rFormulaCell ),
1108 : theFormulaEnd ( rFormulaEnd ),
1109 : theRowCell ( rRowCell ),
1110 : theColCell ( rColCell ),
1111 3 : nMode ( nMd )
1112 : {
1113 3 : }
1114 :
1115 9 : ScUndoTabOp::~ScUndoTabOp()
1116 : {
1117 3 : delete pUndoDoc;
1118 6 : }
1119 :
1120 3 : OUString ScUndoTabOp::GetComment() const
1121 : {
1122 3 : return ScGlobal::GetRscString( STR_UNDO_TABOP ); // "Multiple operation"
1123 : }
1124 :
1125 0 : void ScUndoTabOp::Undo()
1126 : {
1127 0 : BeginUndo();
1128 :
1129 0 : ScUndoUtil::MarkSimpleBlock( pDocShell, aRange );
1130 :
1131 0 : sal_uInt16 nExtFlags = 0;
1132 0 : pDocShell->UpdatePaintExt( nExtFlags, aRange );
1133 :
1134 0 : ScDocument* pDoc = pDocShell->GetDocument();
1135 0 : pDoc->DeleteAreaTab( aRange,IDF_ALL & ~IDF_NOTE );
1136 0 : pUndoDoc->CopyToDocument( aRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
1137 0 : pDocShell->PostPaint( aRange, PAINT_GRID, nExtFlags );
1138 0 : pDocShell->PostDataChanged();
1139 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1140 0 : if (pViewShell)
1141 0 : pViewShell->CellContentChanged();
1142 :
1143 0 : EndUndo();
1144 0 : }
1145 :
1146 0 : void ScUndoTabOp::Redo()
1147 : {
1148 0 : BeginRedo();
1149 :
1150 0 : ScUndoUtil::MarkSimpleBlock( pDocShell, aRange );
1151 :
1152 : ScTabOpParam aParam( theFormulaCell, theFormulaEnd,
1153 : theRowCell, theColCell,
1154 0 : nMode );
1155 :
1156 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1157 0 : if (pViewShell)
1158 0 : pViewShell->TabOp( aParam, false);
1159 :
1160 0 : EndRedo();
1161 0 : }
1162 :
1163 0 : void ScUndoTabOp::Repeat(SfxRepeatTarget& /* rTarget */)
1164 : {
1165 0 : }
1166 :
1167 0 : bool ScUndoTabOp::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1168 : {
1169 0 : return false;
1170 : }
1171 :
1172 0 : ScUndoConversion::ScUndoConversion(
1173 : ScDocShell* pNewDocShell, const ScMarkData& rMark,
1174 : SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, ScDocument* pNewUndoDoc,
1175 : SCCOL nNewX, SCROW nNewY, SCTAB nNewZ, ScDocument* pNewRedoDoc,
1176 : const ScConversionParam& rConvParam ) :
1177 : ScSimpleUndo( pNewDocShell ),
1178 : aMarkData( rMark ),
1179 : aCursorPos( nCurX, nCurY, nCurZ ),
1180 : pUndoDoc( pNewUndoDoc ),
1181 : aNewCursorPos( nNewX, nNewY, nNewZ ),
1182 : pRedoDoc( pNewRedoDoc ),
1183 0 : maConvParam( rConvParam )
1184 : {
1185 0 : SetChangeTrack();
1186 0 : }
1187 :
1188 0 : ScUndoConversion::~ScUndoConversion()
1189 : {
1190 0 : delete pUndoDoc;
1191 0 : delete pRedoDoc;
1192 0 : }
1193 :
1194 0 : void ScUndoConversion::SetChangeTrack()
1195 : {
1196 0 : ScDocument* pDoc = pDocShell->GetDocument();
1197 0 : ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
1198 0 : if ( pChangeTrack )
1199 : {
1200 0 : if ( pUndoDoc )
1201 : pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc,
1202 0 : nStartChangeAction, nEndChangeAction );
1203 : else
1204 : {
1205 : OSL_FAIL( "ScUndoConversion::SetChangeTrack: no UndoDoc" );
1206 0 : nStartChangeAction = nEndChangeAction = 0;
1207 : }
1208 : }
1209 : else
1210 0 : nStartChangeAction = nEndChangeAction = 0;
1211 0 : }
1212 :
1213 0 : OUString ScUndoConversion::GetComment() const
1214 : {
1215 0 : OUString aText;
1216 0 : switch( maConvParam.GetType() )
1217 : {
1218 0 : case SC_CONVERSION_SPELLCHECK: aText = ScGlobal::GetRscString( STR_UNDO_SPELLING ); break;
1219 0 : case SC_CONVERSION_HANGULHANJA: aText = ScGlobal::GetRscString( STR_UNDO_HANGULHANJA ); break;
1220 0 : case SC_CONVERSION_CHINESE_TRANSL: aText = ScGlobal::GetRscString( STR_UNDO_CHINESE_TRANSLATION ); break;
1221 : default: OSL_FAIL( "ScUndoConversion::GetComment - unknown conversion type" );
1222 : }
1223 0 : return aText;
1224 : }
1225 :
1226 0 : void ScUndoConversion::DoChange( ScDocument* pRefDoc, const ScAddress& rCursorPos )
1227 : {
1228 0 : if (pRefDoc)
1229 : {
1230 0 : ScDocument* pDoc = pDocShell->GetDocument();
1231 0 : ShowTable( rCursorPos.Tab() );
1232 :
1233 0 : SetViewMarkData( aMarkData );
1234 :
1235 0 : SCTAB nTabCount = pDoc->GetTableCount();
1236 : // Undo/Redo-doc has only selected tables
1237 :
1238 0 : sal_Bool bMulti = aMarkData.IsMultiMarked();
1239 : pRefDoc->CopyToDocument( 0, 0, 0,
1240 : MAXCOL, MAXROW, nTabCount-1,
1241 0 : IDF_CONTENTS, bMulti, pDoc, &aMarkData );
1242 0 : pDocShell->PostPaintGridAll();
1243 : }
1244 : else
1245 : {
1246 : OSL_FAIL("no Un-/RedoDoc for Un-/RedoSpelling");
1247 : }
1248 0 : }
1249 :
1250 0 : void ScUndoConversion::Undo()
1251 : {
1252 0 : BeginUndo();
1253 0 : DoChange( pUndoDoc, aCursorPos );
1254 0 : ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
1255 0 : if ( pChangeTrack )
1256 0 : pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
1257 0 : EndUndo();
1258 0 : }
1259 :
1260 0 : void ScUndoConversion::Redo()
1261 : {
1262 0 : BeginRedo();
1263 0 : DoChange( pRedoDoc, aNewCursorPos );
1264 0 : SetChangeTrack();
1265 0 : EndRedo();
1266 0 : }
1267 :
1268 0 : void ScUndoConversion::Repeat( SfxRepeatTarget& rTarget )
1269 : {
1270 0 : if( rTarget.ISA( ScTabViewTarget ) )
1271 0 : ((ScTabViewTarget&)rTarget).GetViewShell()->DoSheetConversion( maConvParam, sal_True );
1272 0 : }
1273 :
1274 0 : bool ScUndoConversion::CanRepeat(SfxRepeatTarget& rTarget) const
1275 : {
1276 0 : return rTarget.ISA( ScTabViewTarget );
1277 : }
1278 :
1279 0 : ScUndoRefConversion::ScUndoRefConversion( ScDocShell* pNewDocShell,
1280 : const ScRange& aMarkRange, const ScMarkData& rMark,
1281 : ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc, sal_Bool bNewMulti, sal_uInt16 nNewFlag) :
1282 : ScSimpleUndo( pNewDocShell ),
1283 : aMarkData ( rMark ),
1284 : pUndoDoc ( pNewUndoDoc ),
1285 : pRedoDoc ( pNewRedoDoc ),
1286 : aRange ( aMarkRange ),
1287 : bMulti ( bNewMulti ),
1288 0 : nFlags ( nNewFlag )
1289 : {
1290 0 : SetChangeTrack();
1291 0 : }
1292 :
1293 0 : ScUndoRefConversion::~ScUndoRefConversion()
1294 : {
1295 0 : delete pUndoDoc;
1296 0 : delete pRedoDoc;
1297 0 : }
1298 :
1299 0 : OUString ScUndoRefConversion::GetComment() const
1300 : {
1301 0 : return ScGlobal::GetRscString( STR_UNDO_ENTERDATA ); // "Input"
1302 : }
1303 :
1304 0 : void ScUndoRefConversion::SetChangeTrack()
1305 : {
1306 0 : ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
1307 0 : if ( pChangeTrack && (nFlags & IDF_FORMULA) )
1308 : pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc,
1309 0 : nStartChangeAction, nEndChangeAction );
1310 : else
1311 0 : nStartChangeAction = nEndChangeAction = 0;
1312 0 : }
1313 :
1314 0 : void ScUndoRefConversion::DoChange( ScDocument* pRefDoc)
1315 : {
1316 0 : ScDocument* pDoc = pDocShell->GetDocument();
1317 :
1318 0 : ShowTable(aRange);
1319 :
1320 0 : SetViewMarkData( aMarkData );
1321 :
1322 0 : ScRange aCopyRange = aRange;
1323 0 : SCTAB nTabCount = pDoc->GetTableCount();
1324 0 : aCopyRange.aStart.SetTab(0);
1325 0 : aCopyRange.aEnd.SetTab(nTabCount-1);
1326 0 : pRefDoc->CopyToDocument( aCopyRange, nFlags, bMulti, pDoc, &aMarkData );
1327 0 : pDocShell->PostPaint( aRange, PAINT_GRID);
1328 0 : pDocShell->PostDataChanged();
1329 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1330 0 : if (pViewShell)
1331 0 : pViewShell->CellContentChanged();
1332 0 : }
1333 :
1334 0 : void ScUndoRefConversion::Undo()
1335 : {
1336 0 : BeginUndo();
1337 0 : if (pUndoDoc)
1338 0 : DoChange(pUndoDoc);
1339 0 : ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
1340 0 : if ( pChangeTrack )
1341 0 : pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
1342 0 : EndUndo();
1343 0 : }
1344 :
1345 0 : void ScUndoRefConversion::Redo()
1346 : {
1347 0 : BeginRedo();
1348 0 : if (pRedoDoc)
1349 0 : DoChange(pRedoDoc);
1350 0 : SetChangeTrack();
1351 0 : EndRedo();
1352 0 : }
1353 :
1354 0 : void ScUndoRefConversion::Repeat(SfxRepeatTarget& rTarget)
1355 : {
1356 0 : if (rTarget.ISA(ScTabViewTarget))
1357 0 : ((ScTabViewTarget&)rTarget).GetViewShell()->DoRefConversion();
1358 0 : }
1359 :
1360 0 : bool ScUndoRefConversion::CanRepeat(SfxRepeatTarget& rTarget) const
1361 : {
1362 0 : return rTarget.ISA(ScTabViewTarget);
1363 : }
1364 :
1365 2 : ScUndoRefreshLink::ScUndoRefreshLink( ScDocShell* pNewDocShell,
1366 : ScDocument* pNewUndoDoc )
1367 : : ScSimpleUndo( pNewDocShell ),
1368 : pUndoDoc( pNewUndoDoc ),
1369 2 : pRedoDoc( NULL )
1370 : {
1371 2 : }
1372 :
1373 6 : ScUndoRefreshLink::~ScUndoRefreshLink()
1374 : {
1375 2 : delete pUndoDoc;
1376 2 : delete pRedoDoc;
1377 4 : }
1378 :
1379 6 : OUString ScUndoRefreshLink::GetComment() const
1380 : {
1381 6 : return ScGlobal::GetRscString( STR_UNDO_UPDATELINK );
1382 : }
1383 :
1384 0 : void ScUndoRefreshLink::Undo()
1385 : {
1386 0 : BeginUndo();
1387 :
1388 0 : sal_Bool bMakeRedo = !pRedoDoc;
1389 0 : if (bMakeRedo)
1390 0 : pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
1391 :
1392 0 : sal_Bool bFirst = sal_True;
1393 0 : ScDocument* pDoc = pDocShell->GetDocument();
1394 0 : SCTAB nCount = pDoc->GetTableCount();
1395 0 : for (SCTAB nTab=0; nTab<nCount; nTab++)
1396 0 : if (pUndoDoc->HasTable(nTab))
1397 : {
1398 0 : ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
1399 0 : if (bMakeRedo)
1400 : {
1401 0 : if (bFirst)
1402 0 : pRedoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
1403 : else
1404 0 : pRedoDoc->AddUndoTab( nTab, nTab, true, true );
1405 0 : bFirst = false;
1406 0 : pDoc->CopyToDocument(aRange, IDF_ALL, false, pRedoDoc);
1407 : pRedoDoc->SetLink( nTab,
1408 0 : pDoc->GetLinkMode(nTab),
1409 : pDoc->GetLinkDoc(nTab),
1410 : pDoc->GetLinkFlt(nTab),
1411 : pDoc->GetLinkOpt(nTab),
1412 : pDoc->GetLinkTab(nTab),
1413 0 : pDoc->GetLinkRefreshDelay(nTab) );
1414 0 : pRedoDoc->SetTabBgColor( nTab, pDoc->GetTabBgColor(nTab) );
1415 : }
1416 :
1417 0 : pDoc->DeleteAreaTab( aRange,IDF_ALL );
1418 0 : pUndoDoc->CopyToDocument( aRange, IDF_ALL, false, pDoc );
1419 0 : pDoc->SetLink( nTab, pUndoDoc->GetLinkMode(nTab), pUndoDoc->GetLinkDoc(nTab),
1420 : pUndoDoc->GetLinkFlt(nTab), pUndoDoc->GetLinkOpt(nTab),
1421 : pUndoDoc->GetLinkTab(nTab),
1422 0 : pUndoDoc->GetLinkRefreshDelay(nTab) );
1423 0 : pDoc->SetTabBgColor( nTab, pUndoDoc->GetTabBgColor(nTab) );
1424 : }
1425 :
1426 0 : pDocShell->PostPaintGridAll();
1427 0 : pDocShell->PostPaintExtras();
1428 :
1429 0 : EndUndo();
1430 0 : }
1431 :
1432 0 : void ScUndoRefreshLink::Redo()
1433 : {
1434 : OSL_ENSURE(pRedoDoc, "No RedoDoc for ScUndoRefreshLink::Redo");
1435 :
1436 0 : BeginUndo();
1437 :
1438 0 : ScDocument* pDoc = pDocShell->GetDocument();
1439 0 : SCTAB nCount = pDoc->GetTableCount();
1440 0 : for (SCTAB nTab=0; nTab<nCount; nTab++)
1441 0 : if (pRedoDoc->HasTable(nTab))
1442 : {
1443 0 : ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
1444 :
1445 0 : pDoc->DeleteAreaTab( aRange, IDF_ALL );
1446 0 : pRedoDoc->CopyToDocument( aRange, IDF_ALL, false, pDoc );
1447 : pDoc->SetLink( nTab,
1448 0 : pRedoDoc->GetLinkMode(nTab),
1449 : pRedoDoc->GetLinkDoc(nTab),
1450 : pRedoDoc->GetLinkFlt(nTab),
1451 : pRedoDoc->GetLinkOpt(nTab),
1452 : pRedoDoc->GetLinkTab(nTab),
1453 0 : pRedoDoc->GetLinkRefreshDelay(nTab) );
1454 0 : pDoc->SetTabBgColor( nTab, pRedoDoc->GetTabBgColor(nTab) );
1455 : }
1456 :
1457 0 : pDocShell->PostPaintGridAll();
1458 0 : pDocShell->PostPaintExtras();
1459 :
1460 0 : EndUndo();
1461 0 : }
1462 :
1463 0 : void ScUndoRefreshLink::Repeat(SfxRepeatTarget& /* rTarget */)
1464 : {
1465 : // makes no sense
1466 0 : }
1467 :
1468 4 : bool ScUndoRefreshLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1469 : {
1470 4 : return false;
1471 : }
1472 :
1473 0 : static ScAreaLink* lcl_FindAreaLink( sfx2::LinkManager* pLinkManager, const String& rDoc,
1474 : const String& rFlt, const String& rOpt,
1475 : const String& rSrc, const ScRange& rDest )
1476 : {
1477 0 : const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
1478 0 : sal_uInt16 nCount = pLinkManager->GetLinks().size();
1479 0 : for (sal_uInt16 i=0; i<nCount; i++)
1480 : {
1481 0 : ::sfx2::SvBaseLink* pBase = *rLinks[i];
1482 0 : if (pBase->ISA(ScAreaLink))
1483 0 : if ( ((ScAreaLink*)pBase)->IsEqual( rDoc, rFlt, rOpt, rSrc, rDest ) )
1484 0 : return (ScAreaLink*)pBase;
1485 : }
1486 :
1487 : OSL_FAIL("ScAreaLink not found");
1488 0 : return NULL;
1489 : }
1490 :
1491 16 : ScUndoInsertAreaLink::ScUndoInsertAreaLink( ScDocShell* pShell,
1492 : const String& rDoc,
1493 : const String& rFlt, const String& rOpt,
1494 : const String& rArea, const ScRange& rDestRange,
1495 : sal_uLong nRefresh )
1496 : : ScSimpleUndo ( pShell ),
1497 : aDocName ( rDoc ),
1498 : aFltName ( rFlt ),
1499 : aOptions ( rOpt ),
1500 : aAreaName ( rArea ),
1501 : aRange ( rDestRange ),
1502 16 : nRefreshDelay ( nRefresh )
1503 : {
1504 16 : }
1505 :
1506 32 : ScUndoInsertAreaLink::~ScUndoInsertAreaLink()
1507 : {
1508 32 : }
1509 :
1510 16 : OUString ScUndoInsertAreaLink::GetComment() const
1511 : {
1512 16 : return ScGlobal::GetRscString( STR_UNDO_INSERTAREALINK );
1513 : }
1514 :
1515 0 : void ScUndoInsertAreaLink::Undo()
1516 : {
1517 0 : ScDocument* pDoc = pDocShell->GetDocument();
1518 0 : sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1519 :
1520 : ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aDocName, aFltName, aOptions,
1521 0 : aAreaName, aRange );
1522 0 : if (pLink)
1523 0 : pLinkManager->Remove( pLink );
1524 :
1525 0 : SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) ); // Navigator
1526 0 : }
1527 :
1528 0 : void ScUndoInsertAreaLink::Redo()
1529 : {
1530 0 : ScDocument* pDoc = pDocShell->GetDocument();
1531 0 : sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1532 :
1533 : ScAreaLink* pLink = new ScAreaLink( pDocShell, aDocName, aFltName, aOptions,
1534 0 : aAreaName, aRange.aStart, nRefreshDelay );
1535 0 : pLink->SetInCreate( sal_True );
1536 0 : pLink->SetDestArea( aRange );
1537 0 : pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aDocName, &aFltName, &aAreaName );
1538 0 : pLink->Update();
1539 0 : pLink->SetInCreate( false );
1540 :
1541 0 : SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) ); // Navigator
1542 0 : }
1543 :
1544 0 : void ScUndoInsertAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
1545 : {
1546 : // makes no sense
1547 0 : }
1548 :
1549 0 : bool ScUndoInsertAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1550 : {
1551 0 : return false;
1552 : }
1553 :
1554 0 : ScUndoRemoveAreaLink::ScUndoRemoveAreaLink( ScDocShell* pShell,
1555 : const String& rDoc, const String& rFlt, const String& rOpt,
1556 : const String& rArea, const ScRange& rDestRange,
1557 : sal_uLong nRefresh )
1558 : : ScSimpleUndo ( pShell ),
1559 : aDocName ( rDoc ),
1560 : aFltName ( rFlt ),
1561 : aOptions ( rOpt ),
1562 : aAreaName ( rArea ),
1563 : aRange ( rDestRange ),
1564 0 : nRefreshDelay ( nRefresh )
1565 : {
1566 0 : }
1567 :
1568 0 : ScUndoRemoveAreaLink::~ScUndoRemoveAreaLink()
1569 : {
1570 0 : }
1571 :
1572 0 : OUString ScUndoRemoveAreaLink::GetComment() const
1573 : {
1574 0 : return ScGlobal::GetRscString( STR_UNDO_REMOVELINK ); //! eigener Text ??
1575 : }
1576 :
1577 0 : void ScUndoRemoveAreaLink::Undo()
1578 : {
1579 0 : ScDocument* pDoc = pDocShell->GetDocument();
1580 0 : sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1581 :
1582 : ScAreaLink* pLink = new ScAreaLink( pDocShell, aDocName, aFltName, aOptions,
1583 0 : aAreaName, aRange.aStart, nRefreshDelay );
1584 0 : pLink->SetInCreate( sal_True );
1585 0 : pLink->SetDestArea( aRange );
1586 0 : pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aDocName, &aFltName, &aAreaName );
1587 0 : pLink->Update();
1588 0 : pLink->SetInCreate( false );
1589 :
1590 0 : SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) ); // Navigator
1591 0 : }
1592 :
1593 0 : void ScUndoRemoveAreaLink::Redo()
1594 : {
1595 0 : ScDocument* pDoc = pDocShell->GetDocument();
1596 0 : sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1597 :
1598 : ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aDocName, aFltName, aOptions,
1599 0 : aAreaName, aRange );
1600 0 : if (pLink)
1601 0 : pLinkManager->Remove( pLink );
1602 :
1603 0 : SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) ); // Navigator
1604 0 : }
1605 :
1606 0 : void ScUndoRemoveAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
1607 : {
1608 : // makes no sense
1609 0 : }
1610 :
1611 0 : bool ScUndoRemoveAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1612 : {
1613 0 : return false;
1614 : }
1615 :
1616 4 : ScUndoUpdateAreaLink::ScUndoUpdateAreaLink( ScDocShell* pShell,
1617 : const String& rOldD, const String& rOldF, const String& rOldO,
1618 : const String& rOldA, const ScRange& rOldR, sal_uLong nOldRD,
1619 : const String& rNewD, const String& rNewF, const String& rNewO,
1620 : const String& rNewA, const ScRange& rNewR, sal_uLong nNewRD,
1621 : ScDocument* pUndo, ScDocument* pRedo, sal_Bool bDoInsert )
1622 : : ScSimpleUndo( pShell ),
1623 : aOldDoc ( rOldD ),
1624 : aOldFlt ( rOldF ),
1625 : aOldOpt ( rOldO ),
1626 : aOldArea ( rOldA ),
1627 : aOldRange ( rOldR ),
1628 : aNewDoc ( rNewD ),
1629 : aNewFlt ( rNewF ),
1630 : aNewOpt ( rNewO ),
1631 : aNewArea ( rNewA ),
1632 : aNewRange ( rNewR ),
1633 : pUndoDoc ( pUndo ),
1634 : pRedoDoc ( pRedo ),
1635 : nOldRefresh ( nOldRD ),
1636 : nNewRefresh ( nNewRD ),
1637 4 : bWithInsert ( bDoInsert )
1638 : {
1639 : OSL_ENSURE( aOldRange.aStart == aNewRange.aStart, "AreaLink moved ?" );
1640 4 : }
1641 :
1642 12 : ScUndoUpdateAreaLink::~ScUndoUpdateAreaLink()
1643 : {
1644 4 : delete pUndoDoc;
1645 4 : delete pRedoDoc;
1646 8 : }
1647 :
1648 10 : OUString ScUndoUpdateAreaLink::GetComment() const
1649 : {
1650 10 : return ScGlobal::GetRscString( STR_UNDO_UPDATELINK ); //! own text ??
1651 : }
1652 :
1653 0 : void ScUndoUpdateAreaLink::DoChange( const sal_Bool bUndo ) const
1654 : {
1655 0 : ScDocument* pDoc = pDocShell->GetDocument();
1656 :
1657 0 : SCCOL nEndX = std::max( aOldRange.aEnd.Col(), aNewRange.aEnd.Col() );
1658 0 : SCROW nEndY = std::max( aOldRange.aEnd.Row(), aNewRange.aEnd.Row() );
1659 0 : SCTAB nEndZ = std::max( aOldRange.aEnd.Tab(), aNewRange.aEnd.Tab() ); //?
1660 :
1661 0 : if ( bUndo )
1662 : {
1663 0 : if ( bWithInsert )
1664 : {
1665 0 : pDoc->FitBlock( aNewRange, aOldRange );
1666 0 : pDoc->DeleteAreaTab( aOldRange, IDF_ALL & ~IDF_NOTE );
1667 0 : pUndoDoc->UndoToDocument( aOldRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
1668 : }
1669 : else
1670 : {
1671 0 : ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) );
1672 0 : pDoc->DeleteAreaTab( aCopyRange, IDF_ALL & ~IDF_NOTE );
1673 0 : pUndoDoc->CopyToDocument( aCopyRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
1674 : }
1675 : }
1676 : else
1677 : {
1678 0 : if ( bWithInsert )
1679 : {
1680 0 : pDoc->FitBlock( aOldRange, aNewRange );
1681 0 : pDoc->DeleteAreaTab( aNewRange, IDF_ALL & ~IDF_NOTE );
1682 0 : pRedoDoc->CopyToDocument( aNewRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
1683 : }
1684 : else
1685 : {
1686 0 : ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) );
1687 0 : pDoc->DeleteAreaTab( aCopyRange, IDF_ALL & ~IDF_NOTE );
1688 0 : pRedoDoc->CopyToDocument( aCopyRange, IDF_ALL & ~IDF_NOTE, false, pDoc );
1689 : }
1690 : }
1691 :
1692 0 : ScRange aWorkRange( aNewRange.aStart, ScAddress( nEndX, nEndY, nEndZ ) );
1693 0 : pDoc->ExtendMerge( aWorkRange, sal_True );
1694 :
1695 : // Paint
1696 :
1697 0 : if ( aNewRange.aEnd.Col() != aOldRange.aEnd.Col() )
1698 0 : aWorkRange.aEnd.SetCol(MAXCOL);
1699 0 : if ( aNewRange.aEnd.Row() != aOldRange.aEnd.Row() )
1700 0 : aWorkRange.aEnd.SetRow(MAXROW);
1701 :
1702 0 : if ( !pDocShell->AdjustRowHeight( aWorkRange.aStart.Row(), aWorkRange.aEnd.Row(), aWorkRange.aStart.Tab() ) )
1703 0 : pDocShell->PostPaint( aWorkRange, PAINT_GRID );
1704 :
1705 0 : pDocShell->PostDataChanged();
1706 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1707 0 : if (pViewShell)
1708 0 : pViewShell->CellContentChanged();
1709 0 : }
1710 :
1711 0 : void ScUndoUpdateAreaLink::Undo()
1712 : {
1713 0 : ScDocument* pDoc = pDocShell->GetDocument();
1714 0 : sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1715 : ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aNewDoc, aNewFlt, aNewOpt,
1716 0 : aNewArea, aNewRange );
1717 0 : if (pLink)
1718 : {
1719 0 : pLink->SetSource( aOldDoc, aOldFlt, aOldOpt, aOldArea ); // old data in Link
1720 0 : pLink->SetDestArea( aOldRange );
1721 0 : pLink->SetRefreshDelay( nOldRefresh );
1722 : }
1723 :
1724 0 : DoChange(sal_True);
1725 0 : }
1726 :
1727 0 : void ScUndoUpdateAreaLink::Redo()
1728 : {
1729 0 : ScDocument* pDoc = pDocShell->GetDocument();
1730 0 : sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1731 : ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aOldDoc, aOldFlt, aOldOpt,
1732 0 : aOldArea, aOldRange );
1733 0 : if (pLink)
1734 : {
1735 0 : pLink->SetSource( aNewDoc, aNewFlt, aNewOpt, aNewArea ); // neue Werte im Link
1736 0 : pLink->SetDestArea( aNewRange );
1737 0 : pLink->SetRefreshDelay( nNewRefresh );
1738 : }
1739 :
1740 0 : DoChange(false);
1741 0 : }
1742 :
1743 0 : void ScUndoUpdateAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
1744 : {
1745 : // makes no sense
1746 0 : }
1747 :
1748 6 : bool ScUndoUpdateAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1749 : {
1750 6 : return false;
1751 93 : }
1752 :
1753 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|