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