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