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"
31 // -----------------------------------------------------------------------------
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::table
;
36 // -----------------------------------------------------------------------------
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 sal_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
;
133 mxObjRef
->ActionChanged();
136 void CellUndo::getDataFromCell( Data
& rData
)
138 if( mxObjRef
.is() && mxCell
.is() )
140 if( mxCell
->mpProperties
)
141 rData
.mpProperties
= mxCell
->CloneProperties( *mxObjRef
.get(), *mxCell
.get());
143 if( mxCell
->GetOutlinerParaObject() )
144 rData
.mpOutlinerParaObject
= new OutlinerParaObject(*mxCell
->GetOutlinerParaObject());
146 rData
.mpOutlinerParaObject
= 0;
148 rData
.mnCellContentType
= mxCell
->mnCellContentType
;
150 rData
.msFormula
= mxCell
->msFormula
;
151 rData
.mfValue
= mxCell
->mfValue
;
152 rData
.mnError
= mxCell
->mnError
;
153 rData
.mbMerged
= mxCell
->mbMerged
;
154 rData
.mnRowSpan
= mxCell
->mnRowSpan
;
155 rData
.mnColSpan
= mxCell
->mnColSpan
;
159 // -----------------------------------------------------------------------------
160 // class InsertRowUndo : public SdrUndoAction
161 // -----------------------------------------------------------------------------
163 static void Dispose( RowVector
& rRows
)
165 RowVector::iterator
aIter( rRows
.begin() );
166 while( aIter
!= rRows
.end() )
167 (*aIter
++)->dispose();
170 // -----------------------------------------------------------------------------
172 InsertRowUndo::InsertRowUndo( const TableModelRef
& xTable
, sal_Int32 nIndex
, RowVector
& aNewRows
)
173 : SdrUndoAction( *xTable
->getSdrTableObj()->GetModel() )
178 maRows
.swap( aNewRows
);
181 // -----------------------------------------------------------------------------
183 InsertRowUndo::~InsertRowUndo()
189 // -----------------------------------------------------------------------------
191 void InsertRowUndo::Undo()
195 mxTable
->UndoInsertRows( mnIndex
, sal::static_int_cast
< sal_Int32
>( maRows
.size() ) );
200 // -----------------------------------------------------------------------------
202 void InsertRowUndo::Redo()
206 mxTable
->UndoRemoveRows( mnIndex
, maRows
);
211 // -----------------------------------------------------------------------------
212 // class RemoveRowUndo : public SdrUndoAction
213 // -----------------------------------------------------------------------------
215 RemoveRowUndo::RemoveRowUndo( const TableModelRef
& xTable
, sal_Int32 nIndex
, RowVector
& aRemovedRows
)
216 : SdrUndoAction( *xTable
->getSdrTableObj()->GetModel() )
221 maRows
.swap( aRemovedRows
);
224 // -----------------------------------------------------------------------------
226 RemoveRowUndo::~RemoveRowUndo()
232 // -----------------------------------------------------------------------------
234 void RemoveRowUndo::Undo()
238 mxTable
->UndoRemoveRows( mnIndex
, maRows
);
243 // -----------------------------------------------------------------------------
245 void RemoveRowUndo::Redo()
249 mxTable
->UndoInsertRows( mnIndex
, sal::static_int_cast
< sal_Int32
>( maRows
.size() ) );
254 // -----------------------------------------------------------------------------
255 // class InsertColUndo : public SdrUndoAction
256 // -----------------------------------------------------------------------------
258 static void Dispose( ColumnVector
& rCols
)
260 ColumnVector::iterator
aIter( rCols
.begin() );
261 while( aIter
!= rCols
.end() )
262 (*aIter
++)->dispose();
265 // -----------------------------------------------------------------------------
267 static void Dispose( CellVector
& rCells
)
269 CellVector::iterator
aIter( rCells
.begin() );
270 while( aIter
!= rCells
.end() )
271 (*aIter
++)->dispose();
274 // -----------------------------------------------------------------------------
276 InsertColUndo::InsertColUndo( const TableModelRef
& xTable
, sal_Int32 nIndex
, ColumnVector
& aNewCols
, CellVector
& aCells
)
277 : SdrUndoAction( *xTable
->getSdrTableObj()->GetModel() )
282 maColumns
.swap( aNewCols
);
283 maCells
.swap( aCells
);
286 // -----------------------------------------------------------------------------
288 InsertColUndo::~InsertColUndo()
292 Dispose( maColumns
);
297 // -----------------------------------------------------------------------------
299 void InsertColUndo::Undo()
303 mxTable
->UndoInsertColumns( mnIndex
, sal::static_int_cast
< sal_Int32
>( maColumns
.size() ) );
308 // -----------------------------------------------------------------------------
310 void InsertColUndo::Redo()
314 mxTable
->UndoRemoveColumns( mnIndex
, maColumns
, maCells
);
319 // -----------------------------------------------------------------------------
320 // class RemoveColUndo : public SdrUndoAction
321 // -----------------------------------------------------------------------------
323 RemoveColUndo::RemoveColUndo( const TableModelRef
& xTable
, sal_Int32 nIndex
, ColumnVector
& aNewCols
, CellVector
& aCells
)
324 : SdrUndoAction( *xTable
->getSdrTableObj()->GetModel() )
329 maColumns
.swap( aNewCols
);
330 maCells
.swap( aCells
);
333 // -----------------------------------------------------------------------------
335 RemoveColUndo::~RemoveColUndo()
339 Dispose( maColumns
);
344 // -----------------------------------------------------------------------------
346 void RemoveColUndo::Undo()
350 mxTable
->UndoRemoveColumns( mnIndex
, maColumns
, maCells
);
355 // -----------------------------------------------------------------------------
357 void RemoveColUndo::Redo()
361 mxTable
->UndoInsertColumns( mnIndex
, sal::static_int_cast
< sal_Int32
>( maColumns
.size() ) );
366 // -----------------------------------------------------------------------------
367 // class TableColumnUndo : public SdrUndoAction
368 // -----------------------------------------------------------------------------
370 TableColumnUndo::TableColumnUndo( const TableColumnRef
& xCol
)
371 : SdrUndoAction( *xCol
->mxTableModel
->getSdrTableObj()->GetModel() )
373 , mbHasRedoData( false )
375 getData( maUndoData
);
378 // -----------------------------------------------------------------------------
380 TableColumnUndo::~TableColumnUndo()
384 // -----------------------------------------------------------------------------
386 void TableColumnUndo::Undo()
390 getData( maRedoData
);
391 mbHasRedoData
= true;
393 setData( maUndoData
);
396 // -----------------------------------------------------------------------------
398 void TableColumnUndo::Redo()
400 setData( maRedoData
);
403 // -----------------------------------------------------------------------------
405 sal_Bool
TableColumnUndo::Merge( SfxUndoAction
*pNextAction
)
407 TableColumnUndo
* pNext
= dynamic_cast< TableColumnUndo
* >( pNextAction
);
408 return pNext
&& pNext
->mxCol
== mxCol
;
411 // -----------------------------------------------------------------------------
413 void TableColumnUndo::setData( const Data
& rData
)
415 mxCol
->mnColumn
= rData
.mnColumn
;
416 mxCol
->mnWidth
= rData
.mnWidth
;
417 mxCol
->mbOptimalWidth
= rData
.mbOptimalWidth
;
418 mxCol
->mbIsVisible
= rData
.mbIsVisible
;
419 mxCol
->mbIsStartOfNewPage
= rData
.mbIsStartOfNewPage
;
420 mxCol
->maName
= rData
.maName
;
423 // -----------------------------------------------------------------------------
425 void TableColumnUndo::getData( Data
& rData
)
427 rData
.mnColumn
= mxCol
->mnColumn
;
428 rData
.mnWidth
= mxCol
->mnWidth
;
429 rData
.mbOptimalWidth
= mxCol
->mbOptimalWidth
;
430 rData
.mbIsVisible
= mxCol
->mbIsVisible
;
431 rData
.mbIsStartOfNewPage
= mxCol
->mbIsStartOfNewPage
;
432 rData
.maName
= mxCol
->maName
;
435 // -----------------------------------------------------------------------------
436 // class TableRowUndo : public SdrUndoAction
437 // -----------------------------------------------------------------------------
439 TableRowUndo::TableRowUndo( const TableRowRef
& xRow
)
440 : SdrUndoAction( *xRow
->mxTableModel
->getSdrTableObj()->GetModel() )
442 , mbHasRedoData( false )
444 getData( maUndoData
);
447 // -----------------------------------------------------------------------------
449 TableRowUndo::~TableRowUndo()
453 // -----------------------------------------------------------------------------
455 void TableRowUndo::Undo()
459 getData( maRedoData
);
460 mbHasRedoData
= true;
462 setData( maUndoData
);
465 // -----------------------------------------------------------------------------
467 void TableRowUndo::Redo()
469 setData( maRedoData
);
472 // -----------------------------------------------------------------------------
474 sal_Bool
TableRowUndo::Merge( SfxUndoAction
*pNextAction
)
476 TableRowUndo
* pNext
= dynamic_cast< TableRowUndo
* >( pNextAction
);
477 return pNext
&& pNext
->mxRow
== mxRow
;
480 // -----------------------------------------------------------------------------
482 void TableRowUndo::setData( const Data
& rData
)
484 mxRow
->mnRow
= rData
.mnRow
;
485 mxRow
->mnHeight
= rData
.mnHeight
;
486 mxRow
->mbOptimalHeight
= rData
.mbOptimalHeight
;
487 mxRow
->mbIsVisible
= rData
.mbIsVisible
;
488 mxRow
->mbIsStartOfNewPage
= rData
.mbIsStartOfNewPage
;
489 mxRow
->maName
= rData
.maName
;
492 // -----------------------------------------------------------------------------
494 void TableRowUndo::getData( Data
& rData
)
496 rData
.mnRow
= mxRow
->mnRow
;
497 rData
.mnHeight
= mxRow
->mnHeight
;
498 rData
.mbOptimalHeight
= mxRow
->mbOptimalHeight
;
499 rData
.mbIsVisible
= mxRow
->mbIsVisible
;
500 rData
.mbIsStartOfNewPage
= mxRow
->mbIsStartOfNewPage
;
501 rData
.maName
= mxRow
->maName
;
504 // -----------------------------------------------------------------------------
506 TableStyleUndo::TableStyleUndo( const SdrTableObj
& rTableObj
)
507 : SdrUndoAction( *rTableObj
.GetModel() )
508 , mxObjRef( const_cast< sdr::table::SdrTableObj
*>( &rTableObj
) )
510 getData( maUndoData
);
513 void TableStyleUndo::Undo()
517 getData( maRedoData
);
518 mbHasRedoData
= true;
520 setData( maUndoData
);
523 void TableStyleUndo::Redo()
525 setData( maRedoData
);
528 void TableStyleUndo::setData( const Data
& rData
)
530 SdrTableObj
* pTableObj
= dynamic_cast< SdrTableObj
* >( mxObjRef
.get() );
533 pTableObj
->setTableStyle( rData
.mxTableStyle
);
534 pTableObj
->setTableStyleSettings( rData
.maSettings
);
538 void TableStyleUndo::getData( Data
& rData
)
540 SdrTableObj
* pTableObj
= dynamic_cast< SdrTableObj
* >( mxObjRef
.get() );
543 rData
.maSettings
= pTableObj
->getTableStyleSettings();
544 rData
.mxTableStyle
= pTableObj
->getTableStyle();
550 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */