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 <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"
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::table
;
35 namespace sdr
{ namespace table
{
37 CellUndo::CellUndo( const tools::WeakReference
<SdrObject
>& xObjRef
, const CellRef
& xCell
)
38 : SdrUndoAction(xCell
->GetObject().getSdrModelFromSdrObject())
43 if( mxCell
.is() && mxObjRef
.is() )
45 getDataFromCell( maUndoData
);
46 mxObjRef
->AddObjectUser( *this );
53 mxObjRef
->RemoveObjectUser( *this );
57 void CellUndo::dispose()
60 delete maUndoData
.mpProperties
;
61 maUndoData
.mpProperties
= nullptr;
62 delete maRedoData
.mpProperties
;
63 maRedoData
.mpProperties
= nullptr;
64 delete maUndoData
.mpOutlinerParaObject
;
65 maUndoData
.mpOutlinerParaObject
= nullptr;
66 delete maRedoData
.mpOutlinerParaObject
;
67 maRedoData
.mpOutlinerParaObject
= nullptr;
70 void CellUndo::ObjectInDestruction(const SdrObject
& )
77 if( mxCell
.is() && mbUndo
)
79 if( maRedoData
.mpProperties
== nullptr )
80 getDataFromCell( maRedoData
);
82 setDataToCell( maUndoData
);
89 if( mxCell
.is() && !mbUndo
)
91 setDataToCell( maRedoData
);
96 bool CellUndo::Merge( SfxUndoAction
*pNextAction
)
98 CellUndo
* pNext
= dynamic_cast< CellUndo
* >( pNextAction
);
99 return pNext
&& pNext
->mxCell
.get() == mxCell
.get();
102 void CellUndo::setDataToCell( const Data
& rData
)
104 if( rData
.mpProperties
)
105 mxCell
->mpProperties
.reset(Cell::CloneProperties( rData
.mpProperties
, *mxObjRef
.get(), *mxCell
));
107 mxCell
->mpProperties
.reset();
109 if( rData
.mpOutlinerParaObject
)
110 mxCell
->SetOutlinerParaObject( std::make_unique
<OutlinerParaObject
>(*rData
.mpOutlinerParaObject
) );
112 mxCell
->RemoveOutlinerParaObject();
114 mxCell
->msFormula
= rData
.msFormula
;
115 mxCell
->mfValue
= rData
.mfValue
;
116 mxCell
->mnError
= rData
.mnError
;
117 mxCell
->mbMerged
= rData
.mbMerged
;
118 mxCell
->mnRowSpan
= rData
.mnRowSpan
;
119 mxCell
->mnColSpan
= rData
.mnColSpan
;
123 // #i120201# ActionChanged is not enough, we need to trigger TableLayouter::UpdateBorderLayout()
124 // and this is done best using ReformatText() for table objects
125 mxObjRef
->ActionChanged();
126 mxObjRef
->NbcReformatText();
130 void CellUndo::getDataFromCell( Data
& rData
)
132 if( mxObjRef
.is() && mxCell
.is() )
134 if( mxCell
->mpProperties
)
135 rData
.mpProperties
= mxCell
->CloneProperties( *mxObjRef
.get(), *mxCell
);
137 if( mxCell
->GetOutlinerParaObject() )
138 rData
.mpOutlinerParaObject
= new OutlinerParaObject(*mxCell
->GetOutlinerParaObject());
140 rData
.mpOutlinerParaObject
= nullptr;
142 rData
.msFormula
= mxCell
->msFormula
;
143 rData
.mfValue
= mxCell
->mfValue
;
144 rData
.mnError
= mxCell
->mnError
;
145 rData
.mbMerged
= mxCell
->mbMerged
;
146 rData
.mnRowSpan
= mxCell
->mnRowSpan
;
147 rData
.mnColSpan
= mxCell
->mnColSpan
;
152 // class InsertRowUndo : public SdrUndoAction
155 static void Dispose( RowVector
& rRows
)
157 for( auto& rpRow
: rRows
)
162 InsertRowUndo::InsertRowUndo( const TableModelRef
& xTable
, sal_Int32 nIndex
, RowVector
& aNewRows
)
163 : SdrUndoAction(xTable
->getSdrTableObj()->getSdrModelFromSdrObject())
168 maRows
.swap( aNewRows
);
172 InsertRowUndo::~InsertRowUndo()
179 void InsertRowUndo::Undo()
183 mxTable
->UndoInsertRows( mnIndex
, sal::static_int_cast
< sal_Int32
>( maRows
.size() ) );
189 void InsertRowUndo::Redo()
193 mxTable
->UndoRemoveRows( mnIndex
, maRows
);
199 // class RemoveRowUndo : public SdrUndoAction
202 RemoveRowUndo::RemoveRowUndo( const TableModelRef
& xTable
, sal_Int32 nIndex
, RowVector
& aRemovedRows
)
203 : SdrUndoAction(xTable
->getSdrTableObj()->getSdrModelFromSdrObject())
208 maRows
.swap( aRemovedRows
);
212 RemoveRowUndo::~RemoveRowUndo()
219 void RemoveRowUndo::Undo()
223 mxTable
->UndoRemoveRows( mnIndex
, maRows
);
229 void RemoveRowUndo::Redo()
233 mxTable
->UndoInsertRows( mnIndex
, sal::static_int_cast
< sal_Int32
>( maRows
.size() ) );
239 // class InsertColUndo : public SdrUndoAction
242 static void Dispose( ColumnVector
& rCols
)
244 for( auto& rpCol
: rCols
)
249 static void Dispose( CellVector
& rCells
)
251 for( auto& rpCell
: rCells
)
256 InsertColUndo::InsertColUndo( const TableModelRef
& xTable
, sal_Int32 nIndex
, ColumnVector
& aNewCols
, CellVector
& aCells
)
257 : SdrUndoAction(xTable
->getSdrTableObj()->getSdrModelFromSdrObject())
262 maColumns
.swap( aNewCols
);
263 maCells
.swap( aCells
);
267 InsertColUndo::~InsertColUndo()
271 Dispose( maColumns
);
277 void InsertColUndo::Undo()
281 mxTable
->UndoInsertColumns( mnIndex
, sal::static_int_cast
< sal_Int32
>( maColumns
.size() ) );
287 void InsertColUndo::Redo()
291 mxTable
->UndoRemoveColumns( mnIndex
, maColumns
, maCells
);
297 // class RemoveColUndo : public SdrUndoAction
300 RemoveColUndo::RemoveColUndo( const TableModelRef
& xTable
, sal_Int32 nIndex
, ColumnVector
& aNewCols
, CellVector
& aCells
)
301 : SdrUndoAction(xTable
->getSdrTableObj()->getSdrModelFromSdrObject())
306 maColumns
.swap( aNewCols
);
307 maCells
.swap( aCells
);
311 RemoveColUndo::~RemoveColUndo()
315 Dispose( maColumns
);
321 void RemoveColUndo::Undo()
325 mxTable
->UndoRemoveColumns( mnIndex
, maColumns
, maCells
);
331 void RemoveColUndo::Redo()
335 mxTable
->UndoInsertColumns( mnIndex
, sal::static_int_cast
< sal_Int32
>( maColumns
.size() ) );
341 // class TableColumnUndo : public SdrUndoAction
344 TableColumnUndo::TableColumnUndo( const TableColumnRef
& xCol
)
345 : SdrUndoAction(xCol
->mxTableModel
->getSdrTableObj()->getSdrModelFromSdrObject())
347 ,mbHasRedoData( false )
349 getData( maUndoData
);
353 TableColumnUndo::~TableColumnUndo()
358 void TableColumnUndo::Undo()
362 getData( maRedoData
);
363 mbHasRedoData
= true;
365 setData( maUndoData
);
369 void TableColumnUndo::Redo()
371 setData( maRedoData
);
375 bool TableColumnUndo::Merge( SfxUndoAction
*pNextAction
)
377 TableColumnUndo
* pNext
= dynamic_cast< TableColumnUndo
* >( pNextAction
);
378 return pNext
&& pNext
->mxCol
== mxCol
;
382 void TableColumnUndo::setData( const Data
& rData
)
384 mxCol
->mnColumn
= rData
.mnColumn
;
385 mxCol
->mnWidth
= rData
.mnWidth
;
386 mxCol
->mbOptimalWidth
= rData
.mbOptimalWidth
;
387 mxCol
->mbIsVisible
= rData
.mbIsVisible
;
388 mxCol
->mbIsStartOfNewPage
= rData
.mbIsStartOfNewPage
;
389 mxCol
->maName
= rData
.maName
;
391 // Trigger re-layout of the table.
392 mxCol
->getModel()->setModified(true);
396 void TableColumnUndo::getData( Data
& rData
)
398 rData
.mnColumn
= mxCol
->mnColumn
;
399 rData
.mnWidth
= mxCol
->mnWidth
;
400 rData
.mbOptimalWidth
= mxCol
->mbOptimalWidth
;
401 rData
.mbIsVisible
= mxCol
->mbIsVisible
;
402 rData
.mbIsStartOfNewPage
= mxCol
->mbIsStartOfNewPage
;
403 rData
.maName
= mxCol
->maName
;
407 // class TableRowUndo : public SdrUndoAction
410 TableRowUndo::TableRowUndo( const TableRowRef
& xRow
)
411 : SdrUndoAction(xRow
->mxTableModel
->getSdrTableObj()->getSdrModelFromSdrObject())
413 , mbHasRedoData( false )
415 getData( maUndoData
);
419 TableRowUndo::~TableRowUndo()
424 void TableRowUndo::Undo()
428 getData( maRedoData
);
429 mbHasRedoData
= true;
431 setData( maUndoData
);
435 void TableRowUndo::Redo()
437 setData( maRedoData
);
441 bool TableRowUndo::Merge( SfxUndoAction
*pNextAction
)
443 TableRowUndo
* pNext
= dynamic_cast< TableRowUndo
* >( pNextAction
);
444 return pNext
&& pNext
->mxRow
== mxRow
;
448 void TableRowUndo::setData( const Data
& rData
)
450 mxRow
->mnRow
= rData
.mnRow
;
451 mxRow
->mnHeight
= rData
.mnHeight
;
452 mxRow
->mbOptimalHeight
= rData
.mbOptimalHeight
;
453 mxRow
->mbIsVisible
= rData
.mbIsVisible
;
454 mxRow
->mbIsStartOfNewPage
= rData
.mbIsStartOfNewPage
;
455 mxRow
->maName
= rData
.maName
;
457 // Trigger re-layout of the table.
458 mxRow
->getModel()->setModified(true);
462 void TableRowUndo::getData( Data
& rData
)
464 rData
.mnRow
= mxRow
->mnRow
;
465 rData
.mnHeight
= mxRow
->mnHeight
;
466 rData
.mbOptimalHeight
= mxRow
->mbOptimalHeight
;
467 rData
.mbIsVisible
= mxRow
->mbIsVisible
;
468 rData
.mbIsStartOfNewPage
= mxRow
->mbIsStartOfNewPage
;
469 rData
.maName
= mxRow
->maName
;
473 TableStyleUndo::TableStyleUndo( const SdrTableObj
& rTableObj
)
474 : SdrUndoAction(rTableObj
.getSdrModelFromSdrObject())
475 ,mxObjRef( const_cast< sdr::table::SdrTableObj
*>( &rTableObj
) )
476 ,mbHasRedoData(false)
478 getData( maUndoData
);
481 void TableStyleUndo::Undo()
485 getData( maRedoData
);
486 mbHasRedoData
= true;
488 setData( maUndoData
);
491 void TableStyleUndo::Redo()
493 setData( maRedoData
);
496 void TableStyleUndo::setData( const Data
& rData
)
498 SdrTableObj
* pTableObj
= mxObjRef
.get();
501 pTableObj
->setTableStyle( rData
.mxTableStyle
);
502 pTableObj
->setTableStyleSettings( rData
.maSettings
);
506 void TableStyleUndo::getData( Data
& rData
)
508 SdrTableObj
* pTableObj
= mxObjRef
.get();
511 rData
.maSettings
= pTableObj
->getTableStyleSettings();
512 rData
.mxTableStyle
= pTableObj
->getTableStyle();
518 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */