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 : #include <UndoDraw.hxx>
21 :
22 : #include <rtl/string.h>
23 :
24 : #include <svx/svdogrp.hxx>
25 : #include <svx/svdundo.hxx>
26 : #include <svx/svdpage.hxx>
27 : #include <svx/svdmark.hxx>
28 :
29 : #include <hintids.hxx>
30 : #include <hints.hxx>
31 : #include <fmtanchr.hxx>
32 : #include <fmtflcnt.hxx>
33 : #include <txtflcnt.hxx>
34 : #include <frmfmt.hxx>
35 : #include <doc.hxx>
36 : #include <IDocumentUndoRedo.hxx>
37 : #include <IDocumentLayoutAccess.hxx>
38 : #include <docary.hxx>
39 : #include <frame.hxx>
40 : #include <swundo.hxx>
41 : #include <pam.hxx>
42 : #include <ndtxt.hxx>
43 : #include <UndoCore.hxx>
44 : #include <dcontact.hxx>
45 : #include <dview.hxx>
46 : #include <rootfrm.hxx>
47 : #include <viewsh.hxx>
48 :
49 : struct SwUndoGroupObjImpl
50 : {
51 : SwDrawFrameFormat* pFormat;
52 : SdrObject* pObj;
53 : sal_uLong nNodeIdx;
54 : };
55 :
56 : // Draw-Objecte
57 :
58 11300 : IMPL_LINK( SwDoc, AddDrawUndo, SdrUndoAction *, pUndo )
59 : {
60 : #if OSL_DEBUG_LEVEL > 1
61 : SAL_INFO("sw.core", "Id: " << pUndo->GetId() << "Comment: " << pUndo->GetComment());
62 : #endif
63 :
64 11300 : if (GetIDocumentUndoRedo().DoesUndo() &&
65 5650 : GetIDocumentUndoRedo().DoesDrawUndo())
66 : {
67 5650 : const SdrMarkList* pMarkList = 0;
68 5650 : SwViewShell* pSh = getIDocumentLayoutAccess().GetCurrentViewShell();
69 5650 : if( pSh && pSh->HasDrawView() )
70 5650 : pMarkList = &pSh->GetDrawView()->GetMarkedObjectList();
71 :
72 5650 : GetIDocumentUndoRedo().AppendUndo( new SwSdrUndo(pUndo, pMarkList) );
73 : }
74 : else
75 0 : delete pUndo;
76 5650 : return 0;
77 : }
78 :
79 5650 : SwSdrUndo::SwSdrUndo( SdrUndoAction* pUndo, const SdrMarkList* pMrkLst )
80 5650 : : SwUndo( UNDO_DRAWUNDO ), pSdrUndo( pUndo )
81 : {
82 5650 : if( pMrkLst && pMrkLst->GetMarkCount() )
83 1 : pMarkList = new SdrMarkList( *pMrkLst );
84 : else
85 5649 : pMarkList = 0;
86 5650 : }
87 :
88 16950 : SwSdrUndo::~SwSdrUndo()
89 : {
90 5650 : delete pSdrUndo;
91 5650 : delete pMarkList;
92 11300 : }
93 :
94 0 : void SwSdrUndo::UndoImpl(::sw::UndoRedoContext & rContext)
95 : {
96 0 : pSdrUndo->Undo();
97 0 : rContext.SetSelections(0, pMarkList);
98 0 : }
99 :
100 0 : void SwSdrUndo::RedoImpl(::sw::UndoRedoContext & rContext)
101 : {
102 0 : pSdrUndo->Redo();
103 0 : rContext.SetSelections(0, pMarkList);
104 0 : }
105 :
106 5710 : OUString SwSdrUndo::GetComment() const
107 : {
108 5710 : return pSdrUndo->GetComment();
109 : }
110 :
111 1 : static void lcl_SendRemoveToUno( SwFormat& rFormat )
112 : {
113 1 : SwPtrMsgPoolItem aMsgHint( RES_REMOVE_UNO_OBJECT, &rFormat );
114 1 : rFormat.ModifyNotification( &aMsgHint, &aMsgHint );
115 1 : }
116 :
117 1 : static void lcl_SaveAnchor( SwFrameFormat* pFormat, sal_uLong& rNodePos )
118 : {
119 1 : const SwFormatAnchor& rAnchor = pFormat->GetAnchor();
120 2 : if ((FLY_AT_PARA == rAnchor.GetAnchorId()) ||
121 0 : (FLY_AT_CHAR == rAnchor.GetAnchorId()) ||
122 1 : (FLY_AT_FLY == rAnchor.GetAnchorId()) ||
123 0 : (FLY_AS_CHAR == rAnchor.GetAnchorId()))
124 : {
125 1 : rNodePos = rAnchor.GetContentAnchor()->nNode.GetIndex();
126 1 : sal_Int32 nContentPos = 0;
127 :
128 1 : if (FLY_AS_CHAR == rAnchor.GetAnchorId())
129 : {
130 0 : nContentPos = rAnchor.GetContentAnchor()->nContent.GetIndex();
131 :
132 : // destroy TextAttribute
133 0 : SwTextNode *pTextNd = pFormat->GetDoc()->GetNodes()[ rNodePos ]->GetTextNode();
134 : OSL_ENSURE( pTextNd, "No text node found!" );
135 : SwTextFlyCnt* pAttr = static_cast<SwTextFlyCnt*>(
136 0 : pTextNd->GetTextAttrForCharAt( nContentPos, RES_TXTATR_FLYCNT ));
137 : // attribute still in text node, delete
138 0 : if( pAttr && pAttr->GetFlyCnt().GetFrameFormat() == pFormat )
139 : {
140 : // just set pointer to 0, don't delete
141 0 : const_cast<SwFormatFlyCnt&>(pAttr->GetFlyCnt()).SetFlyFormat();
142 0 : SwIndex aIdx( pTextNd, nContentPos );
143 0 : pTextNd->EraseText( aIdx, 1 );
144 : }
145 : }
146 1 : else if (FLY_AT_CHAR == rAnchor.GetAnchorId())
147 : {
148 0 : nContentPos = rAnchor.GetContentAnchor()->nContent.GetIndex();
149 : }
150 :
151 1 : pFormat->SetFormatAttr( SwFormatAnchor( rAnchor.GetAnchorId(), nContentPos ) );
152 : }
153 1 : }
154 :
155 0 : static void lcl_RestoreAnchor( SwFrameFormat* pFormat, sal_uLong& rNodePos )
156 : {
157 0 : const SwFormatAnchor& rAnchor = pFormat->GetAnchor();
158 0 : if ((FLY_AT_PARA == rAnchor.GetAnchorId()) ||
159 0 : (FLY_AT_CHAR == rAnchor.GetAnchorId()) ||
160 0 : (FLY_AT_FLY == rAnchor.GetAnchorId()) ||
161 0 : (FLY_AS_CHAR == rAnchor.GetAnchorId()))
162 : {
163 0 : const sal_Int32 nContentPos = rAnchor.GetPageNum();
164 0 : SwNodes& rNds = pFormat->GetDoc()->GetNodes();
165 :
166 0 : SwNodeIndex aIdx( rNds, rNodePos );
167 0 : SwPosition aPos( aIdx );
168 :
169 0 : SwFormatAnchor aTmp( rAnchor.GetAnchorId() );
170 0 : if ((FLY_AS_CHAR == rAnchor.GetAnchorId()) ||
171 0 : (FLY_AT_CHAR == rAnchor.GetAnchorId()))
172 : {
173 0 : aPos.nContent.Assign( aIdx.GetNode().GetContentNode(), nContentPos );
174 : }
175 0 : aTmp.SetAnchor( &aPos );
176 0 : pFormat->SetFormatAttr( aTmp );
177 :
178 0 : if (FLY_AS_CHAR == rAnchor.GetAnchorId())
179 : {
180 0 : SwTextNode *pTextNd = aIdx.GetNode().GetTextNode();
181 : OSL_ENSURE( pTextNd, "no Text Node" );
182 0 : SwFormatFlyCnt aFormat( pFormat );
183 0 : pTextNd->InsertItem( aFormat, nContentPos, nContentPos );
184 0 : }
185 : }
186 0 : }
187 :
188 0 : SwUndoDrawGroup::SwUndoDrawGroup( sal_uInt16 nCnt )
189 0 : : SwUndo( UNDO_DRAWGROUP ), nSize( nCnt + 1 ), bDelFormat( true )
190 : {
191 0 : pObjArr = new SwUndoGroupObjImpl[ nSize ];
192 0 : }
193 :
194 0 : SwUndoDrawGroup::~SwUndoDrawGroup()
195 : {
196 0 : if( bDelFormat )
197 : {
198 0 : SwUndoGroupObjImpl* pTmp = pObjArr + 1;
199 0 : for( sal_uInt16 n = 1; n < nSize; ++n, ++pTmp )
200 0 : delete pTmp->pFormat;
201 : }
202 : else
203 0 : delete pObjArr->pFormat;
204 :
205 0 : delete [] pObjArr;
206 0 : }
207 :
208 0 : void SwUndoDrawGroup::UndoImpl(::sw::UndoRedoContext &)
209 : {
210 0 : bDelFormat = false;
211 :
212 : // save group object
213 0 : SwDrawFrameFormat* pFormat = pObjArr->pFormat;
214 0 : SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(pFormat->FindContactObj());
215 0 : SdrObject* pObj = pDrawContact->GetMaster();
216 0 : pObjArr->pObj = pObj;
217 :
218 : // object will destroy itself
219 0 : pDrawContact->Changed( *pObj, SDRUSERCALL_DELETE, pObj->GetLastBoundRect() );
220 0 : pObj->SetUserCall( 0 );
221 :
222 0 : ::lcl_SaveAnchor( pFormat, pObjArr->nNodeIdx );
223 :
224 : // notify UNO objects to decouple
225 0 : ::lcl_SendRemoveToUno( *pFormat );
226 :
227 : // remove from array
228 0 : SwDoc* pDoc = pFormat->GetDoc();
229 0 : SwFrameFormats& rFlyFormats = *pDoc->GetSpzFrameFormats();
230 0 : rFlyFormats.erase( std::find( rFlyFormats.begin(), rFlyFormats.end(), pFormat ));
231 :
232 0 : for( sal_uInt16 n = 1; n < nSize; ++n )
233 : {
234 0 : SwUndoGroupObjImpl& rSave = *( pObjArr + n );
235 :
236 0 : ::lcl_RestoreAnchor( rSave.pFormat, rSave.nNodeIdx );
237 0 : rFlyFormats.push_back( rSave.pFormat );
238 :
239 0 : pObj = rSave.pObj;
240 :
241 0 : SwDrawContact *pContact = new SwDrawContact( rSave.pFormat, pObj );
242 0 : pContact->ConnectToLayout();
243 : // #i45718# - follow-up of #i35635# move object to visible layer
244 0 : pContact->MoveObjToVisibleLayer( pObj );
245 : // #i45952# - notify that position attributes are already set
246 : OSL_ENSURE( rSave.pFormat->ISA(SwDrawFrameFormat),
247 : "<SwUndoDrawGroup::Undo(..)> - wrong type of frame format for drawing object" );
248 0 : if ( rSave.pFormat->ISA(SwDrawFrameFormat) )
249 : {
250 0 : static_cast<SwDrawFrameFormat*>(rSave.pFormat)->PosAttrSet();
251 : }
252 : }
253 0 : }
254 :
255 0 : void SwUndoDrawGroup::RedoImpl(::sw::UndoRedoContext &)
256 : {
257 0 : bDelFormat = true;
258 :
259 : // remove from array
260 0 : SwDoc* pDoc = pObjArr->pFormat->GetDoc();
261 0 : SwFrameFormats& rFlyFormats = *pDoc->GetSpzFrameFormats();
262 :
263 0 : for( sal_uInt16 n = 1; n < nSize; ++n )
264 : {
265 0 : SwUndoGroupObjImpl& rSave = *( pObjArr + n );
266 :
267 0 : SdrObject* pObj = rSave.pObj;
268 :
269 0 : SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
270 :
271 : // object will destroy itself
272 0 : pContact->Changed( *pObj, SDRUSERCALL_DELETE, pObj->GetLastBoundRect() );
273 0 : pObj->SetUserCall( 0 );
274 :
275 0 : ::lcl_SaveAnchor( rSave.pFormat, rSave.nNodeIdx );
276 :
277 : // notify UNO objects to decouple
278 0 : ::lcl_SendRemoveToUno( *rSave.pFormat );
279 :
280 0 : rFlyFormats.erase( std::find( rFlyFormats.begin(), rFlyFormats.end(), rSave.pFormat ));
281 : }
282 :
283 : // re-insert group object
284 0 : ::lcl_RestoreAnchor( pObjArr->pFormat, pObjArr->nNodeIdx );
285 0 : rFlyFormats.push_back( pObjArr->pFormat );
286 :
287 0 : SwDrawContact *pContact = new SwDrawContact( pObjArr->pFormat, pObjArr->pObj );
288 : // #i26791# - correction: connect object to layout
289 0 : pContact->ConnectToLayout();
290 : // #i45718# - follow-up of #i35635# move object to visible layer
291 0 : pContact->MoveObjToVisibleLayer( pObjArr->pObj );
292 : // #i45952# - notify that position attributes are already set
293 : OSL_ENSURE( pObjArr->pFormat->ISA(SwDrawFrameFormat),
294 : "<SwUndoDrawGroup::Undo(..)> - wrong type of frame format for drawing object" );
295 0 : if ( pObjArr->pFormat->ISA(SwDrawFrameFormat) )
296 : {
297 0 : static_cast<SwDrawFrameFormat*>(pObjArr->pFormat)->PosAttrSet();
298 : }
299 0 : }
300 :
301 0 : void SwUndoDrawGroup::AddObj( sal_uInt16 nPos, SwDrawFrameFormat* pFormat, SdrObject* pObj )
302 : {
303 0 : SwUndoGroupObjImpl& rSave = *( pObjArr + nPos + 1 );
304 0 : rSave.pObj = pObj;
305 0 : rSave.pFormat = pFormat;
306 0 : ::lcl_SaveAnchor( pFormat, rSave.nNodeIdx );
307 :
308 : // notify UNO objects to decouple
309 0 : ::lcl_SendRemoveToUno( *pFormat );
310 :
311 : // remove from array
312 0 : SwFrameFormats& rFlyFormats = *pFormat->GetDoc()->GetSpzFrameFormats();
313 0 : rFlyFormats.erase( std::find( rFlyFormats.begin(), rFlyFormats.end(), pFormat ));
314 0 : }
315 :
316 0 : void SwUndoDrawGroup::SetGroupFormat( SwDrawFrameFormat* pFormat )
317 : {
318 0 : pObjArr->pObj = 0;
319 0 : pObjArr->pFormat = pFormat;
320 0 : }
321 :
322 0 : SwUndoDrawUnGroup::SwUndoDrawUnGroup( SdrObjGroup* pObj )
323 0 : : SwUndo( UNDO_DRAWUNGROUP ), bDelFormat( false )
324 : {
325 0 : nSize = (sal_uInt16)pObj->GetSubList()->GetObjCount() + 1;
326 0 : pObjArr = new SwUndoGroupObjImpl[ nSize ];
327 :
328 0 : SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
329 0 : SwDrawFrameFormat* pFormat = static_cast<SwDrawFrameFormat*>(pContact->GetFormat());
330 :
331 0 : pObjArr->pObj = pObj;
332 0 : pObjArr->pFormat = pFormat;
333 :
334 : // object will destroy itself
335 0 : pContact->Changed( *pObj, SDRUSERCALL_DELETE, pObj->GetLastBoundRect() );
336 0 : pObj->SetUserCall( 0 );
337 :
338 0 : ::lcl_SaveAnchor( pFormat, pObjArr->nNodeIdx );
339 :
340 : // notify UNO objects to decouple
341 0 : ::lcl_SendRemoveToUno( *pFormat );
342 :
343 : // remove from array
344 0 : SwFrameFormats& rFlyFormats = *pFormat->GetDoc()->GetSpzFrameFormats();
345 0 : rFlyFormats.erase( std::find( rFlyFormats.begin(), rFlyFormats.end(), pFormat ));
346 0 : }
347 :
348 0 : SwUndoDrawUnGroup::~SwUndoDrawUnGroup()
349 : {
350 0 : if( bDelFormat )
351 : {
352 0 : SwUndoGroupObjImpl* pTmp = pObjArr + 1;
353 0 : for( sal_uInt16 n = 1; n < nSize; ++n, ++pTmp )
354 0 : delete pTmp->pFormat;
355 : }
356 : else
357 0 : delete pObjArr->pFormat;
358 :
359 0 : delete [] pObjArr;
360 0 : }
361 :
362 0 : void SwUndoDrawUnGroup::UndoImpl(::sw::UndoRedoContext & rContext)
363 : {
364 0 : bDelFormat = true;
365 :
366 0 : SwDoc *const pDoc = & rContext.GetDoc();
367 0 : SwFrameFormats& rFlyFormats = *pDoc->GetSpzFrameFormats();
368 :
369 : // remove from array
370 0 : for( sal_uInt16 n = 1; n < nSize; ++n )
371 : {
372 0 : SwUndoGroupObjImpl& rSave = *( pObjArr + n );
373 :
374 0 : ::lcl_SaveAnchor( rSave.pFormat, rSave.nNodeIdx );
375 :
376 : // notify UNO objects to decouple
377 0 : ::lcl_SendRemoveToUno( *rSave.pFormat );
378 :
379 0 : rFlyFormats.erase( std::find( rFlyFormats.begin(), rFlyFormats.end(), rSave.pFormat ));
380 : }
381 :
382 : // re-insert group object
383 0 : ::lcl_RestoreAnchor( pObjArr->pFormat, pObjArr->nNodeIdx );
384 0 : rFlyFormats.push_back( pObjArr->pFormat );
385 :
386 0 : SwDrawContact *pContact = new SwDrawContact( pObjArr->pFormat, pObjArr->pObj );
387 0 : pContact->ConnectToLayout();
388 : // #i45718# - follow-up of #i35635# move object to visible layer
389 0 : pContact->MoveObjToVisibleLayer( pObjArr->pObj );
390 : // #i45952# - notify that position attributes are already set
391 : OSL_ENSURE( pObjArr->pFormat->ISA(SwDrawFrameFormat),
392 : "<SwUndoDrawGroup::Undo(..)> - wrong type of frame format for drawing object" );
393 0 : if ( pObjArr->pFormat->ISA(SwDrawFrameFormat) )
394 : {
395 0 : static_cast<SwDrawFrameFormat*>(pObjArr->pFormat)->PosAttrSet();
396 : }
397 0 : }
398 :
399 0 : void SwUndoDrawUnGroup::RedoImpl(::sw::UndoRedoContext &)
400 : {
401 0 : bDelFormat = false;
402 :
403 : // save group object
404 0 : SwDrawFrameFormat* pFormat = pObjArr->pFormat;
405 0 : SwDrawContact* pContact = static_cast<SwDrawContact*>(pFormat->FindContactObj());
406 :
407 : // object will destroy itself
408 : pContact->Changed( *pObjArr->pObj, SDRUSERCALL_DELETE,
409 0 : pObjArr->pObj->GetLastBoundRect() );
410 0 : pObjArr->pObj->SetUserCall( 0 );
411 :
412 0 : ::lcl_SaveAnchor( pFormat, pObjArr->nNodeIdx );
413 :
414 : // notify UNO objects to decouple
415 0 : ::lcl_SendRemoveToUno( *pFormat );
416 :
417 : // remove from array
418 0 : SwDoc* pDoc = pFormat->GetDoc();
419 0 : SwFrameFormats& rFlyFormats = *pDoc->GetSpzFrameFormats();
420 0 : rFlyFormats.erase( std::find( rFlyFormats.begin(), rFlyFormats.end(), pFormat ));
421 :
422 0 : for( sal_uInt16 n = 1; n < nSize; ++n )
423 : {
424 0 : SwUndoGroupObjImpl& rSave = *( pObjArr + n );
425 :
426 0 : ::lcl_RestoreAnchor( rSave.pFormat, rSave.nNodeIdx );
427 0 : rFlyFormats.push_back( rSave.pFormat );
428 :
429 : // #i45952# - notify that position attributes are already set
430 : OSL_ENSURE( rSave.pFormat->ISA(SwDrawFrameFormat),
431 : "<SwUndoDrawGroup::Undo(..)> - wrong type of frame format for drawing object" );
432 0 : if ( rSave.pFormat->ISA(SwDrawFrameFormat) )
433 : {
434 0 : static_cast<SwDrawFrameFormat*>(rSave.pFormat)->PosAttrSet();
435 : }
436 : }
437 0 : }
438 :
439 0 : void SwUndoDrawUnGroup::AddObj( sal_uInt16 nPos, SwDrawFrameFormat* pFormat )
440 : {
441 0 : SwUndoGroupObjImpl& rSave = *( pObjArr + nPos + 1 );
442 0 : rSave.pFormat = pFormat;
443 0 : rSave.pObj = 0;
444 0 : }
445 :
446 0 : SwUndoDrawUnGroupConnectToLayout::SwUndoDrawUnGroupConnectToLayout()
447 0 : : SwUndo( UNDO_DRAWUNGROUP )
448 : {
449 0 : }
450 :
451 0 : SwUndoDrawUnGroupConnectToLayout::~SwUndoDrawUnGroupConnectToLayout()
452 : {
453 0 : }
454 :
455 : void
456 0 : SwUndoDrawUnGroupConnectToLayout::UndoImpl(::sw::UndoRedoContext &)
457 : {
458 0 : for ( std::vector< SdrObject >::size_type i = 0;
459 0 : i < aDrawFormatsAndObjs.size(); ++i )
460 : {
461 0 : SdrObject* pObj( aDrawFormatsAndObjs[i].second );
462 0 : SwDrawContact* pDrawContact( dynamic_cast<SwDrawContact*>(pObj->GetUserCall()) );
463 : OSL_ENSURE( pDrawContact,
464 : "<SwUndoDrawUnGroupConnectToLayout::Undo(..)> -- missing SwDrawContact instance" );
465 0 : if ( pDrawContact )
466 : {
467 : // deletion of instance <pDrawContact> and thus disconnection from
468 : // the Writer layout.
469 0 : pDrawContact->Changed( *pObj, SDRUSERCALL_DELETE, pObj->GetLastBoundRect() );
470 0 : pObj->SetUserCall( 0 );
471 : }
472 : }
473 0 : }
474 :
475 : void
476 0 : SwUndoDrawUnGroupConnectToLayout::RedoImpl(::sw::UndoRedoContext &)
477 : {
478 0 : for ( std::vector< std::pair< SwDrawFrameFormat*, SdrObject* > >::size_type i = 0;
479 0 : i < aDrawFormatsAndObjs.size(); ++i )
480 : {
481 0 : SwDrawFrameFormat* pFormat( aDrawFormatsAndObjs[i].first );
482 0 : SdrObject* pObj( aDrawFormatsAndObjs[i].second );
483 0 : SwDrawContact *pContact = new SwDrawContact( pFormat, pObj );
484 0 : pContact->ConnectToLayout();
485 0 : pContact->MoveObjToVisibleLayer( pObj );
486 : }
487 0 : }
488 :
489 0 : void SwUndoDrawUnGroupConnectToLayout::AddFormatAndObj( SwDrawFrameFormat* pDrawFrameFormat,
490 : SdrObject* pDrawObject )
491 : {
492 : aDrawFormatsAndObjs.push_back(
493 0 : std::pair< SwDrawFrameFormat*, SdrObject* >( pDrawFrameFormat, pDrawObject ) );
494 0 : }
495 :
496 1 : SwUndoDrawDelete::SwUndoDrawDelete( sal_uInt16 nCnt )
497 1 : : SwUndo( UNDO_DRAWDELETE ), nSize( nCnt ), bDelFormat( true )
498 : {
499 1 : pObjArr = new SwUndoGroupObjImpl[ nSize ];
500 1 : pMarkLst = new SdrMarkList();
501 1 : }
502 :
503 3 : SwUndoDrawDelete::~SwUndoDrawDelete()
504 : {
505 1 : if( bDelFormat )
506 : {
507 1 : SwUndoGroupObjImpl* pTmp = pObjArr;
508 2 : for( size_t n = 0; n < pMarkLst->GetMarkCount(); ++n, ++pTmp )
509 1 : delete pTmp->pFormat;
510 : }
511 1 : delete [] pObjArr;
512 1 : delete pMarkLst;
513 2 : }
514 :
515 0 : void SwUndoDrawDelete::UndoImpl(::sw::UndoRedoContext & rContext)
516 : {
517 0 : bDelFormat = false;
518 0 : SwFrameFormats & rFlyFormats = *rContext.GetDoc().GetSpzFrameFormats();
519 0 : for( size_t n = 0; n < pMarkLst->GetMarkCount(); ++n )
520 : {
521 0 : SwUndoGroupObjImpl& rSave = *( pObjArr + n );
522 0 : ::lcl_RestoreAnchor( rSave.pFormat, rSave.nNodeIdx );
523 0 : rFlyFormats.push_back( rSave.pFormat );
524 0 : SdrObject *pObj = rSave.pObj;
525 0 : SwDrawContact *pContact = new SwDrawContact( rSave.pFormat, pObj );
526 0 : pContact->_Changed( *pObj, SDRUSERCALL_INSERTED, NULL );
527 : // #i45718# - follow-up of #i35635# move object to visible layer
528 0 : pContact->MoveObjToVisibleLayer( pObj );
529 : // #i45952# - notify that position attributes are already set
530 : OSL_ENSURE( rSave.pFormat->ISA(SwDrawFrameFormat),
531 : "<SwUndoDrawGroup::Undo(..)> - wrong type of frame format for drawing object" );
532 0 : if ( rSave.pFormat->ISA(SwDrawFrameFormat) )
533 : {
534 0 : static_cast<SwDrawFrameFormat*>(rSave.pFormat)->PosAttrSet();
535 : }
536 : }
537 0 : rContext.SetSelections(0, pMarkLst);
538 0 : }
539 :
540 0 : void SwUndoDrawDelete::RedoImpl(::sw::UndoRedoContext & rContext)
541 : {
542 0 : bDelFormat = true;
543 0 : SwFrameFormats & rFlyFormats = *rContext.GetDoc().GetSpzFrameFormats();
544 0 : for( size_t n = 0; n < pMarkLst->GetMarkCount(); ++n )
545 : {
546 0 : SwUndoGroupObjImpl& rSave = *( pObjArr + n );
547 0 : SdrObject *pObj = rSave.pObj;
548 0 : SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
549 0 : SwDrawFrameFormat *pFormat = static_cast<SwDrawFrameFormat*>(pContact->GetFormat());
550 :
551 : // object will destroy itself
552 0 : pContact->Changed( *pObj, SDRUSERCALL_DELETE, pObj->GetLastBoundRect() );
553 0 : pObj->SetUserCall( 0 );
554 :
555 : // notify UNO objects to decouple
556 0 : ::lcl_SendRemoveToUno( *pFormat );
557 :
558 0 : rFlyFormats.erase( std::find( rFlyFormats.begin(), rFlyFormats.end(), pFormat ));
559 0 : ::lcl_SaveAnchor( pFormat, rSave.nNodeIdx );
560 : }
561 0 : }
562 :
563 1 : void SwUndoDrawDelete::AddObj( sal_uInt16 , SwDrawFrameFormat* pFormat,
564 : const SdrMark& rMark )
565 : {
566 1 : SwUndoGroupObjImpl& rSave = *( pObjArr + pMarkLst->GetMarkCount() );
567 1 : rSave.pObj = rMark.GetMarkedSdrObj();
568 1 : rSave.pFormat = pFormat;
569 1 : ::lcl_SaveAnchor( pFormat, rSave.nNodeIdx );
570 :
571 : // notify UNO objects to decouple
572 1 : ::lcl_SendRemoveToUno( *pFormat );
573 :
574 : // remove from array
575 1 : SwDoc* pDoc = pFormat->GetDoc();
576 1 : SwFrameFormats& rFlyFormats = *pDoc->GetSpzFrameFormats();
577 1 : rFlyFormats.erase( std::find( rFlyFormats.begin(), rFlyFormats.end(), pFormat ));
578 :
579 1 : pMarkLst->InsertEntry( rMark );
580 178 : }
581 :
582 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|