LCOV - code coverage report
Current view: top level - sw/source/core/undo - undraw.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 288 0.0 %
Date: 2014-04-14 Functions: 0 36 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10