1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svx.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "svx/sdr/properties/textproperties.hxx" 32*cdf0e10cSrcweir #include "editeng/outlobj.hxx" 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include "cell.hxx" 35*cdf0e10cSrcweir #include "tableundo.hxx" 36*cdf0e10cSrcweir #include "svx/svdotable.hxx" 37*cdf0e10cSrcweir #include "tablerow.hxx" 38*cdf0e10cSrcweir #include "tablecolumn.hxx" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir using ::rtl::OUString; 44*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 45*cdf0e10cSrcweir using namespace ::com::sun::star::table; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir namespace sdr { namespace table { 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir CellUndo::CellUndo( const SdrObjectWeakRef& xObjRef, const CellRef& xCell ) 52*cdf0e10cSrcweir : SdrUndoAction( *xCell->GetModel() ) 53*cdf0e10cSrcweir , mxObjRef( xObjRef ) 54*cdf0e10cSrcweir , mxCell( xCell ) 55*cdf0e10cSrcweir , mbUndo( true ) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir if( mxCell.is() && mxObjRef.is() ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir getDataFromCell( maUndoData ); 60*cdf0e10cSrcweir mxObjRef->AddObjectUser( *this ); 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir CellUndo::~CellUndo() 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir if( mxObjRef.is() ) 67*cdf0e10cSrcweir mxObjRef->RemoveObjectUser( *this ); 68*cdf0e10cSrcweir dispose(); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir void CellUndo::dispose() 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir mxCell.clear(); 74*cdf0e10cSrcweir delete maUndoData.mpProperties; 75*cdf0e10cSrcweir maUndoData.mpProperties = 0; 76*cdf0e10cSrcweir delete maRedoData.mpProperties; 77*cdf0e10cSrcweir maRedoData.mpProperties = 0; 78*cdf0e10cSrcweir delete maUndoData.mpOutlinerParaObject; 79*cdf0e10cSrcweir maUndoData.mpOutlinerParaObject = 0; 80*cdf0e10cSrcweir delete maRedoData.mpOutlinerParaObject; 81*cdf0e10cSrcweir maRedoData.mpOutlinerParaObject = 0; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir void CellUndo::ObjectInDestruction(const SdrObject& ) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir dispose(); 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir void CellUndo::Undo() 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir if( mxCell.is() && mbUndo ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir if( maRedoData.mpProperties == 0 ) 94*cdf0e10cSrcweir getDataFromCell( maRedoData ); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir setDataToCell( maUndoData ); 97*cdf0e10cSrcweir mbUndo = false; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir void CellUndo::Redo() 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir if( mxCell.is() && !mbUndo ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir setDataToCell( maRedoData ); 106*cdf0e10cSrcweir mbUndo = true; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir sal_Bool CellUndo::Merge( SfxUndoAction *pNextAction ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir CellUndo* pNext = dynamic_cast< CellUndo* >( pNextAction ); 113*cdf0e10cSrcweir if( pNext && pNext->mxCell.get() == mxCell.get() ) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir return sal_True; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir else 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir return sal_False; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir void CellUndo::setDataToCell( const Data& rData ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir delete mxCell->mpProperties; 126*cdf0e10cSrcweir if( rData.mpProperties ) 127*cdf0e10cSrcweir mxCell->mpProperties = Cell::CloneProperties( rData.mpProperties, *mxObjRef.get(), *mxCell.get() ); 128*cdf0e10cSrcweir else 129*cdf0e10cSrcweir mxCell->mpProperties = 0; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir if( rData.mpOutlinerParaObject ) 132*cdf0e10cSrcweir mxCell->SetOutlinerParaObject( new OutlinerParaObject(*rData.mpOutlinerParaObject) ); 133*cdf0e10cSrcweir else 134*cdf0e10cSrcweir mxCell->RemoveOutlinerParaObject(); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir mxCell->msFormula = rData.msFormula; 137*cdf0e10cSrcweir mxCell->mfValue = rData.mfValue; 138*cdf0e10cSrcweir mxCell->mnError = rData.mnError; 139*cdf0e10cSrcweir mxCell->mbMerged = rData.mbMerged; 140*cdf0e10cSrcweir mxCell->mnRowSpan = rData.mnRowSpan; 141*cdf0e10cSrcweir mxCell->mnColSpan = rData.mnColSpan; 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir if( mxObjRef.is() ) 144*cdf0e10cSrcweir mxObjRef->ActionChanged(); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir void CellUndo::getDataFromCell( Data& rData ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir if( mxObjRef.is() && mxCell.is() ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir if( mxCell->mpProperties ) 152*cdf0e10cSrcweir rData.mpProperties = mxCell->CloneProperties( *mxObjRef.get(), *mxCell.get()); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir if( mxCell->GetOutlinerParaObject() ) 155*cdf0e10cSrcweir rData.mpOutlinerParaObject = new OutlinerParaObject(*mxCell->GetOutlinerParaObject()); 156*cdf0e10cSrcweir else 157*cdf0e10cSrcweir rData.mpOutlinerParaObject = 0; 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir rData.mnCellContentType = mxCell->mnCellContentType; 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir rData.msFormula = mxCell->msFormula; 162*cdf0e10cSrcweir rData.mfValue = mxCell->mfValue; 163*cdf0e10cSrcweir rData.mnError = mxCell->mnError; 164*cdf0e10cSrcweir rData.mbMerged = mxCell->mbMerged; 165*cdf0e10cSrcweir rData.mnRowSpan = mxCell->mnRowSpan; 166*cdf0e10cSrcweir rData.mnColSpan = mxCell->mnColSpan; 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 171*cdf0e10cSrcweir // class InsertRowUndo : public SdrUndoAction 172*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir static void Dispose( RowVector& rRows ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir RowVector::iterator aIter( rRows.begin() ); 177*cdf0e10cSrcweir while( aIter != rRows.end() ) 178*cdf0e10cSrcweir (*aIter++)->dispose(); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir InsertRowUndo::InsertRowUndo( const TableModelRef& xTable, sal_Int32 nIndex, RowVector& aNewRows ) 184*cdf0e10cSrcweir : SdrUndoAction( *xTable->getSdrTableObj()->GetModel() ) 185*cdf0e10cSrcweir , mxTable( xTable ) 186*cdf0e10cSrcweir , mnIndex( nIndex ) 187*cdf0e10cSrcweir , mbUndo( true ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir maRows.swap( aNewRows ); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir InsertRowUndo::~InsertRowUndo() 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir if( !mbUndo ) 197*cdf0e10cSrcweir Dispose( maRows ); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir void InsertRowUndo::Undo() 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir if( mxTable.is() ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir mxTable->UndoInsertRows( mnIndex, sal::static_int_cast< sal_Int32 >( maRows.size() ) ); 207*cdf0e10cSrcweir mbUndo = false; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir void InsertRowUndo::Redo() 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir if( mxTable.is() ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir mxTable->UndoRemoveRows( mnIndex, maRows ); 218*cdf0e10cSrcweir mbUndo = true; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 223*cdf0e10cSrcweir // class RemoveRowUndo : public SdrUndoAction 224*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir RemoveRowUndo::RemoveRowUndo( const TableModelRef& xTable, sal_Int32 nIndex, RowVector& aRemovedRows ) 227*cdf0e10cSrcweir : SdrUndoAction( *xTable->getSdrTableObj()->GetModel() ) 228*cdf0e10cSrcweir , mxTable( xTable ) 229*cdf0e10cSrcweir , mnIndex( nIndex ) 230*cdf0e10cSrcweir , mbUndo( true ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir maRows.swap( aRemovedRows ); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir RemoveRowUndo::~RemoveRowUndo() 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir if( mbUndo ) 240*cdf0e10cSrcweir Dispose( maRows ); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir void RemoveRowUndo::Undo() 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir if( mxTable.is() ) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir mxTable->UndoRemoveRows( mnIndex, maRows ); 250*cdf0e10cSrcweir mbUndo = false; 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir void RemoveRowUndo::Redo() 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir if( mxTable.is() ) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir mxTable->UndoInsertRows( mnIndex, sal::static_int_cast< sal_Int32 >( maRows.size() ) ); 261*cdf0e10cSrcweir mbUndo = true; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 266*cdf0e10cSrcweir // class InsertColUndo : public SdrUndoAction 267*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir static void Dispose( ColumnVector& rCols ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir ColumnVector::iterator aIter( rCols.begin() ); 272*cdf0e10cSrcweir while( aIter != rCols.end() ) 273*cdf0e10cSrcweir (*aIter++)->dispose(); 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir static void Dispose( CellVector& rCells ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir CellVector::iterator aIter( rCells.begin() ); 281*cdf0e10cSrcweir while( aIter != rCells.end() ) 282*cdf0e10cSrcweir (*aIter++)->dispose(); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir InsertColUndo::InsertColUndo( const TableModelRef& xTable, sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells ) 288*cdf0e10cSrcweir : SdrUndoAction( *xTable->getSdrTableObj()->GetModel() ) 289*cdf0e10cSrcweir , mxTable( xTable ) 290*cdf0e10cSrcweir , mnIndex( nIndex ) 291*cdf0e10cSrcweir , mbUndo( true ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir maColumns.swap( aNewCols ); 294*cdf0e10cSrcweir maCells.swap( aCells ); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir InsertColUndo::~InsertColUndo() 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir if( !mbUndo ) 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir Dispose( maColumns ); 304*cdf0e10cSrcweir Dispose( maCells ); 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir void InsertColUndo::Undo() 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir if( mxTable.is() ) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir mxTable->UndoInsertColumns( mnIndex, sal::static_int_cast< sal_Int32 >( maColumns.size() ) ); 315*cdf0e10cSrcweir mbUndo = false; 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir void InsertColUndo::Redo() 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir if( mxTable.is() ) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir mxTable->UndoRemoveColumns( mnIndex, maColumns, maCells ); 326*cdf0e10cSrcweir mbUndo = true; 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 331*cdf0e10cSrcweir // class RemoveColUndo : public SdrUndoAction 332*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir RemoveColUndo::RemoveColUndo( const TableModelRef& xTable, sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells ) 335*cdf0e10cSrcweir : SdrUndoAction( *xTable->getSdrTableObj()->GetModel() ) 336*cdf0e10cSrcweir , mxTable( xTable ) 337*cdf0e10cSrcweir , mnIndex( nIndex ) 338*cdf0e10cSrcweir , mbUndo( true ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir maColumns.swap( aNewCols ); 341*cdf0e10cSrcweir maCells.swap( aCells ); 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir RemoveColUndo::~RemoveColUndo() 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir if( mbUndo ) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir Dispose( maColumns ); 351*cdf0e10cSrcweir Dispose( maCells ); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir void RemoveColUndo::Undo() 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir if( mxTable.is() ) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir mxTable->UndoRemoveColumns( mnIndex, maColumns, maCells ); 362*cdf0e10cSrcweir mbUndo = false; 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir void RemoveColUndo::Redo() 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir if( mxTable.is() ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir mxTable->UndoInsertColumns( mnIndex, sal::static_int_cast< sal_Int32 >( maColumns.size() ) ); 373*cdf0e10cSrcweir mbUndo = true; 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 378*cdf0e10cSrcweir // class TableColumnUndo : public SdrUndoAction 379*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir TableColumnUndo::TableColumnUndo( const TableColumnRef& xCol ) 382*cdf0e10cSrcweir : SdrUndoAction( *xCol->mxTableModel->getSdrTableObj()->GetModel() ) 383*cdf0e10cSrcweir , mxCol( xCol ) 384*cdf0e10cSrcweir , mbHasRedoData( false ) 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir getData( maUndoData ); 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir TableColumnUndo::~TableColumnUndo() 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir void TableColumnUndo::Undo() 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir if( !mbHasRedoData ) 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir getData( maRedoData ); 402*cdf0e10cSrcweir mbHasRedoData = true; 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir setData( maUndoData ); 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir void TableColumnUndo::Redo() 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir setData( maRedoData ); 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir sal_Bool TableColumnUndo::Merge( SfxUndoAction *pNextAction ) 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir TableColumnUndo* pNext = dynamic_cast< TableColumnUndo* >( pNextAction ); 419*cdf0e10cSrcweir return pNext && pNext->mxCol == mxCol; 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir void TableColumnUndo::setData( const Data& rData ) 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir mxCol->mnColumn = rData.mnColumn; 427*cdf0e10cSrcweir mxCol->mnWidth = rData.mnWidth; 428*cdf0e10cSrcweir mxCol->mbOptimalWidth = rData.mbOptimalWidth; 429*cdf0e10cSrcweir mxCol->mbIsVisible = rData.mbIsVisible; 430*cdf0e10cSrcweir mxCol->mbIsStartOfNewPage = rData.mbIsStartOfNewPage; 431*cdf0e10cSrcweir mxCol->maName = rData.maName; 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir void TableColumnUndo::getData( Data& rData ) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir rData.mnColumn = mxCol->mnColumn; 439*cdf0e10cSrcweir rData.mnWidth = mxCol->mnWidth; 440*cdf0e10cSrcweir rData.mbOptimalWidth = mxCol->mbOptimalWidth; 441*cdf0e10cSrcweir rData.mbIsVisible = mxCol->mbIsVisible; 442*cdf0e10cSrcweir rData.mbIsStartOfNewPage = mxCol->mbIsStartOfNewPage; 443*cdf0e10cSrcweir rData.maName = mxCol->maName; 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 447*cdf0e10cSrcweir // class TableRowUndo : public SdrUndoAction 448*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir TableRowUndo::TableRowUndo( const TableRowRef& xRow ) 451*cdf0e10cSrcweir : SdrUndoAction( *xRow->mxTableModel->getSdrTableObj()->GetModel() ) 452*cdf0e10cSrcweir , mxRow( xRow ) 453*cdf0e10cSrcweir , mbHasRedoData( false ) 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir getData( maUndoData ); 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir TableRowUndo::~TableRowUndo() 461*cdf0e10cSrcweir { 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir void TableRowUndo::Undo() 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir if( !mbHasRedoData ) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir getData( maRedoData ); 471*cdf0e10cSrcweir mbHasRedoData = true; 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir setData( maUndoData ); 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir void TableRowUndo::Redo() 479*cdf0e10cSrcweir { 480*cdf0e10cSrcweir setData( maRedoData ); 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir sal_Bool TableRowUndo::Merge( SfxUndoAction *pNextAction ) 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir TableRowUndo* pNext = dynamic_cast< TableRowUndo* >( pNextAction ); 488*cdf0e10cSrcweir return pNext && pNext->mxRow == mxRow; 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir void TableRowUndo::setData( const Data& rData ) 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir mxRow->mnRow = rData.mnRow; 496*cdf0e10cSrcweir mxRow->mnHeight = rData.mnHeight; 497*cdf0e10cSrcweir mxRow->mbOptimalHeight = rData.mbOptimalHeight; 498*cdf0e10cSrcweir mxRow->mbIsVisible = rData.mbIsVisible; 499*cdf0e10cSrcweir mxRow->mbIsStartOfNewPage = rData.mbIsStartOfNewPage; 500*cdf0e10cSrcweir mxRow->maName = rData.maName; 501*cdf0e10cSrcweir } 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir void TableRowUndo::getData( Data& rData ) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir rData.mnRow = mxRow->mnRow; 508*cdf0e10cSrcweir rData.mnHeight = mxRow->mnHeight; 509*cdf0e10cSrcweir rData.mbOptimalHeight = mxRow->mbOptimalHeight; 510*cdf0e10cSrcweir rData.mbIsVisible = mxRow->mbIsVisible; 511*cdf0e10cSrcweir rData.mbIsStartOfNewPage = mxRow->mbIsStartOfNewPage; 512*cdf0e10cSrcweir rData.maName = mxRow->maName; 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir TableStyleUndo::TableStyleUndo( const SdrTableObj& rTableObj ) 518*cdf0e10cSrcweir : SdrUndoAction( *rTableObj.GetModel() ) 519*cdf0e10cSrcweir , mxObjRef( const_cast< sdr::table::SdrTableObj*>( &rTableObj ) ) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir getData( maUndoData ); 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir void TableStyleUndo::Undo() 525*cdf0e10cSrcweir { 526*cdf0e10cSrcweir if( !mbHasRedoData ) 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir getData( maRedoData ); 529*cdf0e10cSrcweir mbHasRedoData = true; 530*cdf0e10cSrcweir } 531*cdf0e10cSrcweir setData( maUndoData ); 532*cdf0e10cSrcweir } 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir void TableStyleUndo::Redo() 535*cdf0e10cSrcweir { 536*cdf0e10cSrcweir setData( maRedoData ); 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir void TableStyleUndo::setData( const Data& rData ) 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir SdrTableObj* pTableObj = dynamic_cast< SdrTableObj* >( mxObjRef.get() ); 542*cdf0e10cSrcweir if( pTableObj ) 543*cdf0e10cSrcweir { 544*cdf0e10cSrcweir pTableObj->setTableStyle( rData.mxTableStyle ); 545*cdf0e10cSrcweir pTableObj->setTableStyleSettings( rData.maSettings ); 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir void TableStyleUndo::getData( Data& rData ) 550*cdf0e10cSrcweir { 551*cdf0e10cSrcweir SdrTableObj* pTableObj = dynamic_cast< SdrTableObj* >( mxObjRef.get() ); 552*cdf0e10cSrcweir if( pTableObj ) 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir rData.maSettings = pTableObj->getTableStyleSettings(); 555*cdf0e10cSrcweir rData.mxTableStyle = pTableObj->getTableStyle(); 556*cdf0e10cSrcweir } 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir } } 560