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