LibreOffice Module svx (master) 1
tableundo.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
22#include <editeng/outlobj.hxx>
23
24#include <cell.hxx>
25#include "tableundo.hxx"
26#include <svx/svdotable.hxx>
27#include "tablerow.hxx"
28#include "tablecolumn.hxx"
29
30
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::table;
33
34
35namespace sdr::table {
36
37CellUndo::CellUndo( SdrObject* pObjRef, const CellRef& xCell )
38: SdrUndoAction(xCell->GetObject().getSdrModelFromSdrObject())
39 ,mxObjRef( pObjRef )
40 ,mxCell( xCell )
41 ,mbUndo( true )
42{
43 if( mxCell.is() && pObjRef )
44 {
46 pObjRef->AddObjectUser( *this );
47 }
48}
49
51{
52 if( auto pObj = mxObjRef.get() )
53 pObj->RemoveObjectUser( *this );
54 dispose();
55}
56
58{
59 mxCell.clear();
64}
65
67{
68 dispose();
69}
70
72{
73 if( mxCell.is() && mbUndo )
74 {
77
79 mbUndo = false;
80 }
81}
82
84{
85 if( mxCell.is() && !mbUndo )
86 {
88 mbUndo = true;
89 }
90}
91
92bool CellUndo::Merge( SfxUndoAction *pNextAction )
93{
94 CellUndo* pNext = dynamic_cast< CellUndo* >( pNextAction );
95 return pNext && pNext->mxCell.get() == mxCell.get();
96}
97
98void CellUndo::setDataToCell( const Data& rData )
99{
100 if( rData.mxProperties )
101 mxCell->mpProperties.reset(new properties::CellProperties( *rData.mxProperties, *mxObjRef.get(), mxCell.get() ));
102 else
103 mxCell->mpProperties.reset();
104
105 if( rData.mpOutlinerParaObject )
106 mxCell->SetOutlinerParaObject( *rData.mpOutlinerParaObject );
107 else
108 mxCell->RemoveOutlinerParaObject();
109
110 mxCell->msFormula = rData.msFormula;
111 mxCell->mfValue = rData.mfValue;
112 mxCell->mnError = rData.mnError;
113 mxCell->mbMerged = rData.mbMerged;
114 mxCell->mnRowSpan = rData.mnRowSpan;
115 mxCell->mnColSpan = rData.mnColSpan;
116
117 if(auto pObj = mxObjRef.get())
118 {
119 // #i120201# ActionChanged is not enough, we need to trigger TableLayouter::UpdateBorderLayout()
120 // and this is done best using ReformatText() for table objects
121 pObj->ActionChanged();
122 pObj->NbcReformatText();
123 }
124}
125
127{
128 if( !(mxObjRef.get().is() && mxCell.is()) )
129 return;
130
131 if( mxCell->mpProperties )
132 rData.mxProperties.reset( mxCell->CloneProperties( *mxObjRef.get(), *mxCell) );
133
134 if( mxCell->GetOutlinerParaObject() )
135 rData.mpOutlinerParaObject = *mxCell->GetOutlinerParaObject();
136 else
138
139 rData.msFormula = mxCell->msFormula;
140 rData.mfValue = mxCell->mfValue;
141 rData.mnError = mxCell->mnError;
142 rData.mbMerged = mxCell->mbMerged;
143 rData.mnRowSpan = mxCell->mnRowSpan;
144 rData.mnColSpan = mxCell->mnColSpan;
145}
146
147
148// class InsertRowUndo : public SdrUndoAction
149
150
151static void Dispose( RowVector& rRows )
152{
153 for( auto& rpRow : rRows )
154 rpRow->dispose();
155}
156
157
158InsertRowUndo::InsertRowUndo( const TableModelRef& xTable, sal_Int32 nIndex, RowVector& aNewRows )
159: SdrUndoAction(xTable->getSdrTableObj()->getSdrModelFromSdrObject())
160 ,mxTable( xTable )
161 ,mnIndex( nIndex )
162 ,mbUndo( true )
163{
164 maRows.swap( aNewRows );
165}
166
167
169{
170 if( !mbUndo )
171 Dispose( maRows );
172}
173
174
176{
177 if( mxTable.is() )
178 {
179 mxTable->UndoInsertRows( mnIndex, sal::static_int_cast< sal_Int32 >( maRows.size() ) );
180 mbUndo = false;
181 }
182}
183
184
186{
187 if( mxTable.is() )
188 {
189 mxTable->UndoRemoveRows( mnIndex, maRows );
190 mbUndo = true;
191 }
192}
193
194
195// class RemoveRowUndo : public SdrUndoAction
196
197
198RemoveRowUndo::RemoveRowUndo( const TableModelRef& xTable, sal_Int32 nIndex, RowVector& aRemovedRows )
199: SdrUndoAction(xTable->getSdrTableObj()->getSdrModelFromSdrObject())
200 ,mxTable( xTable )
201 ,mnIndex( nIndex )
202 ,mbUndo( true )
203{
204 maRows.swap( aRemovedRows );
205}
206
207
209{
210 if( mbUndo )
211 Dispose( maRows );
212}
213
214
216{
217 if( mxTable.is() )
218 {
219 mxTable->UndoRemoveRows( mnIndex, maRows );
220 mbUndo = false;
221 }
222}
223
224
226{
227 if( mxTable.is() )
228 {
229 mxTable->UndoInsertRows( mnIndex, sal::static_int_cast< sal_Int32 >( maRows.size() ) );
230 mbUndo = true;
231 }
232}
233
234
235// class InsertColUndo : public SdrUndoAction
236
237
238static void Dispose( ColumnVector& rCols )
239{
240 for( auto& rpCol : rCols )
241 rpCol->dispose();
242}
243
244
245static void Dispose( CellVector& rCells )
246{
247 for( auto& rpCell : rCells )
248 rpCell->dispose();
249}
250
251
252InsertColUndo::InsertColUndo( const TableModelRef& xTable, sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells )
253: SdrUndoAction(xTable->getSdrTableObj()->getSdrModelFromSdrObject())
254 ,mxTable( xTable )
255 ,mnIndex( nIndex )
256 ,mbUndo( true )
257{
258 maColumns.swap( aNewCols );
259 maCells.swap( aCells );
260}
261
262
264{
265 if( !mbUndo )
266 {
268 Dispose( maCells );
269 }
270}
271
272
274{
275 if( mxTable.is() )
276 {
277 mxTable->UndoInsertColumns( mnIndex, sal::static_int_cast< sal_Int32 >( maColumns.size() ) );
278 mbUndo = false;
279 }
280}
281
282
284{
285 if( mxTable.is() )
286 {
287 mxTable->UndoRemoveColumns( mnIndex, maColumns, maCells );
288 mbUndo = true;
289 }
290}
291
292
293// class RemoveColUndo : public SdrUndoAction
294
295
296RemoveColUndo::RemoveColUndo( const TableModelRef& xTable, sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells )
297: SdrUndoAction(xTable->getSdrTableObj()->getSdrModelFromSdrObject())
298 ,mxTable( xTable )
299 ,mnIndex( nIndex )
300 ,mbUndo( true )
301{
302 maColumns.swap( aNewCols );
303 maCells.swap( aCells );
304}
305
306
308{
309 if( mbUndo )
310 {
312 Dispose( maCells );
313 }
314}
315
316
318{
319 if( mxTable.is() )
320 {
321 mxTable->UndoRemoveColumns( mnIndex, maColumns, maCells );
322 mbUndo = false;
323 }
324}
325
326
328{
329 if( mxTable.is() )
330 {
331 mxTable->UndoInsertColumns( mnIndex, sal::static_int_cast< sal_Int32 >( maColumns.size() ) );
332 mbUndo = true;
333 }
334}
335
336
337// class TableColumnUndo : public SdrUndoAction
338
339
341: SdrUndoAction(xCol->mxTableModel->getSdrTableObj()->getSdrModelFromSdrObject())
342 ,mxCol( xCol )
343 ,mbHasRedoData( false )
344{
346}
347
348
350{
351}
352
353
355{
356 if( !mbHasRedoData )
357 {
359 mbHasRedoData = true;
360 }
362}
363
364
366{
368}
369
370
372{
373 TableColumnUndo* pNext = dynamic_cast< TableColumnUndo* >( pNextAction );
374 return pNext && pNext->mxCol == mxCol;
375}
376
377
378void TableColumnUndo::setData( const Data& rData )
379{
380 mxCol->mnColumn = rData.mnColumn;
381 mxCol->mnWidth = rData.mnWidth;
382 mxCol->mbOptimalWidth = rData.mbOptimalWidth;
383 mxCol->mbIsVisible = rData.mbIsVisible;
384 mxCol->mbIsStartOfNewPage = rData.mbIsStartOfNewPage;
385 mxCol->maName = rData.maName;
386
387 // Trigger re-layout of the table.
388 mxCol->getModel()->setModified(true);
389}
390
391
393{
394 rData.mnColumn = mxCol->mnColumn;
395 rData.mnWidth = mxCol->mnWidth;
396 rData.mbOptimalWidth = mxCol->mbOptimalWidth;
397 rData.mbIsVisible = mxCol->mbIsVisible;
398 rData.mbIsStartOfNewPage = mxCol->mbIsStartOfNewPage;
399 rData.maName = mxCol->maName;
400}
401
402
403// class TableRowUndo : public SdrUndoAction
404
405
407: SdrUndoAction(xRow->mxTableModel->getSdrTableObj()->getSdrModelFromSdrObject())
408 , mxRow( xRow )
409 , mbHasRedoData( false )
410{
412}
413
414
416{
417}
418
419
421{
422 if( !mbHasRedoData )
423 {
425 mbHasRedoData = true;
426 }
428}
429
430
432{
434}
435
436
438{
439 TableRowUndo* pNext = dynamic_cast< TableRowUndo* >( pNextAction );
440 return pNext && pNext->mxRow == mxRow;
441}
442
443
444void TableRowUndo::setData( const Data& rData )
445{
446 mxRow->mnRow = rData.mnRow;
447 mxRow->mnHeight = rData.mnHeight;
448 mxRow->mbOptimalHeight = rData.mbOptimalHeight;
449 mxRow->mbIsVisible = rData.mbIsVisible;
450 mxRow->mbIsStartOfNewPage = rData.mbIsStartOfNewPage;
451 mxRow->maName = rData.maName;
452
453 // Trigger re-layout of the table.
454 mxRow->getModel()->setModified(true);
455 }
456
457
459{
460 rData.mnRow = mxRow->mnRow;
461 rData.mnHeight = mxRow->mnHeight;
462 rData.mbOptimalHeight = mxRow->mbOptimalHeight;
463 rData.mbIsVisible = mxRow->mbIsVisible;
464 rData.mbIsStartOfNewPage = mxRow->mbIsStartOfNewPage;
465 rData.maName = mxRow->maName;
466}
467
468
470: SdrUndoAction(rTableObj.getSdrModelFromSdrObject())
471 ,mxObjRef( const_cast< sdr::table::SdrTableObj*>( &rTableObj ) )
472 ,mbHasRedoData(false)
473{
475}
476
478{
479 if( !mbHasRedoData )
480 {
482 mbHasRedoData = true;
483 }
485}
486
488{
490}
491
492void TableStyleUndo::setData( const Data& rData )
493{
494 rtl::Reference<SdrTableObj> pTableObj = mxObjRef.get();
495 if( pTableObj )
496 {
497 pTableObj->setTableStyle( rData.mxTableStyle );
498 pTableObj->setTableStyleSettings( rData.maSettings );
499 }
500}
501
503{
504 rtl::Reference<SdrTableObj> pTableObj = mxObjRef.get();
505 if( pTableObj )
506 {
507 rData.maSettings = pTableObj->getTableStyleSettings();
508 rData.mxTableStyle = pTableObj->getTableStyle();
509 }
510}
511
512}
513
514/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Abstract DrawObject.
Definition: svdobj.hxx:260
void AddObjectUser(sdr::ObjectUser &rNewUser)
Definition: svdobj.cxx:238
Abstract base class (ABC) for all UndoActions of DrawingEngine.
Definition: svdundo.hxx:61
void setDataToCell(const Data &rData)
Definition: tableundo.cxx:98
CellUndo(SdrObject *pObj, const CellRef &xCell)
Definition: tableundo.cxx:37
unotools::WeakReference< SdrObject > mxObjRef
Definition: tableundo.hxx:81
void getDataFromCell(Data &rData)
Definition: tableundo.cxx:126
virtual bool Merge(SfxUndoAction *pNextAction) override
Definition: tableundo.cxx:92
virtual void Undo() override
Definition: tableundo.cxx:71
virtual void ObjectInDestruction(const SdrObject &rObject) override
Definition: tableundo.cxx:66
virtual ~CellUndo() override
Definition: tableundo.cxx:50
virtual void Redo() override
Definition: tableundo.cxx:83
virtual void Redo() override
Definition: tableundo.cxx:283
InsertColUndo(const TableModelRef &xTable, sal_Int32 nIndex, ColumnVector &aNewCols, CellVector &aCells)
Definition: tableundo.cxx:252
virtual ~InsertColUndo() override
Definition: tableundo.cxx:263
virtual void Undo() override
Definition: tableundo.cxx:273
virtual void Redo() override
Definition: tableundo.cxx:185
virtual ~InsertRowUndo() override
Definition: tableundo.cxx:168
InsertRowUndo(const TableModelRef &xTable, sal_Int32 nIndex, RowVector &aNewRows)
Definition: tableundo.cxx:158
virtual void Undo() override
Definition: tableundo.cxx:175
virtual void Undo() override
Definition: tableundo.cxx:317
RemoveColUndo(const TableModelRef &xTable, sal_Int32 nIndex, ColumnVector &aNewCols, CellVector &aCells)
Definition: tableundo.cxx:296
virtual ~RemoveColUndo() override
Definition: tableundo.cxx:307
virtual void Redo() override
Definition: tableundo.cxx:327
virtual void Redo() override
Definition: tableundo.cxx:225
virtual ~RemoveRowUndo() override
Definition: tableundo.cxx:208
RemoveRowUndo(const TableModelRef &xTable, sal_Int32 nIndex, RowVector &aRemovedRows)
Definition: tableundo.cxx:198
virtual void Undo() override
Definition: tableundo.cxx:215
TableColumnUndo(const TableColumnRef &xCol)
Definition: tableundo.cxx:340
virtual void Redo() override
Definition: tableundo.cxx:365
void getData(Data &rData)
Definition: tableundo.cxx:392
virtual void Undo() override
Definition: tableundo.cxx:354
virtual bool Merge(SfxUndoAction *pNextAction) override
Definition: tableundo.cxx:371
void setData(const Data &rData)
Definition: tableundo.cxx:378
virtual ~TableColumnUndo() override
Definition: tableundo.cxx:349
virtual void Redo() override
Definition: tableundo.cxx:431
virtual bool Merge(SfxUndoAction *pNextAction) override
Definition: tableundo.cxx:437
TableRowUndo(const TableRowRef &xRow)
Definition: tableundo.cxx:406
void getData(Data &rData)
Definition: tableundo.cxx:458
void setData(const Data &rData)
Definition: tableundo.cxx:444
virtual ~TableRowUndo() override
Definition: tableundo.cxx:415
virtual void Undo() override
Definition: tableundo.cxx:420
virtual void Undo() override
Definition: tableundo.cxx:477
virtual void Redo() override
Definition: tableundo.cxx:487
unotools::WeakReference< SdrTableObj > mxObjRef
Definition: tableundo.hxx:238
void setData(const Data &rData)
Definition: tableundo.cxx:492
void getData(Data &rData)
Definition: tableundo.cxx:502
TableStyleUndo(const SdrTableObj &rTableObj)
Definition: tableundo.cxx:469
rtl::Reference< interface_type > SAL_CALL get() const
virtual css::uno::Reference< css::embed::XEmbeddedObject > GetObject() override
sal_Int32 nIndex
@ table
std::vector< CellRef > CellVector
Definition: celltypes.hxx:38
std::vector< TableColumnRef > ColumnVector
Definition: celltypes.hxx:40
std::vector< TableRowRef > RowVector
Definition: celltypes.hxx:39
static void Dispose(RowVector &rRows)
Definition: tableundo.cxx:151
std::unique_ptr< sdr::properties::CellProperties > mxProperties
Definition: tableundo.hxx:58
std::optional< OutlinerParaObject > mpOutlinerParaObject
Definition: tableundo.hxx:59
css::uno::Reference< css::container::XIndexAccess > mxTableStyle
Definition: tableundo.hxx:243
TableStyleSettings maSettings
Definition: tableundo.hxx:242
sal_uInt32 mnIndex