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 <editeng/eeitem.hxx>
22 : #include <editeng/editobj.hxx>
23 : #include <svl/zforlist.hxx>
24 : #include <sfx2/app.hxx>
25 :
26 : #include "undocell.hxx"
27 : #include "document.hxx"
28 : #include "docpool.hxx"
29 : #include "patattr.hxx"
30 : #include "docsh.hxx"
31 : #include "tabvwsh.hxx"
32 : #include "globstr.hrc"
33 : #include "global.hxx"
34 : #include "formulacell.hxx"
35 : #include "target.hxx"
36 : #include "undoolk.hxx"
37 : #include "detdata.hxx"
38 : #include "stlpool.hxx"
39 : #include "printfun.hxx"
40 : #include "rangenam.hxx"
41 : #include "chgtrack.hxx"
42 : #include "sc.hrc"
43 : #include "docuno.hxx"
44 : #include "stringutil.hxx"
45 :
46 : using ::boost::shared_ptr;
47 :
48 0 : TYPEINIT1(ScUndoCursorAttr, ScSimpleUndo);
49 0 : TYPEINIT1(ScUndoEnterData, ScSimpleUndo);
50 0 : TYPEINIT1(ScUndoEnterValue, ScSimpleUndo);
51 0 : TYPEINIT1(ScUndoSetCell, ScSimpleUndo);
52 0 : TYPEINIT1(ScUndoPageBreak, ScSimpleUndo);
53 0 : TYPEINIT1(ScUndoPrintZoom, ScSimpleUndo);
54 0 : TYPEINIT1(ScUndoThesaurus, ScSimpleUndo);
55 0 : TYPEINIT1(ScUndoReplaceNote, ScSimpleUndo);
56 0 : TYPEINIT1(ScUndoShowHideNote, ScSimpleUndo);
57 0 : TYPEINIT1(ScUndoDetective, ScSimpleUndo);
58 0 : TYPEINIT1(ScUndoRangeNames, ScSimpleUndo);
59 :
60 0 : ScUndoCursorAttr::ScUndoCursorAttr( ScDocShell* pNewDocShell,
61 : SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
62 : const ScPatternAttr* pOldPat, const ScPatternAttr* pNewPat,
63 : const ScPatternAttr* pApplyPat, sal_Bool bAutomatic ) :
64 : ScSimpleUndo( pNewDocShell ),
65 : nCol( nNewCol ),
66 : nRow( nNewRow ),
67 : nTab( nNewTab ),
68 : pOldEditData( static_cast<EditTextObject*>(NULL) ),
69 : pNewEditData( static_cast<EditTextObject*>(NULL) ),
70 0 : bIsAutomatic( bAutomatic )
71 : {
72 0 : ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
73 0 : pNewPattern = (ScPatternAttr*) &pPool->Put( *pNewPat );
74 0 : pOldPattern = (ScPatternAttr*) &pPool->Put( *pOldPat );
75 0 : pApplyPattern = (ScPatternAttr*) &pPool->Put( *pApplyPat );
76 0 : }
77 :
78 0 : ScUndoCursorAttr::~ScUndoCursorAttr()
79 : {
80 0 : ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
81 0 : pPool->Remove(*pNewPattern);
82 0 : pPool->Remove(*pOldPattern);
83 0 : pPool->Remove(*pApplyPattern);
84 0 : }
85 :
86 0 : OUString ScUndoCursorAttr::GetComment() const
87 : {
88 : //! own text for automatic attribution
89 :
90 0 : sal_uInt16 nId = STR_UNDO_CURSORATTR; // "Attribute"
91 0 : return ScGlobal::GetRscString( nId );
92 : }
93 :
94 0 : void ScUndoCursorAttr::SetEditData( EditTextObject* pOld, EditTextObject* pNew )
95 : {
96 0 : pOldEditData.reset(pOld);
97 0 : pNewEditData.reset(pNew);
98 0 : }
99 :
100 0 : void ScUndoCursorAttr::DoChange( const ScPatternAttr* pWhichPattern, const shared_ptr<EditTextObject>& pEditData ) const
101 : {
102 0 : ScDocument* pDoc = pDocShell->GetDocument();
103 0 : ScAddress aPos(nCol, nRow, nTab);
104 0 : pDoc->SetPattern( nCol, nRow, nTab, *pWhichPattern, true );
105 :
106 0 : if (pDoc->GetCellType(aPos) == CELLTYPE_EDIT && pEditData)
107 0 : pDoc->SetEditText(aPos, *pEditData, NULL);
108 :
109 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
110 0 : if (pViewShell)
111 : {
112 0 : pViewShell->SetTabNo( nTab );
113 0 : pViewShell->MoveCursorAbs( nCol, nRow, SC_FOLLOW_JUMP, false, false );
114 0 : pViewShell->AdjustBlockHeight();
115 : }
116 :
117 0 : const SfxItemSet& rApplySet = pApplyPattern->GetItemSet();
118 0 : sal_Bool bPaintExt = ( rApplySet.GetItemState( ATTR_SHADOW, sal_True ) != SFX_ITEM_DEFAULT ||
119 0 : rApplySet.GetItemState( ATTR_CONDITIONAL, sal_True ) != SFX_ITEM_DEFAULT );
120 0 : sal_Bool bPaintRows = ( rApplySet.GetItemState( ATTR_HOR_JUSTIFY, sal_True ) != SFX_ITEM_DEFAULT );
121 :
122 0 : sal_uInt16 nFlags = SC_PF_TESTMERGE;
123 0 : if (bPaintExt)
124 0 : nFlags |= SC_PF_LINES;
125 0 : if (bPaintRows)
126 0 : nFlags |= SC_PF_WHOLEROWS;
127 0 : pDocShell->PostPaint( nCol,nRow,nTab, nCol,nRow,nTab, PAINT_GRID, nFlags );
128 0 : }
129 :
130 0 : void ScUndoCursorAttr::Undo()
131 : {
132 0 : BeginUndo();
133 0 : DoChange(pOldPattern, pOldEditData);
134 :
135 0 : if ( bIsAutomatic )
136 : {
137 : // if automatic formatting is reversed, then
138 : // automatic formatting should also not continue to be done
139 :
140 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
141 0 : if (pViewShell)
142 0 : pViewShell->ForgetFormatArea();
143 : }
144 :
145 0 : EndUndo();
146 0 : }
147 :
148 0 : void ScUndoCursorAttr::Redo()
149 : {
150 0 : BeginRedo();
151 0 : DoChange(pNewPattern, pNewEditData);
152 0 : EndRedo();
153 0 : }
154 :
155 0 : void ScUndoCursorAttr::Repeat(SfxRepeatTarget& rTarget)
156 : {
157 0 : if (rTarget.ISA(ScTabViewTarget))
158 0 : ((ScTabViewTarget&)rTarget).GetViewShell()->ApplySelectionPattern( *pApplyPattern );
159 0 : }
160 :
161 0 : bool ScUndoCursorAttr::CanRepeat(SfxRepeatTarget& rTarget) const
162 : {
163 0 : return rTarget.ISA(ScTabViewTarget);
164 : }
165 :
166 2062 : ScUndoEnterData::Value::Value() : mnTab(-1), mbHasFormat(false), mnFormat(0) {}
167 :
168 2062 : ScUndoEnterData::ScUndoEnterData(
169 : ScDocShell* pNewDocShell, const ScAddress& rPos, ValuesType& rOldValues,
170 : const OUString& rNewStr, EditTextObject* pObj ) :
171 : ScSimpleUndo( pNewDocShell ),
172 : maNewString(rNewStr),
173 : mpNewEditData(pObj),
174 : mnEndChangeAction(0),
175 2062 : maPos(rPos)
176 : {
177 2062 : maOldValues.swap(rOldValues);
178 :
179 2062 : SetChangeTrack();
180 2062 : }
181 :
182 4124 : ScUndoEnterData::~ScUndoEnterData() {}
183 :
184 2182 : OUString ScUndoEnterData::GetComment() const
185 : {
186 2182 : return ScGlobal::GetRscString( STR_UNDO_ENTERDATA ); // "Input"
187 : }
188 :
189 0 : void ScUndoEnterData::DoChange() const
190 : {
191 : // only when needed (old or new Edit cell, or Attribute)?
192 0 : for (size_t i = 0, n = maOldValues.size(); i < n; ++i)
193 0 : pDocShell->AdjustRowHeight(maPos.Row(), maPos.Row(), maOldValues[i].mnTab);
194 :
195 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
196 0 : if (pViewShell)
197 : {
198 0 : pViewShell->SetTabNo(maPos.Tab());
199 0 : pViewShell->MoveCursorAbs(maPos.Col(), maPos.Row(), SC_FOLLOW_JUMP, false, false);
200 : }
201 :
202 0 : pDocShell->PostDataChanged();
203 0 : }
204 :
205 2062 : void ScUndoEnterData::SetChangeTrack()
206 : {
207 2062 : ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
208 2062 : if ( pChangeTrack )
209 : {
210 0 : mnEndChangeAction = pChangeTrack->GetActionMax() + 1;
211 0 : ScAddress aPos(maPos);
212 0 : for (size_t i = 0, n = maOldValues.size(); i < n; ++i)
213 : {
214 0 : aPos.SetTab(maOldValues[i].mnTab);
215 0 : sal_uLong nFormat = 0;
216 0 : if (maOldValues[i].mbHasFormat)
217 0 : nFormat = maOldValues[i].mnFormat;
218 0 : pChangeTrack->AppendContent(aPos, maOldValues[i].maCell, nFormat);
219 : }
220 0 : if ( mnEndChangeAction > pChangeTrack->GetActionMax() )
221 0 : mnEndChangeAction = 0; // nothing is appended
222 : }
223 : else
224 2062 : mnEndChangeAction = 0;
225 2062 : }
226 :
227 0 : void ScUndoEnterData::Undo()
228 : {
229 0 : BeginUndo();
230 :
231 0 : ScDocument* pDoc = pDocShell->GetDocument();
232 0 : for (size_t i = 0, n = maOldValues.size(); i < n; ++i)
233 : {
234 0 : Value& rVal = maOldValues[i];
235 0 : ScCellValue aNewCell;
236 0 : aNewCell.assign(rVal.maCell, *pDoc, SC_CLONECELL_STARTLISTENING);
237 0 : ScAddress aPos = maPos;
238 0 : aPos.SetTab(rVal.mnTab);
239 0 : aNewCell.release(*pDoc, aPos);
240 :
241 0 : if (rVal.mbHasFormat)
242 0 : pDoc->ApplyAttr(maPos.Col(), maPos.Row(), rVal.mnTab,
243 0 : SfxUInt32Item(ATTR_VALUE_FORMAT, rVal.mnFormat));
244 : else
245 : {
246 0 : ScPatternAttr aPattern(*pDoc->GetPattern(maPos.Col(), maPos.Row(), rVal.mnTab));
247 0 : aPattern.GetItemSet().ClearItem( ATTR_VALUE_FORMAT );
248 0 : pDoc->SetPattern(maPos.Col(), maPos.Row(), rVal.mnTab, aPattern, true);
249 : }
250 0 : pDocShell->PostPaintCell(maPos.Col(), maPos.Row(), rVal.mnTab);
251 0 : }
252 :
253 0 : ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
254 0 : size_t nCount = maOldValues.size();
255 0 : if ( pChangeTrack && mnEndChangeAction >= sal::static_int_cast<sal_uLong>(nCount) )
256 0 : pChangeTrack->Undo( mnEndChangeAction - nCount + 1, mnEndChangeAction );
257 :
258 0 : DoChange();
259 0 : EndUndo();
260 :
261 : // #i97876# Spreadsheet data changes are not notified
262 0 : ScModelObj* pModelObj = ScModelObj::getImplementation( pDocShell->GetModel() );
263 0 : if ( pModelObj && pModelObj->HasChangesListeners() )
264 : {
265 0 : ScRangeList aChangeRanges;
266 0 : for (size_t i = 0, n = maOldValues.size(); i < n; ++i)
267 : {
268 0 : aChangeRanges.Append( ScRange(maPos.Col(), maPos.Row(), maOldValues[i].mnTab));
269 : }
270 0 : pModelObj->NotifyChanges( OUString( "cell-change" ), aChangeRanges );
271 : }
272 0 : }
273 :
274 0 : void ScUndoEnterData::Redo()
275 : {
276 0 : BeginRedo();
277 :
278 0 : ScDocument* pDoc = pDocShell->GetDocument();
279 0 : for (size_t i = 0, n = maOldValues.size(); i < n; ++i)
280 : {
281 0 : SCTAB nTab = maOldValues[i].mnTab;
282 0 : if (mpNewEditData)
283 : {
284 0 : ScAddress aPos = maPos;
285 0 : aPos.SetTab(nTab);
286 : // edit text wil be cloned.
287 0 : pDoc->SetEditText(aPos, *mpNewEditData, NULL);
288 : }
289 : else
290 0 : pDoc->SetString(maPos.Col(), maPos.Row(), nTab, maNewString);
291 :
292 0 : pDocShell->PostPaintCell(maPos.Col(), maPos.Row(), nTab);
293 : }
294 :
295 0 : SetChangeTrack();
296 :
297 0 : DoChange();
298 0 : EndRedo();
299 :
300 : // #i97876# Spreadsheet data changes are not notified
301 0 : ScModelObj* pModelObj = ScModelObj::getImplementation( pDocShell->GetModel() );
302 0 : if ( pModelObj && pModelObj->HasChangesListeners() )
303 : {
304 0 : ScRangeList aChangeRanges;
305 0 : for (size_t i = 0, n = maOldValues.size(); i < n; ++i)
306 : {
307 0 : aChangeRanges.Append(ScRange(maPos.Col(), maPos.Row(), maOldValues[i].mnTab));
308 : }
309 0 : pModelObj->NotifyChanges( OUString( "cell-change" ), aChangeRanges );
310 : }
311 0 : }
312 :
313 0 : void ScUndoEnterData::Repeat(SfxRepeatTarget& rTarget)
314 : {
315 0 : if (rTarget.ISA(ScTabViewTarget))
316 : {
317 0 : OUString aTemp = maNewString;
318 0 : ((ScTabViewTarget&)rTarget).GetViewShell()->EnterDataAtCursor( aTemp );
319 : }
320 0 : }
321 :
322 60 : bool ScUndoEnterData::CanRepeat(SfxRepeatTarget& rTarget) const
323 : {
324 60 : return rTarget.ISA(ScTabViewTarget);
325 : }
326 :
327 :
328 0 : ScUndoEnterValue::ScUndoEnterValue(
329 : ScDocShell* pNewDocShell, const ScAddress& rNewPos,
330 : const ScCellValue& rUndoCell, double nVal ) :
331 : ScSimpleUndo( pNewDocShell ),
332 : aPos ( rNewPos ),
333 : maOldCell(rUndoCell),
334 0 : nValue ( nVal )
335 : {
336 0 : SetChangeTrack();
337 0 : }
338 :
339 0 : ScUndoEnterValue::~ScUndoEnterValue()
340 : {
341 0 : }
342 :
343 0 : OUString ScUndoEnterValue::GetComment() const
344 : {
345 0 : return ScGlobal::GetRscString( STR_UNDO_ENTERDATA ); // "Input"
346 : }
347 :
348 0 : void ScUndoEnterValue::SetChangeTrack()
349 : {
350 0 : ScDocument* pDoc = pDocShell->GetDocument();
351 0 : ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
352 0 : if ( pChangeTrack )
353 : {
354 0 : nEndChangeAction = pChangeTrack->GetActionMax() + 1;
355 0 : pChangeTrack->AppendContent(aPos, maOldCell);
356 0 : if ( nEndChangeAction > pChangeTrack->GetActionMax() )
357 0 : nEndChangeAction = 0; // nothing is appended
358 : }
359 : else
360 0 : nEndChangeAction = 0;
361 0 : }
362 :
363 0 : void ScUndoEnterValue::Undo()
364 : {
365 0 : BeginUndo();
366 :
367 0 : ScDocument* pDoc = pDocShell->GetDocument();
368 0 : ScCellValue aNewCell;
369 0 : aNewCell.assign(maOldCell, *pDoc, SC_CLONECELL_STARTLISTENING);
370 0 : aNewCell.release(*pDoc, aPos);
371 :
372 0 : pDocShell->PostPaintCell( aPos );
373 :
374 0 : ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
375 0 : if ( pChangeTrack )
376 0 : pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
377 :
378 0 : EndUndo();
379 0 : }
380 :
381 0 : void ScUndoEnterValue::Redo()
382 : {
383 0 : BeginRedo();
384 :
385 0 : ScDocument* pDoc = pDocShell->GetDocument();
386 0 : pDoc->SetValue( aPos.Col(), aPos.Row(), aPos.Tab(), nValue );
387 0 : pDocShell->PostPaintCell( aPos );
388 :
389 0 : SetChangeTrack();
390 :
391 0 : EndRedo();
392 0 : }
393 :
394 0 : void ScUndoEnterValue::Repeat(SfxRepeatTarget& /* rTarget */)
395 : {
396 : // makes no sense
397 0 : }
398 :
399 0 : bool ScUndoEnterValue::CanRepeat(SfxRepeatTarget& /* rTarget */) const
400 : {
401 0 : return false;
402 : }
403 :
404 0 : ScUndoSetCell::ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScCellValue& rNewVal ) :
405 0 : ScSimpleUndo(pDocSh), maPos(rPos), maNewValue(rNewVal), mnEndChangeAction(0)
406 : {
407 0 : SetChangeTrack();
408 0 : }
409 :
410 5042 : ScUndoSetCell::ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScCellValue& rOldVal, const ScCellValue& rNewVal ) :
411 5042 : ScSimpleUndo(pDocSh), maPos(rPos), maOldValue(rOldVal), maNewValue(rNewVal), mnEndChangeAction(0)
412 : {
413 5042 : SetChangeTrack();
414 5042 : }
415 :
416 10084 : ScUndoSetCell::~ScUndoSetCell() {}
417 :
418 0 : void ScUndoSetCell::Undo()
419 : {
420 0 : BeginUndo();
421 0 : SetValue(maOldValue);
422 0 : pDocShell->PostPaintCell(maPos);
423 :
424 0 : ScDocument* pDoc = pDocShell->GetDocument();
425 0 : ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
426 0 : if (pChangeTrack)
427 0 : pChangeTrack->Undo(mnEndChangeAction, mnEndChangeAction);
428 :
429 0 : EndUndo();
430 0 : }
431 :
432 0 : void ScUndoSetCell::Redo()
433 : {
434 0 : BeginRedo();
435 0 : SetValue(maNewValue);
436 0 : pDocShell->PostPaintCell(maPos);
437 0 : SetChangeTrack();
438 0 : EndRedo();
439 0 : }
440 :
441 0 : void ScUndoSetCell::Repeat( SfxRepeatTarget& /*rTarget*/ )
442 : {
443 : // Makes no sense.
444 0 : }
445 :
446 18 : bool ScUndoSetCell::CanRepeat( SfxRepeatTarget& /*rTarget*/ ) const
447 : {
448 18 : return false;
449 : }
450 :
451 5060 : OUString ScUndoSetCell::GetComment() const
452 : {
453 5060 : return ScGlobal::GetRscString(STR_UNDO_ENTERDATA); // "Input"
454 : }
455 :
456 5042 : void ScUndoSetCell::SetChangeTrack()
457 : {
458 5042 : ScDocument* pDoc = pDocShell->GetDocument();
459 5042 : ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
460 5042 : if (pChangeTrack)
461 : {
462 0 : mnEndChangeAction = pChangeTrack->GetActionMax() + 1;
463 :
464 0 : pChangeTrack->AppendContent(maPos, maOldValue);
465 :
466 0 : if (mnEndChangeAction > pChangeTrack->GetActionMax())
467 0 : mnEndChangeAction = 0; // Nothing is appended
468 : }
469 : else
470 5042 : mnEndChangeAction = 0;
471 5042 : }
472 :
473 0 : void ScUndoSetCell::SetValue( const ScCellValue& rVal )
474 : {
475 0 : ScDocument* pDoc = pDocShell->GetDocument();
476 :
477 0 : switch (rVal.meType)
478 : {
479 : case CELLTYPE_NONE:
480 : // empty cell
481 0 : pDoc->SetEmptyCell(maPos);
482 0 : break;
483 : case CELLTYPE_VALUE:
484 0 : pDoc->SetValue(maPos, rVal.mfValue);
485 0 : break;
486 : case CELLTYPE_STRING:
487 : {
488 0 : ScSetStringParam aParam;
489 0 : aParam.setTextInput();
490 0 : pDoc->SetString(maPos, *rVal.mpString);
491 : }
492 0 : break;
493 : case CELLTYPE_EDIT:
494 0 : pDoc->SetEditText(maPos, rVal.mpEditText->Clone());
495 0 : break;
496 : case CELLTYPE_FORMULA:
497 0 : pDoc->SetFormulaCell(maPos, rVal.mpFormula->Clone());
498 0 : break;
499 : default:
500 : ;
501 : }
502 0 : }
503 :
504 4 : ScUndoPageBreak::ScUndoPageBreak( ScDocShell* pNewDocShell,
505 : SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
506 : sal_Bool bNewColumn, sal_Bool bNewInsert ) :
507 : ScSimpleUndo( pNewDocShell ),
508 : nCol( nNewCol ),
509 : nRow( nNewRow ),
510 : nTab( nNewTab ),
511 : bColumn( bNewColumn ),
512 4 : bInsert( bNewInsert )
513 : {
514 4 : }
515 :
516 8 : ScUndoPageBreak::~ScUndoPageBreak()
517 : {
518 8 : }
519 :
520 4 : OUString ScUndoPageBreak::GetComment() const
521 : {
522 : //"Column break" | "Row break" "insert" | "delete"
523 : return String ( bColumn ?
524 : ( bInsert ?
525 : ScGlobal::GetRscString( STR_UNDO_INSCOLBREAK ) :
526 : ScGlobal::GetRscString( STR_UNDO_DELCOLBREAK )
527 : ) :
528 : ( bInsert ?
529 : ScGlobal::GetRscString( STR_UNDO_INSROWBREAK ) :
530 : ScGlobal::GetRscString( STR_UNDO_DELROWBREAK )
531 4 : ) );
532 : }
533 :
534 0 : void ScUndoPageBreak::DoChange( sal_Bool bInsertP ) const
535 : {
536 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
537 :
538 0 : if (pViewShell)
539 : {
540 0 : pViewShell->SetTabNo( nTab );
541 0 : pViewShell->MoveCursorAbs( nCol, nRow, SC_FOLLOW_JUMP, false, false );
542 :
543 0 : if (bInsertP)
544 0 : pViewShell->InsertPageBreak(bColumn, false);
545 : else
546 0 : pViewShell->DeletePageBreak(bColumn, false);
547 :
548 0 : pDocShell->GetDocument()->InvalidatePageBreaks(nTab);
549 : }
550 0 : }
551 :
552 0 : void ScUndoPageBreak::Undo()
553 : {
554 0 : BeginUndo();
555 0 : DoChange(!bInsert);
556 0 : EndUndo();
557 0 : }
558 :
559 0 : void ScUndoPageBreak::Redo()
560 : {
561 0 : BeginRedo();
562 0 : DoChange(bInsert);
563 0 : EndRedo();
564 0 : }
565 :
566 0 : void ScUndoPageBreak::Repeat(SfxRepeatTarget& rTarget)
567 : {
568 0 : if (rTarget.ISA(ScTabViewTarget))
569 : {
570 0 : ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
571 :
572 0 : if (bInsert)
573 0 : rViewShell.InsertPageBreak(bColumn, sal_True);
574 : else
575 0 : rViewShell.DeletePageBreak(bColumn, sal_True);
576 : }
577 0 : }
578 :
579 0 : bool ScUndoPageBreak::CanRepeat(SfxRepeatTarget& rTarget) const
580 : {
581 0 : return rTarget.ISA(ScTabViewTarget);
582 : }
583 :
584 0 : ScUndoPrintZoom::ScUndoPrintZoom( ScDocShell* pNewDocShell,
585 : SCTAB nT, sal_uInt16 nOS, sal_uInt16 nOP, sal_uInt16 nNS, sal_uInt16 nNP ) :
586 : ScSimpleUndo( pNewDocShell ),
587 : nTab( nT ),
588 : nOldScale( nOS ),
589 : nOldPages( nOP ),
590 : nNewScale( nNS ),
591 0 : nNewPages( nNP )
592 : {
593 0 : }
594 :
595 0 : ScUndoPrintZoom::~ScUndoPrintZoom()
596 : {
597 0 : }
598 :
599 0 : OUString ScUndoPrintZoom::GetComment() const
600 : {
601 0 : return ScGlobal::GetRscString( STR_UNDO_PRINTSCALE );
602 : }
603 :
604 0 : void ScUndoPrintZoom::DoChange( sal_Bool bUndo )
605 : {
606 0 : sal_uInt16 nScale = bUndo ? nOldScale : nNewScale;
607 0 : sal_uInt16 nPages = bUndo ? nOldPages : nNewPages;
608 :
609 0 : ScDocument* pDoc = pDocShell->GetDocument();
610 0 : String aStyleName = pDoc->GetPageStyle( nTab );
611 0 : ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
612 0 : SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE );
613 : OSL_ENSURE( pStyleSheet, "PageStyle not found" );
614 0 : if ( pStyleSheet )
615 : {
616 0 : SfxItemSet& rSet = pStyleSheet->GetItemSet();
617 0 : rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nScale ) );
618 0 : rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, nPages ) );
619 :
620 0 : ScPrintFunc aPrintFunc( pDocShell, pDocShell->GetPrinter(), nTab );
621 0 : aPrintFunc.UpdatePages();
622 0 : }
623 0 : }
624 :
625 0 : void ScUndoPrintZoom::Undo()
626 : {
627 0 : BeginUndo();
628 0 : DoChange(sal_True);
629 0 : EndUndo();
630 0 : }
631 :
632 0 : void ScUndoPrintZoom::Redo()
633 : {
634 0 : BeginRedo();
635 0 : DoChange(false);
636 0 : EndRedo();
637 0 : }
638 :
639 0 : void ScUndoPrintZoom::Repeat(SfxRepeatTarget& rTarget)
640 : {
641 0 : if (rTarget.ISA(ScTabViewTarget))
642 : {
643 0 : ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
644 0 : ScViewData* pViewData = rViewShell.GetViewData();
645 0 : pViewData->GetDocShell()->SetPrintZoom( pViewData->GetTabNo(), nNewScale, nNewPages );
646 : }
647 0 : }
648 :
649 0 : bool ScUndoPrintZoom::CanRepeat(SfxRepeatTarget& rTarget) const
650 : {
651 0 : return rTarget.ISA(ScTabViewTarget);
652 : }
653 :
654 0 : ScUndoThesaurus::ScUndoThesaurus( ScDocShell* pNewDocShell,
655 : SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
656 : const String& rNewUndoStr, const EditTextObject* pUndoTObj,
657 : const String& rNewRedoStr, const EditTextObject* pRedoTObj) :
658 : ScSimpleUndo( pNewDocShell ),
659 : nCol( nNewCol ),
660 : nRow( nNewRow ),
661 : nTab( nNewTab ),
662 : aUndoStr( rNewUndoStr ),
663 0 : aRedoStr( rNewRedoStr )
664 : {
665 0 : pUndoTObject = (pUndoTObj) ? pUndoTObj->Clone() : NULL;
666 0 : pRedoTObject = (pRedoTObj) ? pRedoTObj->Clone() : NULL;
667 :
668 0 : ScCellValue aOldCell;
669 0 : if ( pUndoTObject )
670 : {
671 0 : aOldCell.meType = CELLTYPE_EDIT;
672 0 : aOldCell.mpEditText = pUndoTObject->Clone();
673 : }
674 : else
675 : {
676 0 : aOldCell.meType = CELLTYPE_STRING;
677 0 : aOldCell.mpString = new OUString(aUndoStr);
678 : }
679 0 : SetChangeTrack(aOldCell);
680 0 : }
681 :
682 0 : ScUndoThesaurus::~ScUndoThesaurus()
683 : {
684 0 : delete pUndoTObject;
685 0 : delete pRedoTObject;
686 0 : }
687 :
688 0 : OUString ScUndoThesaurus::GetComment() const
689 : {
690 0 : return ScGlobal::GetRscString( STR_UNDO_THESAURUS ); // "Thesaurus"
691 : }
692 :
693 0 : void ScUndoThesaurus::SetChangeTrack( const ScCellValue& rOldCell )
694 : {
695 0 : ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
696 0 : if ( pChangeTrack )
697 : {
698 0 : nEndChangeAction = pChangeTrack->GetActionMax() + 1;
699 0 : pChangeTrack->AppendContent(ScAddress(nCol, nRow, nTab), rOldCell);
700 0 : if ( nEndChangeAction > pChangeTrack->GetActionMax() )
701 0 : nEndChangeAction = 0; // nothing is appended
702 : }
703 : else
704 0 : nEndChangeAction = 0;
705 0 : }
706 :
707 0 : void ScUndoThesaurus::DoChange( sal_Bool bUndo, const String& rStr,
708 : const EditTextObject* pTObj )
709 : {
710 0 : ScDocument* pDoc = pDocShell->GetDocument();
711 :
712 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
713 0 : if (pViewShell)
714 : {
715 0 : pViewShell->SetTabNo( nTab );
716 0 : pViewShell->MoveCursorAbs( nCol, nRow, SC_FOLLOW_JUMP, false, false );
717 : }
718 :
719 0 : ScAddress aPos(nCol, nRow, nTab);
720 :
721 0 : if (pTObj)
722 : {
723 : // This is edit text.
724 0 : if (pDoc->GetCellType(aPos) == CELLTYPE_EDIT)
725 : {
726 0 : ScCellValue aOldCell;
727 0 : if (!bUndo)
728 0 : aOldCell.assign(*pDoc, aPos);
729 :
730 : // A copy of pTObj will be stored in the cell.
731 0 : pDoc->SetEditText(aPos, *pTObj, pDoc->GetEditPool());
732 :
733 0 : if ( !bUndo )
734 0 : SetChangeTrack(aOldCell);
735 : }
736 : else
737 : {
738 : OSL_FAIL("Not CELLTYPE_EDIT for Un/RedoThesaurus");
739 : }
740 : }
741 : else
742 : {
743 : // This is simple unformatted string.
744 0 : ScCellValue aOldCell;
745 0 : if (!bUndo)
746 0 : aOldCell.assign(*pDoc, aPos);
747 :
748 0 : pDoc->SetString( nCol, nRow, nTab, rStr );
749 :
750 0 : if (!bUndo)
751 0 : SetChangeTrack(aOldCell);
752 : }
753 :
754 0 : pDocShell->PostPaintCell( nCol, nRow, nTab );
755 0 : }
756 :
757 0 : void ScUndoThesaurus::Undo()
758 : {
759 0 : BeginUndo();
760 0 : DoChange( sal_True, aUndoStr, pUndoTObject );
761 0 : ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
762 0 : if ( pChangeTrack )
763 0 : pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
764 0 : EndUndo();
765 0 : }
766 :
767 0 : void ScUndoThesaurus::Redo()
768 : {
769 0 : BeginRedo();
770 0 : DoChange( false, aRedoStr, pRedoTObject );
771 0 : EndRedo();
772 0 : }
773 :
774 0 : void ScUndoThesaurus::Repeat(SfxRepeatTarget& rTarget)
775 : {
776 0 : if (rTarget.ISA(ScTabViewTarget))
777 0 : ((ScTabViewTarget&)rTarget).GetViewShell()->DoThesaurus( sal_True );
778 0 : }
779 :
780 0 : bool ScUndoThesaurus::CanRepeat(SfxRepeatTarget& rTarget) const
781 : {
782 0 : return rTarget.ISA(ScTabViewTarget);
783 : }
784 :
785 0 : ScUndoReplaceNote::ScUndoReplaceNote( ScDocShell& rDocShell, const ScAddress& rPos,
786 : const ScNoteData& rNoteData, bool bInsert, SdrUndoAction* pDrawUndo ) :
787 : ScSimpleUndo( &rDocShell ),
788 : maPos( rPos ),
789 0 : mpDrawUndo( pDrawUndo )
790 : {
791 : OSL_ENSURE( rNoteData.mpCaption, "ScUndoReplaceNote::ScUndoReplaceNote - missing note caption" );
792 0 : (bInsert ? maNewData : maOldData) = rNoteData;
793 0 : }
794 :
795 6 : ScUndoReplaceNote::ScUndoReplaceNote( ScDocShell& rDocShell, const ScAddress& rPos,
796 : const ScNoteData& rOldData, const ScNoteData& rNewData, SdrUndoAction* pDrawUndo ) :
797 : ScSimpleUndo( &rDocShell ),
798 : maPos( rPos ),
799 : maOldData( rOldData ),
800 : maNewData( rNewData ),
801 6 : mpDrawUndo( pDrawUndo )
802 : {
803 : OSL_ENSURE( maOldData.mpCaption || maNewData.mpCaption, "ScUndoReplaceNote::ScUndoReplaceNote - missing note captions" );
804 : OSL_ENSURE( !maOldData.mxInitData.get() && !maNewData.mxInitData.get(), "ScUndoReplaceNote::ScUndoReplaceNote - unexpected unitialized note" );
805 6 : }
806 :
807 18 : ScUndoReplaceNote::~ScUndoReplaceNote()
808 : {
809 6 : DeleteSdrUndoAction( mpDrawUndo );
810 12 : }
811 :
812 0 : void ScUndoReplaceNote::Undo()
813 : {
814 0 : BeginUndo();
815 0 : DoSdrUndoAction( mpDrawUndo, pDocShell->GetDocument() );
816 : /* Undo insert -> remove new note.
817 : Undo remove -> insert old note.
818 : Undo replace -> remove new note, insert old note. */
819 0 : DoRemoveNote( maNewData );
820 0 : DoInsertNote( maOldData );
821 0 : pDocShell->PostPaintCell( maPos );
822 0 : EndUndo();
823 0 : }
824 :
825 0 : void ScUndoReplaceNote::Redo()
826 : {
827 0 : BeginRedo();
828 0 : RedoSdrUndoAction( mpDrawUndo );
829 : /* Redo insert -> insert new note.
830 : Redo remove -> remove old note.
831 : Redo replace -> remove old note, insert new note. */
832 0 : DoRemoveNote( maOldData );
833 0 : DoInsertNote( maNewData );
834 0 : pDocShell->PostPaintCell( maPos );
835 0 : EndRedo();
836 0 : }
837 :
838 0 : void ScUndoReplaceNote::Repeat( SfxRepeatTarget& /*rTarget*/ )
839 : {
840 0 : }
841 :
842 0 : bool ScUndoReplaceNote::CanRepeat( SfxRepeatTarget& /*rTarget*/ ) const
843 : {
844 0 : return false;
845 : }
846 :
847 6 : OUString ScUndoReplaceNote::GetComment() const
848 : {
849 : return ScGlobal::GetRscString( maNewData.mpCaption ?
850 6 : (maOldData.mpCaption ? STR_UNDO_EDITNOTE : STR_UNDO_INSERTNOTE) : STR_UNDO_DELETENOTE );
851 : }
852 :
853 0 : void ScUndoReplaceNote::DoInsertNote( const ScNoteData& rNoteData )
854 : {
855 0 : if( rNoteData.mpCaption )
856 : {
857 0 : ScDocument& rDoc = *pDocShell->GetDocument();
858 : OSL_ENSURE( !rDoc.GetNotes( maPos.Tab() )->findByAddress(maPos), "ScUndoReplaceNote::DoInsertNote - unexpected cell note" );
859 0 : ScPostIt* pNote = new ScPostIt( rDoc, maPos, rNoteData, false );
860 0 : rDoc.GetNotes(maPos.Tab())->insert( maPos, pNote );
861 : }
862 0 : }
863 :
864 0 : void ScUndoReplaceNote::DoRemoveNote( const ScNoteData& rNoteData )
865 : {
866 0 : if( rNoteData.mpCaption )
867 : {
868 0 : ScDocument& rDoc = *pDocShell->GetDocument();
869 : OSL_ENSURE( rDoc.GetNotes( maPos.Tab() )->findByAddress(maPos), "ScUndoReplaceNote::DoRemoveNote - missing cell note" );
870 0 : if( ScPostIt* pNote = rDoc.GetNotes(maPos.Tab())->ReleaseNote( maPos ) )
871 : {
872 : /* Forget pointer to caption object to suppress removing the
873 : caption object from the drawing layer while deleting pNote
874 : (removing the caption is done by a drawing undo action). */
875 0 : pNote->ForgetCaption();
876 0 : delete pNote;
877 : }
878 : }
879 0 : }
880 :
881 1 : ScUndoShowHideNote::ScUndoShowHideNote( ScDocShell& rDocShell, const ScAddress& rPos, bool bShow ) :
882 : ScSimpleUndo( &rDocShell ),
883 : maPos( rPos ),
884 1 : mbShown( bShow )
885 : {
886 1 : }
887 :
888 2 : ScUndoShowHideNote::~ScUndoShowHideNote()
889 : {
890 2 : }
891 :
892 0 : void ScUndoShowHideNote::Undo()
893 : {
894 0 : BeginUndo();
895 0 : if( ScPostIt* pNote = pDocShell->GetDocument()->GetNotes( maPos.Tab() )->findByAddress(maPos) )
896 0 : pNote->ShowCaption( maPos, !mbShown );
897 0 : EndUndo();
898 0 : }
899 :
900 0 : void ScUndoShowHideNote::Redo()
901 : {
902 0 : BeginRedo();
903 0 : if( ScPostIt* pNote = pDocShell->GetDocument()->GetNotes( maPos.Tab() )->findByAddress(maPos) )
904 0 : pNote->ShowCaption( maPos, mbShown );
905 0 : EndRedo();
906 0 : }
907 :
908 0 : void ScUndoShowHideNote::Repeat( SfxRepeatTarget& /*rTarget*/ )
909 : {
910 0 : }
911 :
912 0 : bool ScUndoShowHideNote::CanRepeat( SfxRepeatTarget& /*rTarget*/ ) const
913 : {
914 0 : return false;
915 : }
916 :
917 1 : OUString ScUndoShowHideNote::GetComment() const
918 : {
919 1 : return ScGlobal::GetRscString( mbShown ? STR_UNDO_SHOWNOTE : STR_UNDO_HIDENOTE );
920 : }
921 :
922 1 : ScUndoDetective::ScUndoDetective( ScDocShell* pNewDocShell,
923 : SdrUndoAction* pDraw, const ScDetOpData* pOperation,
924 : ScDetOpList* pUndoList ) :
925 : ScSimpleUndo( pNewDocShell ),
926 : pOldList ( pUndoList ),
927 : nAction ( 0 ),
928 1 : pDrawUndo ( pDraw )
929 : {
930 1 : bIsDelete = ( pOperation == NULL );
931 1 : if (!bIsDelete)
932 : {
933 1 : nAction = (sal_uInt16) pOperation->GetOperation();
934 1 : aPos = pOperation->GetPos();
935 : }
936 1 : }
937 :
938 3 : ScUndoDetective::~ScUndoDetective()
939 : {
940 1 : DeleteSdrUndoAction( pDrawUndo );
941 1 : delete pOldList;
942 2 : }
943 :
944 1 : OUString ScUndoDetective::GetComment() const
945 : {
946 1 : sal_uInt16 nId = STR_UNDO_DETDELALL;
947 1 : if ( !bIsDelete )
948 1 : switch ( (ScDetOpType) nAction )
949 : {
950 0 : case SCDETOP_ADDSUCC: nId = STR_UNDO_DETADDSUCC; break;
951 0 : case SCDETOP_DELSUCC: nId = STR_UNDO_DETDELSUCC; break;
952 1 : case SCDETOP_ADDPRED: nId = STR_UNDO_DETADDPRED; break;
953 0 : case SCDETOP_DELPRED: nId = STR_UNDO_DETDELPRED; break;
954 0 : case SCDETOP_ADDERROR: nId = STR_UNDO_DETADDERROR; break;
955 : }
956 :
957 1 : return ScGlobal::GetRscString( nId );
958 : }
959 :
960 0 : void ScUndoDetective::Undo()
961 : {
962 0 : BeginUndo();
963 :
964 0 : ScDocument* pDoc = pDocShell->GetDocument();
965 0 : DoSdrUndoAction(pDrawUndo, pDoc);
966 :
967 0 : if (bIsDelete)
968 : {
969 0 : if ( pOldList )
970 0 : pDoc->SetDetOpList( new ScDetOpList(*pOldList) );
971 : }
972 : else
973 : {
974 : // Remove entry from list
975 :
976 0 : ScDetOpList* pList = pDoc->GetDetOpList();
977 0 : if (pList && pList->Count())
978 : {
979 0 : ScDetOpDataVector& rVec = pList->GetDataVector();
980 0 : ScDetOpDataVector::iterator it = rVec.begin() + rVec.size() - 1;
981 0 : if ( it->GetOperation() == (ScDetOpType) nAction && it->GetPos() == aPos )
982 0 : rVec.erase( it);
983 : else
984 : {
985 : OSL_FAIL("Detective entry could not be found in list");
986 : }
987 : }
988 : }
989 :
990 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
991 0 : if (pViewShell)
992 0 : pViewShell->RecalcPPT(); //! use broadcast instead?
993 :
994 0 : EndUndo();
995 0 : }
996 :
997 0 : void ScUndoDetective::Redo()
998 : {
999 0 : BeginRedo();
1000 :
1001 0 : RedoSdrUndoAction(pDrawUndo);
1002 :
1003 0 : ScDocument* pDoc = pDocShell->GetDocument();
1004 :
1005 0 : if (bIsDelete)
1006 0 : pDoc->ClearDetectiveOperations();
1007 : else
1008 0 : pDoc->AddDetectiveOperation( ScDetOpData( aPos, (ScDetOpType) nAction ) );
1009 :
1010 0 : ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1011 0 : if (pViewShell)
1012 0 : pViewShell->RecalcPPT(); //! use broadcast instead?
1013 :
1014 0 : EndRedo();
1015 0 : }
1016 :
1017 0 : void ScUndoDetective::Repeat(SfxRepeatTarget& /* rTarget */)
1018 : {
1019 : // makes no sense
1020 0 : }
1021 :
1022 0 : bool ScUndoDetective::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1023 : {
1024 0 : return false;
1025 : }
1026 :
1027 31 : ScUndoRangeNames::ScUndoRangeNames( ScDocShell* pNewDocShell,
1028 : ScRangeName* pOld, ScRangeName* pNew, SCTAB nTab ) :
1029 : ScSimpleUndo( pNewDocShell ),
1030 : pOldRanges ( pOld ),
1031 : pNewRanges ( pNew ),
1032 31 : mnTab ( nTab )
1033 : {
1034 31 : }
1035 :
1036 93 : ScUndoRangeNames::~ScUndoRangeNames()
1037 : {
1038 31 : delete pOldRanges;
1039 31 : delete pNewRanges;
1040 62 : }
1041 :
1042 33 : OUString ScUndoRangeNames::GetComment() const
1043 : {
1044 33 : return ScGlobal::GetRscString( STR_UNDO_RANGENAMES );
1045 : }
1046 :
1047 0 : void ScUndoRangeNames::DoChange( sal_Bool bUndo )
1048 : {
1049 0 : ScDocument* pDoc = pDocShell->GetDocument();
1050 0 : pDoc->CompileNameFormula( sal_True ); // CreateFormulaString
1051 :
1052 0 : if ( bUndo )
1053 : {
1054 0 : if (mnTab >= 0)
1055 0 : pDoc->SetRangeName( mnTab, new ScRangeName( *pOldRanges ) );
1056 : else
1057 0 : pDoc->SetRangeName( new ScRangeName( *pOldRanges ) );
1058 : }
1059 : else
1060 : {
1061 0 : if (mnTab >= 0)
1062 0 : pDoc->SetRangeName( mnTab, new ScRangeName( *pNewRanges ) );
1063 : else
1064 0 : pDoc->SetRangeName( new ScRangeName( *pNewRanges ) );
1065 : }
1066 :
1067 0 : pDoc->CompileNameFormula( false ); // CompileFormulaString
1068 :
1069 0 : SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
1070 0 : }
1071 :
1072 0 : void ScUndoRangeNames::Undo()
1073 : {
1074 0 : BeginUndo();
1075 0 : DoChange( sal_True );
1076 0 : EndUndo();
1077 0 : }
1078 :
1079 0 : void ScUndoRangeNames::Redo()
1080 : {
1081 0 : BeginRedo();
1082 0 : DoChange( false );
1083 0 : EndRedo();
1084 0 : }
1085 :
1086 0 : void ScUndoRangeNames::Repeat(SfxRepeatTarget& /* rTarget */)
1087 : {
1088 : // makes no sense
1089 0 : }
1090 :
1091 2 : bool ScUndoRangeNames::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1092 : {
1093 2 : return false;
1094 93 : }
1095 :
1096 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|