1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "svx/sdr/properties/textproperties.hxx"
22 #include "editeng/outlobj.hxx"
25 #include "tableundo.hxx"
26 #include "svx/svdotable.hxx"
27 #include "tablerow.hxx"
28 #include "tablecolumn.hxx"
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::table
;
38 namespace sdr
{ namespace table
{
40 CellUndo::CellUndo( const SdrObjectWeakRef
& xObjRef
, const CellRef
& xCell
)
41 : SdrUndoAction( *xCell
->GetModel() )
46 if( mxCell
.is() && mxObjRef
.is() )
48 getDataFromCell( maUndoData
);
49 mxObjRef
->AddObjectUser( *this );
56 mxObjRef
->RemoveObjectUser( *this );
60 void CellUndo::dispose()
63 delete maUndoData
.mpProperties
;
64 maUndoData
.mpProperties
= 0;
65 delete maRedoData
.mpProperties
;
66 maRedoData
.mpProperties
= 0;
67 delete maUndoData
.mpOutlinerParaObject
;
68 maUndoData
.mpOutlinerParaObject
= 0;
69 delete maRedoData
.mpOutlinerParaObject
;
70 maRedoData
.mpOutlinerParaObject
= 0;
73 void CellUndo::ObjectInDestruction(const SdrObject
& )
80 if( mxCell
.is() && mbUndo
)
82 if( maRedoData
.mpProperties
== 0 )
83 getDataFromCell( maRedoData
);
85 setDataToCell( maUndoData
);
92 if( mxCell
.is() && !mbUndo
)
94 setDataToCell( maRedoData
);
99 bool CellUndo::Merge( SfxUndoAction
*pNextAction
)
101 CellUndo
* pNext
= dynamic_cast< CellUndo
* >( pNextAction
);
102 if( pNext
&& pNext
->mxCell
.get() == mxCell
.get() )
112 void CellUndo::setDataToCell( const Data
& rData
)
114 delete mxCell
->mpProperties
;
115 if( rData
.mpProperties
)
116 mxCell
->mpProperties
= Cell::CloneProperties( rData
.mpProperties
, *mxObjRef
.get(), *mxCell
.get() );
118 mxCell
->mpProperties
= 0;
120 if( rData
.mpOutlinerParaObject
)
121 mxCell
->SetOutlinerParaObject( new OutlinerParaObject(*rData
.mpOutlinerParaObject
) );
123 mxCell
->RemoveOutlinerParaObject();
125 mxCell
->msFormula
= rData
.msFormula
;
126 mxCell
->mfValue
= rData
.mfValue
;
127 mxCell
->mnError
= rData
.mnError
;
128 mxCell
->mbMerged
= rData
.mbMerged
;
129 mxCell
->mnRowSpan
= rData
.mnRowSpan
;
130 mxCell
->mnColSpan
= rData
.mnColSpan
;
134 // #i120201# ActionChanged is not enough, we need to trigger TableLayouter::UpdateBorderLayout()
135 // and this is done best using ReformatText() for table objects
136 mxObjRef
->ActionChanged();
137 mxObjRef
->NbcReformatText();
141 void CellUndo::getDataFromCell( Data
& rData
)
143 if( mxObjRef
.is() && mxCell
.is() )
145 if( mxCell
->mpProperties
)
146 rData
.mpProperties
= mxCell
->CloneProperties( *mxObjRef
.get(), *mxCell
.get());
148 if( mxCell
->GetOutlinerParaObject() )
149 rData
.mpOutlinerParaObject
= new OutlinerParaObject(*mxCell
->GetOutlinerParaObject());
151 rData
.mpOutlinerParaObject
= 0;
153 rData
.mnCellContentType
= mxCell
->mnCellContentType
;
155 rData
.msFormula
= mxCell
->msFormula
;
156 rData
.mfValue
= mxCell
->mfValue
;
157 rData
.mnError
= mxCell
->mnError
;
158 rData
.mbMerged
= mxCell
->mbMerged
;
159 rData
.mnRowSpan
= mxCell
->mnRowSpan
;
160 rData
.mnColSpan
= mxCell
->mnColSpan
;
165 // class InsertRowUndo : public SdrUndoAction
168 static void Dispose( RowVector
& rRows
)
170 RowVector::iterator
aIter( rRows
.begin() );
171 while( aIter
!= rRows
.end() )
172 (*aIter
++)->dispose();
177 InsertRowUndo::InsertRowUndo( const TableModelRef
& xTable
, sal_Int32 nIndex
, RowVector
& aNewRows
)
178 : SdrUndoAction( *xTable
->getSdrTableObj()->GetModel() )
183 maRows
.swap( aNewRows
);
188 InsertRowUndo::~InsertRowUndo()
196 void InsertRowUndo::Undo()
200 mxTable
->UndoInsertRows( mnIndex
, sal::static_int_cast
< sal_Int32
>( maRows
.size() ) );
207 void InsertRowUndo::Redo()
211 mxTable
->UndoRemoveRows( mnIndex
, maRows
);
217 // class RemoveRowUndo : public SdrUndoAction
220 RemoveRowUndo::RemoveRowUndo( const TableModelRef
& xTable
, sal_Int32 nIndex
, RowVector
& aRemovedRows
)
221 : SdrUndoAction( *xTable
->getSdrTableObj()->GetModel() )
226 maRows
.swap( aRemovedRows
);
231 RemoveRowUndo::~RemoveRowUndo()
239 void RemoveRowUndo::Undo()
243 mxTable
->UndoRemoveRows( mnIndex
, maRows
);
250 void RemoveRowUndo::Redo()
254 mxTable
->UndoInsertRows( mnIndex
, sal::static_int_cast
< sal_Int32
>( maRows
.size() ) );
260 // class InsertColUndo : public SdrUndoAction
263 static void Dispose( ColumnVector
& rCols
)
265 ColumnVector::iterator
aIter( rCols
.begin() );
266 while( aIter
!= rCols
.end() )
267 (*aIter
++)->dispose();
272 static void Dispose( CellVector
& rCells
)
274 CellVector::iterator
aIter( rCells
.begin() );
275 while( aIter
!= rCells
.end() )
276 (*aIter
++)->dispose();
281 InsertColUndo::InsertColUndo( const TableModelRef
& xTable
, sal_Int32 nIndex
, ColumnVector
& aNewCols
, CellVector
& aCells
)
282 : SdrUndoAction( *xTable
->getSdrTableObj()->GetModel() )
287 maColumns
.swap( aNewCols
);
288 maCells
.swap( aCells
);
293 InsertColUndo::~InsertColUndo()
297 Dispose( maColumns
);
304 void InsertColUndo::Undo()
308 mxTable
->UndoInsertColumns( mnIndex
, sal::static_int_cast
< sal_Int32
>( maColumns
.size() ) );
315 void InsertColUndo::Redo()
319 mxTable
->UndoRemoveColumns( mnIndex
, maColumns
, maCells
);
325 // class RemoveColUndo : public SdrUndoAction
328 RemoveColUndo::RemoveColUndo( const TableModelRef
& xTable
, sal_Int32 nIndex
, ColumnVector
& aNewCols
, CellVector
& aCells
)
329 : SdrUndoAction( *xTable
->getSdrTableObj()->GetModel() )
334 maColumns
.swap( aNewCols
);
335 maCells
.swap( aCells
);
340 RemoveColUndo::~RemoveColUndo()
344 Dispose( maColumns
);
351 void RemoveColUndo::Undo()
355 mxTable
->UndoRemoveColumns( mnIndex
, maColumns
, maCells
);
362 void RemoveColUndo::Redo()
366 mxTable
->UndoInsertColumns( mnIndex
, sal::static_int_cast
< sal_Int32
>( maColumns
.size() ) );
372 // class TableColumnUndo : public SdrUndoAction
375 TableColumnUndo::TableColumnUndo( const TableColumnRef
& xCol
)
376 : SdrUndoAction( *xCol
->mxTableModel
->getSdrTableObj()->GetModel() )
378 , mbHasRedoData( false )
380 getData( maUndoData
);
385 TableColumnUndo::~TableColumnUndo()
391 void TableColumnUndo::Undo()
395 getData( maRedoData
);
396 mbHasRedoData
= true;
398 setData( maUndoData
);
403 void TableColumnUndo::Redo()
405 setData( maRedoData
);
410 bool TableColumnUndo::Merge( SfxUndoAction
*pNextAction
)
412 TableColumnUndo
* pNext
= dynamic_cast< TableColumnUndo
* >( pNextAction
);
413 return pNext
&& pNext
->mxCol
== mxCol
;
418 void TableColumnUndo::setData( const Data
& rData
)
420 mxCol
->mnColumn
= rData
.mnColumn
;
421 mxCol
->mnWidth
= rData
.mnWidth
;
422 mxCol
->mbOptimalWidth
= rData
.mbOptimalWidth
;
423 mxCol
->mbIsVisible
= rData
.mbIsVisible
;
424 mxCol
->mbIsStartOfNewPage
= rData
.mbIsStartOfNewPage
;
425 mxCol
->maName
= rData
.maName
;
430 void TableColumnUndo::getData( Data
& rData
)
432 rData
.mnColumn
= mxCol
->mnColumn
;
433 rData
.mnWidth
= mxCol
->mnWidth
;
434 rData
.mbOptimalWidth
= mxCol
->mbOptimalWidth
;
435 rData
.mbIsVisible
= mxCol
->mbIsVisible
;
436 rData
.mbIsStartOfNewPage
= mxCol
->mbIsStartOfNewPage
;
437 rData
.maName
= mxCol
->maName
;
441 // class TableRowUndo : public SdrUndoAction
444 TableRowUndo::TableRowUndo( const TableRowRef
& xRow
)
445 : SdrUndoAction( *xRow
->mxTableModel
->getSdrTableObj()->GetModel() )
447 , mbHasRedoData( false )
449 getData( maUndoData
);
454 TableRowUndo::~TableRowUndo()
460 void TableRowUndo::Undo()
464 getData( maRedoData
);
465 mbHasRedoData
= true;
467 setData( maUndoData
);
472 void TableRowUndo::Redo()
474 setData( maRedoData
);
479 bool TableRowUndo::Merge( SfxUndoAction
*pNextAction
)
481 TableRowUndo
* pNext
= dynamic_cast< TableRowUndo
* >( pNextAction
);
482 return pNext
&& pNext
->mxRow
== mxRow
;
487 void TableRowUndo::setData( const Data
& rData
)
489 mxRow
->mnRow
= rData
.mnRow
;
490 mxRow
->mnHeight
= rData
.mnHeight
;
491 mxRow
->mbOptimalHeight
= rData
.mbOptimalHeight
;
492 mxRow
->mbIsVisible
= rData
.mbIsVisible
;
493 mxRow
->mbIsStartOfNewPage
= rData
.mbIsStartOfNewPage
;
494 mxRow
->maName
= rData
.maName
;
499 void TableRowUndo::getData( Data
& rData
)
501 rData
.mnRow
= mxRow
->mnRow
;
502 rData
.mnHeight
= mxRow
->mnHeight
;
503 rData
.mbOptimalHeight
= mxRow
->mbOptimalHeight
;
504 rData
.mbIsVisible
= mxRow
->mbIsVisible
;
505 rData
.mbIsStartOfNewPage
= mxRow
->mbIsStartOfNewPage
;
506 rData
.maName
= mxRow
->maName
;
511 TableStyleUndo::TableStyleUndo( const SdrTableObj
& rTableObj
)
512 : SdrUndoAction( *rTableObj
.GetModel() )
513 , mxObjRef( const_cast< sdr::table::SdrTableObj
*>( &rTableObj
) )
514 , mbHasRedoData(false)
516 getData( maUndoData
);
519 void TableStyleUndo::Undo()
523 getData( maRedoData
);
524 mbHasRedoData
= true;
526 setData( maUndoData
);
529 void TableStyleUndo::Redo()
531 setData( maRedoData
);
534 void TableStyleUndo::setData( const Data
& rData
)
536 SdrTableObj
* pTableObj
= dynamic_cast< SdrTableObj
* >( mxObjRef
.get() );
539 pTableObj
->setTableStyle( rData
.mxTableStyle
);
540 pTableObj
->setTableStyleSettings( rData
.maSettings
);
544 void TableStyleUndo::getData( Data
& rData
)
546 SdrTableObj
* pTableObj
= dynamic_cast< SdrTableObj
* >( mxObjRef
.get() );
549 rData
.maSettings
= pTableObj
->getTableStyleSettings();
550 rData
.mxTableStyle
= pTableObj
->getTableStyle();
556 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */