LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/frmedt - fefly1.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 995 0.0 %
Date: 2012-12-27 Functions: 0 47 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             : 
      21             : #include <hintids.hxx>
      22             : #include <svl/itemiter.hxx>
      23             : #include <svtools/imapobj.hxx>
      24             : #include <svtools/soerr.hxx>
      25             : #include <editeng/protitem.hxx>
      26             : #include <svx/svdogrp.hxx>
      27             : #include <svx/svdouno.hxx>
      28             : #include <svx/fmglob.hxx>
      29             : #include <com/sun/star/form/FormButtonType.hpp>
      30             : #include <com/sun/star/beans/XPropertySet.hpp>
      31             : #include <fmtanchr.hxx>
      32             : #include <txtflcnt.hxx>
      33             : #include <fmtcntnt.hxx>
      34             : #include <fmtornt.hxx>
      35             : #include <fmtflcnt.hxx>
      36             : #include <fmturl.hxx>
      37             : #include <fmtclds.hxx>
      38             : #include <fmtfsize.hxx>
      39             : #include <docary.hxx>
      40             : #include <fesh.hxx>
      41             : #include <rootfrm.hxx>
      42             : #include <pagefrm.hxx>
      43             : #include <cntfrm.hxx>
      44             : #include <txtfrm.hxx>
      45             : #include <viewimp.hxx>
      46             : #include <viscrs.hxx>
      47             : #include <doc.hxx>
      48             : #include <IDocumentUndoRedo.hxx>
      49             : #include <dview.hxx>
      50             : #include <dflyobj.hxx>
      51             : #include <dcontact.hxx>
      52             : #include <frmfmt.hxx>
      53             : #include <flyfrm.hxx>
      54             : #include <ndtxt.hxx>
      55             : #include <edimp.hxx>
      56             : #include <swtable.hxx>
      57             : #include <mvsave.hxx>       // storage structures for Move/Delete
      58             : #include <ndgrf.hxx>
      59             : #include <flyfrms.hxx>
      60             : #include <flypos.hxx>
      61             : #include <fldbas.hxx>
      62             : #include <fmtfld.hxx>
      63             : #include <swundo.hxx>
      64             : #include <frame.hxx>
      65             : #include <notxtfrm.hxx>
      66             : #include <HandleAnchorNodeChg.hxx>
      67             : #include <frmatr.hxx>
      68             : #include <fmtsrnd.hxx> // #i89920#
      69             : #include <ndole.hxx>
      70             : #include <editeng/opaqitem.hxx>
      71             : 
      72             : using ::rtl::OUString;
      73             : using namespace ::com::sun::star;
      74             : 
      75             : // To register Flys in Flys in ...
      76             : // as defined in layout/frmtool.cxx
      77             : void RegistFlys( SwPageFrm*, const SwLayoutFrm* );
      78             : 
      79             : /***********************************************************************
      80             : #*  Class       :  SwDoc
      81             : #*  Methode     :  UseSpzLayoutFmt
      82             : #*  Description :  based on the request, changes to the specific layouts
      83             : #*                 will be made, to fit to the format
      84             : #***********************************************************************/
      85             : 
      86           0 : static bool lcl_SetNewFlyPos( const SwNode& rNode, SwFmtAnchor& rAnchor,
      87             :                         const Point& rPt )
      88             : {
      89           0 :     bool bRet = false;
      90           0 :     const SwStartNode* pStNode = rNode.FindFlyStartNode();
      91           0 :     if( pStNode )
      92             :     {
      93           0 :         SwPosition aPos( *pStNode );
      94           0 :         rAnchor.SetAnchor( &aPos );
      95           0 :         bRet = true;
      96             :     }
      97             :     else
      98             :     {
      99           0 :         const SwCntntNode *pCntNd = rNode.GetCntntNode();
     100           0 :         const SwCntntFrm* pCFrm = pCntNd ? pCntNd->getLayoutFrm( pCntNd->GetDoc()->GetCurrentLayout(), &rPt, 0, sal_False ) : 0;
     101           0 :         const SwPageFrm *pPg = pCFrm ? pCFrm->FindPageFrm() : 0;
     102             : 
     103           0 :         rAnchor.SetPageNum( pPg ? pPg->GetPhyPageNum() : 1 );
     104           0 :         rAnchor.SetType( FLY_AT_PAGE );
     105             :     }
     106           0 :     return bRet;
     107             : }
     108             : 
     109           0 : static sal_Bool lcl_FindAnchorPos( SwDoc& rDoc, const Point& rPt, const SwFrm& rFrm,
     110             :                         SfxItemSet& rSet )
     111             : {
     112           0 :     sal_Bool bRet = sal_True;
     113           0 :     SwFmtAnchor aNewAnch( (SwFmtAnchor&)rSet.Get( RES_ANCHOR ) );
     114           0 :     RndStdIds nNew = aNewAnch.GetAnchorId();
     115             :     const SwFrm *pNewAnch;
     116             : 
     117             :     //determine new anchor
     118           0 :     Point aTmpPnt( rPt );
     119           0 :     switch( nNew )
     120             :     {
     121             :     case FLY_AS_CHAR:  // also include this?
     122             :     case FLY_AT_PARA:
     123             :     case FLY_AT_CHAR: // LAYER_IMPL
     124             :         {
     125             :             // starting from the upper-left corner of the Fly,
     126             :             // search nearest CntntFrm
     127           0 :             const SwFrm* pFrm = rFrm.IsFlyFrm() ? ((SwFlyFrm&)rFrm).GetAnchorFrm()
     128           0 :                                                 : &rFrm;
     129           0 :             pNewAnch = ::FindAnchor( pFrm, aTmpPnt );
     130           0 :             if( pNewAnch->IsProtected() )
     131             :             {
     132           0 :                 bRet = sal_False;
     133             :                 break;
     134             :             }
     135             : 
     136           0 :             SwPosition aPos( *((SwCntntFrm*)pNewAnch)->GetNode() );
     137           0 :             if ((FLY_AT_CHAR == nNew) || (FLY_AS_CHAR == nNew))
     138             :             {
     139             :                 // textnode should be found, as only in those
     140             :                 // a content bound frame can be anchored
     141           0 :                 SwCrsrMoveState aState( MV_SETONLYTEXT );
     142           0 :                 aTmpPnt.X() -= 1;                   // do not land in the fly!
     143           0 :                 if( !pNewAnch->GetCrsrOfst( &aPos, aTmpPnt, &aState ) )
     144             :                 {
     145           0 :                     SwCntntNode* pCNd = ((SwCntntFrm*)pNewAnch)->GetNode();
     146           0 :                     if( pNewAnch->Frm().Bottom() < aTmpPnt.Y() )
     147           0 :                         pCNd->MakeStartIndex( &aPos.nContent );
     148             :                     else
     149           0 :                         pCNd->MakeEndIndex( &aPos.nContent );
     150             :                 }
     151             :             }
     152           0 :             aNewAnch.SetAnchor( &aPos );
     153             :         }
     154           0 :         break;
     155             : 
     156             :     case FLY_AT_FLY: // LAYER_IMPL
     157             :         {
     158             :             // starting from the upper-left corner of the Fly
     159             :             // search nearest SwFlyFrm
     160           0 :             SwCrsrMoveState aState( MV_SETONLYTEXT );
     161           0 :             SwPosition aPos( rDoc.GetNodes() );
     162           0 :             aTmpPnt.X() -= 1;                   // do not land in the fly!
     163           0 :             rDoc.GetCurrentLayout()->GetCrsrOfst( &aPos, aTmpPnt, &aState );    //swmod 071108//swmod 071225
     164             :             pNewAnch = ::FindAnchor(
     165           0 :                 aPos.nNode.GetNode().GetCntntNode()->getLayoutFrm( rFrm.getRootFrm(), 0, 0, sal_False ),
     166           0 :                 aTmpPnt )->FindFlyFrm();
     167             : 
     168           0 :             if( pNewAnch && &rFrm != pNewAnch && !pNewAnch->IsProtected() )
     169             :             {
     170           0 :                 aPos.nNode = *((SwFlyFrm*)pNewAnch)->GetFmt()->GetCntnt().
     171           0 :                                 GetCntntIdx();
     172           0 :                 aNewAnch.SetAnchor( &aPos );
     173             :                 break;
     174           0 :             }
     175             :         }
     176             : 
     177           0 :         aNewAnch.SetType( nNew = FLY_AT_PAGE );
     178             :         // no break
     179             : 
     180             :     case FLY_AT_PAGE:
     181           0 :         pNewAnch = rFrm.FindPageFrm();
     182           0 :         aNewAnch.SetPageNum( pNewAnch->GetPhyPageNum() );
     183           0 :         break;
     184             : 
     185             :     default:
     186             :         OSL_ENSURE( !&rDoc, "Falsche ID fuer neuen Anker." );
     187             :     }
     188             : 
     189           0 :     rSet.Put( aNewAnch );
     190           0 :     return bRet;
     191             : }
     192             : 
     193             : //
     194             : //! also used in unoframe.cxx
     195             : //
     196           0 : sal_Bool sw_ChkAndSetNewAnchor( const SwFlyFrm& rFly, SfxItemSet& rSet )
     197             : {
     198           0 :     const SwFrmFmt& rFmt = *rFly.GetFmt();
     199           0 :     const SwFmtAnchor &rOldAnch = rFmt.GetAnchor();
     200           0 :     const RndStdIds nOld = rOldAnch.GetAnchorId();
     201             : 
     202           0 :     RndStdIds nNew = ((SwFmtAnchor&)rSet.Get( RES_ANCHOR )).GetAnchorId();
     203             : 
     204           0 :     if( nOld == nNew )
     205           0 :         return sal_False;
     206             : 
     207           0 :     SwDoc* pDoc = (SwDoc*)rFmt.GetDoc();
     208             : 
     209             : #if OSL_DEBUG_LEVEL > 0
     210             :     OSL_ENSURE( !(nNew == FLY_AT_PAGE &&
     211             :         (FLY_AT_PARA==nOld || FLY_AT_CHAR==nOld || FLY_AS_CHAR==nOld ) &&
     212             :         pDoc->IsInHeaderFooter( rOldAnch.GetCntntAnchor()->nNode )),
     213             :             "forbidden anchor change in Head/Foot." );
     214             : #endif
     215             : 
     216           0 :     return ::lcl_FindAnchorPos( *pDoc, rFly.Frm().Pos(), rFly, rSet );
     217             : }
     218             : 
     219           0 : void SwFEShell::SelectFlyFrm( SwFlyFrm& rFrm, sal_Bool bNew )
     220             : {
     221           0 :     SET_CURR_SHELL( this );
     222             : 
     223             :     // The frame is new, thus select it.
     224             :     // !! Always select the frame, if it's not selected.
     225             :     // - it could be a new "old" one because the anchor was changed
     226             :     // - "old" frames have had to be selected previously otherwise they could
     227             :     //   not have been changed
     228             :     // The frames should not be selected by the document position, because
     229             :     // it should have been selected!
     230           0 :     SwViewImp *pImpl = Imp();
     231           0 :     if( GetWin() && (bNew || !pImpl->GetDrawView()->AreObjectsMarked()) )
     232             :     {
     233             :         OSL_ENSURE( rFrm.IsFlyFrm(), "SelectFlyFrm will einen Fly" );
     234             : 
     235             :        // nothing to be done if the Fly already was selected
     236           0 :         if ( FindFlyFrm() == &rFrm )
     237           0 :             return;
     238             : 
     239             :         // assure the anchor is drawn
     240           0 :         if( rFrm.IsFlyInCntFrm() && rFrm.GetAnchorFrm() )
     241           0 :              rFrm.GetAnchorFrm()->SetCompletePaint();
     242             : 
     243           0 :         if( pImpl->GetDrawView()->AreObjectsMarked() )
     244           0 :             pImpl->GetDrawView()->UnmarkAll();
     245             : 
     246           0 :         pImpl->GetDrawView()->MarkObj( rFrm.GetVirtDrawObj(),
     247           0 :                                       pImpl->GetPageView(), sal_False, sal_False );
     248           0 :         KillPams();
     249           0 :         ClearMark();
     250           0 :         SelFlyGrabCrsr();
     251           0 :     }
     252             : }
     253             : 
     254             : /*************************************************************************
     255             : |*
     256             : |*  SwFEShell::FindFlyFrm()
     257             : |*
     258             : |*  Description        returns a Fly if one is selected
     259             : |*
     260             : *************************************************************************/
     261             : 
     262           0 : SwFlyFrm *SwFEShell::FindFlyFrm() const
     263             : {
     264           0 :     if ( Imp()->HasDrawView() )
     265             :     {
     266             :         // A Fly is only accessible if it is selected
     267           0 :         const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
     268           0 :         if( rMrkList.GetMarkCount() != 1 )
     269           0 :             return 0;
     270             : 
     271           0 :         SdrObject *pO = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
     272           0 :         return ( pO && pO->ISA(SwVirtFlyDrawObj) ) ? ((SwVirtFlyDrawObj*)pO)->GetFlyFrm() : 0;
     273             :     }
     274           0 :     return 0;
     275             : }
     276             : 
     277             : /*************************************************************************
     278             : |*
     279             : |*  SwFEShell::IsFlyInFly()
     280             : |*
     281             : |*  Description        Returns sal_True, if the current Fly could be anchored
     282             : |*                     to another one (so it is inside)
     283             : |*
     284             : *************************************************************************/
     285             : 
     286           0 : const SwFrmFmt* SwFEShell::IsFlyInFly()
     287             : {
     288           0 :     SET_CURR_SHELL( this );
     289             : 
     290           0 :     if ( !Imp()->HasDrawView() )
     291           0 :         return NULL;
     292             : 
     293           0 :     const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
     294           0 :     if ( !rMrkList.GetMarkCount() )
     295             :     {
     296           0 :         SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
     297           0 :         if( !pCntnt )
     298           0 :             return NULL;
     299           0 :         SwFlyFrm *pFly = pCntnt->FindFlyFrm();
     300           0 :         if ( !pFly )
     301           0 :             return NULL;
     302           0 :         return pFly->GetFmt();
     303             :     }
     304           0 :     else if ( rMrkList.GetMarkCount() != 1 ||
     305           0 :          !GetUserCall(rMrkList.GetMark( 0 )->GetMarkedSdrObj()) )
     306           0 :         return NULL;
     307             : 
     308           0 :     SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
     309             : 
     310           0 :     SwFrmFmt *pFmt = FindFrmFmt( pObj );
     311           0 :     if( pFmt && FLY_AT_FLY == pFmt->GetAnchor().GetAnchorId() )
     312             :     {
     313           0 :         const SwFrm* pFly = pObj->ISA(SwVirtFlyDrawObj) ?
     314           0 :             ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm()->GetAnchorFrm() :
     315           0 :             ((SwDrawContact*)GetUserCall(pObj))->GetAnchorFrm( pObj );
     316             :         OSL_ENSURE( pFly, "IsFlyInFly: Where's my anchor?" );
     317             :         OSL_ENSURE( pFly->IsFlyFrm(), "IsFlyInFly: Funny anchor!" );
     318           0 :         return ((SwFlyFrm*)pFly)->GetFmt();
     319             :     }
     320             : 
     321           0 :     Point aTmpPos = pObj->GetCurrentBoundRect().TopLeft();
     322             : 
     323             :     SwFrm *pTxtFrm;
     324             :     {
     325           0 :         SwCrsrMoveState aState( MV_SETONLYTEXT );
     326           0 :         SwNodeIndex aSwNodeIndex( GetDoc()->GetNodes() );
     327           0 :         SwPosition aPos( aSwNodeIndex );
     328           0 :         Point aPoint( aTmpPos );
     329           0 :         aPoint.X() -= 1;                    //do not land in the fly!!
     330           0 :         GetLayout()->GetCrsrOfst( &aPos, aPoint, &aState );
     331             :         // determine text frame by left-top-corner of object
     332           0 :         pTxtFrm = aPos.nNode.GetNode().GetCntntNode()->getLayoutFrm( GetLayout(), &aTmpPos, 0, sal_False );
     333             :     }
     334           0 :     const SwFrm *pTmp = ::FindAnchor( pTxtFrm, aTmpPos );
     335           0 :     const SwFlyFrm *pFly = pTmp->FindFlyFrm();
     336           0 :     if( pFly )
     337           0 :         return pFly->GetFmt();
     338           0 :     return NULL;
     339             : }
     340             : 
     341             : /*************************************************************************
     342             : |*
     343             : |*  SwFEShell::SetFlyPos
     344             : |*
     345             : *************************************************************************/
     346             : 
     347           0 : void SwFEShell::SetFlyPos( const Point& rAbsPos )
     348             : {
     349           0 :     SET_CURR_SHELL( this );
     350             : 
     351             :     // Determine reference point in document coordinates
     352           0 :     SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
     353           0 :     if( !pCntnt )
     354             :         return;
     355           0 :     SwFlyFrm *pFly = pCntnt->FindFlyFrm();
     356           0 :     if ( !pFly )
     357             :         return;
     358             : 
     359             :     //SwSaveHdl aSaveX( Imp() );
     360             : 
     361             :     // Set an anchor starting from the absolute position for paragraph bound Flys
     362             :     // Anchor and new RelPos will be calculated and set by the Fly
     363           0 :     if ( pFly->IsFlyAtCntFrm() )
     364           0 :         ((SwFlyAtCntFrm*)pFly)->SetAbsPos( rAbsPos );
     365             :     else
     366             :     {
     367           0 :             const SwFrm *pAnch = pFly->GetAnchorFrm();
     368           0 :             Point aOrient( pAnch->Frm().Pos() );
     369             : 
     370           0 :         if ( pFly->IsFlyInCntFrm() )
     371           0 :             aOrient.X() = rAbsPos.X();
     372             : 
     373             :         // calculate RelPos.
     374           0 :         aOrient.X() = rAbsPos.X() - aOrient.X();
     375           0 :         aOrient.Y() = rAbsPos.Y() - aOrient.Y();
     376           0 :         pFly->ChgRelPos( aOrient );
     377             :     }
     378           0 :     CallChgLnk();       // call the AttrChangeNotify on the UI-side.
     379             : }
     380             : 
     381             : /*************************************************************************
     382             : |*
     383             : |*  SwFEShell::FindAnchorPos
     384             : |*
     385             : *************************************************************************/
     386             : 
     387           0 : Point SwFEShell::FindAnchorPos( const Point& rAbsPos, sal_Bool bMoveIt )
     388             : {
     389           0 :     Point aRet;
     390             : 
     391           0 :     SET_CURR_SHELL( this );
     392             : 
     393           0 :     if ( !Imp()->HasDrawView() )
     394             :         return aRet;
     395             : 
     396           0 :     const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
     397           0 :     if ( rMrkList.GetMarkCount() != 1 ||
     398           0 :          !GetUserCall(rMrkList.GetMark( 0 )->GetMarkedSdrObj()) )
     399             :         return aRet;
     400             : 
     401           0 :     SdrObject* pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
     402             :     // #i28701#
     403           0 :     SwAnchoredObject* pAnchoredObj = ::GetUserCall( pObj )->GetAnchoredObj( pObj );
     404           0 :     SwFrmFmt& rFmt = pAnchoredObj->GetFrmFmt();
     405           0 :     RndStdIds nAnchorId = rFmt.GetAnchor().GetAnchorId();
     406             : 
     407           0 :     if ( FLY_AS_CHAR == nAnchorId )
     408             :         return aRet;
     409             : 
     410           0 :     sal_Bool bFlyFrame = pObj->ISA(SwVirtFlyDrawObj);
     411             : 
     412           0 :     SwFlyFrm* pFly = 0L;
     413             :     const SwFrm* pOldAnch;
     414           0 :     const SwFrm* pFooterOrHeader = NULL;
     415             : 
     416           0 :     if( bFlyFrame )
     417             :     {
     418             :         // Calculate reference point in document coordinates
     419           0 :         SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
     420           0 :         if( !pCntnt )
     421             :             return aRet;
     422           0 :         pFly = pCntnt->FindFlyFrm();
     423           0 :         if ( !pFly )
     424             :             return aRet;
     425           0 :         pOldAnch = pFly->GetAnchorFrm();
     426           0 :         if( !pOldAnch )
     427             :             return aRet;
     428           0 :         if ( FLY_AT_PAGE != nAnchorId )
     429             :         {
     430           0 :             pFooterOrHeader = pCntnt->FindFooterOrHeader();
     431             :         }
     432             :     }
     433             :     // set <pFooterOrHeader> also for drawing
     434             :     // objects, but not for control objects.
     435             :     // Necessary for moving 'anchor symbol' at the user interface inside header/footer.
     436           0 :     else if ( !::CheckControlLayer( pObj ) )
     437             :     {
     438           0 :         SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
     439           0 :         if( !pCntnt )
     440             :             return aRet;
     441           0 :         pFooterOrHeader = pCntnt->FindFooterOrHeader();
     442             :     }
     443             : 
     444             :     // Search nearest SwFlyFrm starting from the upper-left corner
     445             :     // of the fly
     446             :     SwCntntFrm *pTxtFrm;
     447             :     {
     448           0 :         SwCrsrMoveState aState( MV_SETONLYTEXT );
     449           0 :         SwPosition aPos( GetDoc()->GetNodes().GetEndOfExtras() );
     450           0 :         Point aTmpPnt( rAbsPos );
     451           0 :         GetLayout()->GetCrsrOfst( &aPos, aTmpPnt, &aState );
     452           0 :         pTxtFrm = aPos.nNode.GetNode().GetCntntNode()->getLayoutFrm( GetLayout(),0,&aPos,sal_False );
     453             :     }
     454             :     const SwFrm *pNewAnch;
     455           0 :     if( pTxtFrm )
     456             :     {
     457           0 :         if ( FLY_AT_PAGE == nAnchorId )
     458             :         {
     459           0 :             pNewAnch = pTxtFrm->FindPageFrm();
     460             :         }
     461             :         else
     462             :         {
     463           0 :             pNewAnch = ::FindAnchor( pTxtFrm, rAbsPos );
     464             : 
     465           0 :             if( FLY_AT_FLY == nAnchorId ) // LAYER_IMPL
     466             :             {
     467           0 :                 pNewAnch = pNewAnch->FindFlyFrm();
     468             :             }
     469             :         }
     470             :     }
     471             :     else
     472           0 :         pNewAnch = 0;
     473             : 
     474           0 :     if( pNewAnch && !pNewAnch->IsProtected() )
     475             :     {
     476           0 :         const SwFlyFrm* pCheck = bFlyFrame ? pNewAnch->FindFlyFrm() : 0;
     477             :         // If we land inside the frame, make sure
     478             :         // that the frame does not land inside its own content
     479           0 :         while( pCheck )
     480             :         {
     481           0 :             if( pCheck == pFly )
     482           0 :                 break;
     483           0 :             const SwFrm *pTmp = pCheck->GetAnchorFrm();
     484           0 :             pCheck = pTmp ? pTmp->FindFlyFrm() : NULL;
     485             :         }
     486             : 
     487             :         // Do not switch from header/footer to another area,
     488             :         // do not switch to a header/footer
     489           0 :         if( !pCheck &&
     490           0 :             pFooterOrHeader == pNewAnch->FindFooterOrHeader() )
     491             :         {
     492           0 :             aRet = pNewAnch->GetFrmAnchorPos( ::HasWrap( pObj ) );
     493             : 
     494           0 :             if ( bMoveIt || (nAnchorId == FLY_AT_CHAR) )
     495             :             {
     496           0 :                 SwFmtAnchor aAnch( rFmt.GetAnchor() );
     497           0 :                 switch ( nAnchorId )
     498             :                 {
     499             :                     case FLY_AT_PARA:
     500             :                     {
     501           0 :                         SwPosition *pPos = (SwPosition*)aAnch.GetCntntAnchor();
     502           0 :                         pPos->nNode = *pTxtFrm->GetNode();
     503           0 :                         pPos->nContent.Assign(0,0);
     504           0 :                         break;
     505             :                     }
     506             :                     case FLY_AT_PAGE:
     507             :                     {
     508             :                         aAnch.SetPageNum( ((const SwPageFrm*)pNewAnch)->
     509           0 :                                           GetPhyPageNum() );
     510           0 :                         break;
     511             :                     }
     512             :                     case FLY_AT_FLY:
     513             :                     {
     514           0 :                         SwPosition aPos( *((SwFlyFrm*)pNewAnch)->GetFmt()->
     515           0 :                                                   GetCntnt().GetCntntIdx() );
     516           0 :                         aAnch.SetAnchor( &aPos );
     517           0 :                         break;
     518             :                     }
     519             :                     case FLY_AT_CHAR:
     520             :                     {
     521           0 :                         SwPosition *pPos = (SwPosition*)aAnch.GetCntntAnchor();
     522           0 :                         Point aTmpPnt( rAbsPos );
     523           0 :                         if( pTxtFrm->GetCrsrOfst( pPos, aTmpPnt, NULL ) )
     524             :                         {
     525           0 :                             SwRect aTmpRect;
     526           0 :                             pTxtFrm->GetCharRect( aTmpRect, *pPos );
     527           0 :                             aRet = aTmpRect.Pos();
     528             :                         }
     529             :                         else
     530             :                         {
     531           0 :                             pPos->nNode = *pTxtFrm->GetNode();
     532           0 :                             pPos->nContent.Assign(0,0);
     533             :                         }
     534             :                         break;
     535             :                     }
     536             :                     default:
     537           0 :                         break;
     538             :                 }
     539           0 :                 if( bMoveIt )
     540             :                 {
     541           0 :                     StartAllAction();
     542             :                     // --> handle change of anchor node:
     543             :                     // if count of the anchor frame also change, the fly frames have to be
     544             :                     // re-created. Thus, delete all fly frames except the <this> before the
     545             :                     // anchor attribute is change and re-create them afterwards.
     546             :                     {
     547           0 :                         SwHandleAnchorNodeChg* pHandleAnchorNodeChg( 0L );
     548           0 :                         SwFlyFrmFmt* pFlyFrmFmt( dynamic_cast<SwFlyFrmFmt*>(&rFmt) );
     549           0 :                         if ( pFlyFrmFmt )
     550             :                         {
     551             :                             pHandleAnchorNodeChg =
     552           0 :                                 new SwHandleAnchorNodeChg( *pFlyFrmFmt, aAnch );
     553             :                         }
     554           0 :                         rFmt.GetDoc()->SetAttr( aAnch, rFmt );
     555           0 :                         delete pHandleAnchorNodeChg;
     556             :                     }
     557             :                     // #i28701# - no call of method
     558             :                     // <CheckCharRectAndTopOfLine()> for to-character anchored
     559             :                     // Writer fly frame needed. This method call can cause a
     560             :                     // format of the anchor frame, which is no longer intended.
     561             :                     // Instead clear the anchor character rectangle and
     562             :                     // the top of line values for all to-character anchored objects.
     563           0 :                     pAnchoredObj->ClearCharRectAndTopOfLine();
     564           0 :                     EndAllAction();
     565           0 :                 }
     566             :             }
     567             : 
     568           0 :             SwRect aTmpRect( aRet, rAbsPos );
     569           0 :             if( aTmpRect.HasArea() )
     570           0 :                 MakeVisible( aTmpRect );
     571             : #if OSL_DEBUG_LEVEL > 0
     572             :             //TODO: That doesn't seem to be intended
     573             :             if( Color(COL_TRANSPARENT) != GetOut()->GetLineColor() )
     574             :             {
     575             :                 OSL_FAIL( "Hey, Joe: Where's my Null Pen?" );
     576             :                 GetOut()->SetLineColor( Color(COL_TRANSPARENT) );
     577             :             }
     578             : #endif
     579             :         }
     580             :     }
     581             : 
     582           0 :     return aRet;
     583             : }
     584             : 
     585             : /***********************************************************************
     586             : #*  Class       :  SwFEShell
     587             : #*  Methode     :  NewFlyFrm
     588             : #*  Description :
     589             : #***********************************************************************/
     590             : 
     591           0 : const SwFrmFmt *SwFEShell::NewFlyFrm( const SfxItemSet& rSet, sal_Bool bAnchValid,
     592             :                            SwFrmFmt *pParent )
     593             : {
     594           0 :     SET_CURR_SHELL( this );
     595           0 :     StartAllAction();
     596             : 
     597           0 :     SwPaM* pCrsr = GetCrsr();
     598           0 :     const Point aPt( GetCrsrDocPos() );
     599             : 
     600           0 :     SwSelBoxes aBoxes;
     601           0 :     sal_Bool bMoveCntnt = sal_True;
     602           0 :     if( IsTableMode() )
     603             :     {
     604           0 :         GetTblSel( *this, aBoxes );
     605           0 :         if( !aBoxes.empty() )
     606             :         {
     607             :             // Crsr should be removed from the removal area.
     608             :             // Always put it after/on the table; via the
     609             :             // document position they will be set to the old
     610             :             // position
     611           0 :             ParkCrsr( SwNodeIndex( *aBoxes[0]->GetSttNd() ));
     612             : 
     613             :             // #i127787# pCurCrsr will be deleted in ParkCrsr,
     614             :             // we better get the current pCurCrsr instead of working with the
     615             :             // deleted one:
     616           0 :             pCrsr = GetCrsr();
     617             :         }
     618             :         else
     619           0 :             bMoveCntnt = sal_False;
     620             :     }
     621           0 :     else if( !pCrsr->HasMark() && pCrsr->GetNext() == pCrsr )
     622           0 :         bMoveCntnt = sal_False;
     623             : 
     624           0 :     const SwPosition& rPos = *pCrsr->Start();
     625             : 
     626           0 :     SwFmtAnchor& rAnch = (SwFmtAnchor&)rSet.Get( RES_ANCHOR );
     627           0 :     RndStdIds eRndId = rAnch.GetAnchorId();
     628           0 :     switch( eRndId )
     629             :     {
     630             :     case FLY_AT_PAGE:
     631           0 :         if( !rAnch.GetPageNum() )       //HotFix: Bug in UpdateByExample
     632           0 :             rAnch.SetPageNum( 1 );
     633           0 :         break;
     634             : 
     635             :     case FLY_AT_FLY:
     636             :     case FLY_AT_PARA:
     637             :     case FLY_AT_CHAR:
     638             :     case FLY_AS_CHAR:
     639           0 :         if( !bAnchValid )
     640             :         {
     641           0 :             if( FLY_AT_FLY != eRndId )
     642             :             {
     643           0 :                 rAnch.SetAnchor( &rPos );
     644             :             }
     645           0 :             else if( lcl_SetNewFlyPos( rPos.nNode.GetNode(), rAnch, aPt ) )
     646             :             {
     647           0 :                 eRndId = FLY_AT_PAGE;
     648             :             }
     649             :         }
     650           0 :         break;
     651             : 
     652             :     default:
     653             :         OSL_ENSURE( !this, "What is the purpose of this Fly?" );
     654           0 :         break;
     655             :     }
     656             : 
     657             :     SwFlyFrmFmt *pRet;
     658           0 :     if( bMoveCntnt )
     659             :     {
     660           0 :         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_INSLAYFMT, NULL );
     661           0 :         SwFmtAnchor* pOldAnchor = 0;
     662           0 :         bool bHOriChgd = false, bVOriChgd = false;
     663           0 :         SwFmtVertOrient aOldV;
     664           0 :         SwFmtHoriOrient aOldH;
     665             : 
     666           0 :         if ( FLY_AT_PAGE != eRndId )
     667             :         {
     668             :            // First as with page link. Paragraph/character link on if
     669             :             // everything was shifted. Then the position is valid!
     670             :             // JP 13.05.98: if necessary also convert the horizontal/vertical
     671             :             //              orientation, to prevent correction during re-anchoring
     672           0 :             pOldAnchor = new SwFmtAnchor( rAnch );
     673           0 :             const_cast<SfxItemSet&>(rSet).Put( SwFmtAnchor( FLY_AT_PAGE, 1 ) );
     674             : 
     675             :             const SfxPoolItem* pItem;
     676           0 :             if( SFX_ITEM_SET == rSet.GetItemState( RES_HORI_ORIENT, sal_False, &pItem )
     677           0 :                 && text::HoriOrientation::NONE == ((SwFmtHoriOrient*)pItem)->GetHoriOrient() )
     678             :             {
     679           0 :                 bHOriChgd = true;
     680           0 :                 aOldH = *((SwFmtHoriOrient*)pItem);
     681           0 :                 ((SfxItemSet&)rSet).Put( SwFmtHoriOrient( 0, text::HoriOrientation::LEFT ) );
     682             :             }
     683           0 :             if( SFX_ITEM_SET == rSet.GetItemState( RES_VERT_ORIENT, sal_False, &pItem )
     684           0 :                 && text::VertOrientation::NONE == ((SwFmtVertOrient*)pItem)->GetVertOrient() )
     685             :             {
     686           0 :                 bVOriChgd = true;
     687           0 :                 aOldV = *((SwFmtVertOrient*)pItem);
     688           0 :                 ((SfxItemSet&)rSet).Put( SwFmtVertOrient( 0, text::VertOrientation::TOP ) );
     689             :             }
     690             :         }
     691             : 
     692           0 :         pRet = GetDoc()->MakeFlyAndMove( *pCrsr, rSet, &aBoxes, pParent );
     693             : 
     694           0 :         KillPams();
     695             : 
     696           0 :         if( pOldAnchor )
     697             :         {
     698           0 :             if( pRet )
     699             :             {
     700             :                 // calculate new position
     701             :                 // JP 24.03.97: also go via page links
     702             :                 //              chaos::anchor should not lie in the shifted area
     703           0 :                 pRet->DelFrms();
     704             : 
     705           0 :                 const SwFrm* pAnch = ::FindAnchor( GetLayout(), aPt, sal_False );
     706           0 :                 SwPosition aPos( *((SwCntntFrm*)pAnch)->GetNode() );
     707           0 :                 if ( FLY_AS_CHAR == eRndId )
     708             :                 {
     709           0 :                     aPos.nContent.Assign( ((SwCntntFrm*)pAnch)->GetNode(), 0 );
     710             :                 }
     711           0 :                 pOldAnchor->SetAnchor( &aPos );
     712             : 
     713             :                 // shifting of table selection is not Undo-capable. therefore
     714             :                 // changing the anchors should not be recorded
     715             :                 bool const bDoesUndo =
     716           0 :                     GetDoc()->GetIDocumentUndoRedo().DoesUndo();
     717           0 :                 SwUndoId nLastUndoId(UNDO_EMPTY);
     718           0 :                 if (bDoesUndo &&
     719           0 :                     GetDoc()->GetIDocumentUndoRedo().GetLastUndoInfo(0,
     720           0 :                         & nLastUndoId))
     721             :                 {
     722           0 :                     if (UNDO_INSLAYFMT == nLastUndoId)
     723             :                     {
     724           0 :                         GetDoc()->GetIDocumentUndoRedo().DoUndo(false);
     725             :                     }
     726             :                 }
     727             : 
     728           0 :                 ((SfxItemSet&)rSet).Put( *pOldAnchor );
     729             : 
     730           0 :                 if( bHOriChgd )
     731           0 :                     ((SfxItemSet&)rSet).Put( aOldH );
     732           0 :                 if( bVOriChgd )
     733           0 :                     ((SfxItemSet&)rSet).Put( aOldV );
     734             : 
     735           0 :                 GetDoc()->SetFlyFrmAttr( *pRet, (SfxItemSet&)rSet );
     736           0 :                 GetDoc()->GetIDocumentUndoRedo().DoUndo(bDoesUndo);
     737             :             }
     738           0 :             delete pOldAnchor;
     739             :         }
     740           0 :         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_INSLAYFMT, NULL );
     741             :     }
     742             :     else
     743             :         /* If called from a shell try to propagate an
     744             :             existing adjust item from rPos to the content node of the
     745             :             new frame. */
     746           0 :         pRet = GetDoc()->MakeFlySection( eRndId, &rPos, &rSet, pParent, true );
     747             : 
     748           0 :     if( pRet )
     749             :     {
     750           0 :         SwFlyFrm* pFrm = pRet->GetFrm( &aPt );
     751           0 :         if( pFrm )
     752           0 :             SelectFlyFrm( *pFrm, sal_True );
     753             :         else
     754             :         {
     755           0 :             GetLayout()->SetAssertFlyPages();
     756           0 :             pRet = 0;
     757             :         }
     758             :     }
     759           0 :     EndAllActionAndCall();
     760             : 
     761           0 :     return pRet;
     762             : }
     763             : 
     764             : /***********************************************************************
     765             : #*  Class       :  SwFEShell
     766             : #*  Methode     :  Insert
     767             : #***********************************************************************/
     768             : 
     769           0 : void SwFEShell::Insert( const String& rGrfName, const String& rFltName,
     770             :                         const Graphic* pGraphic,
     771             :                         const SfxItemSet* pFlyAttrSet,
     772             :                         const SfxItemSet* pGrfAttrSet,
     773             :                         SwFrmFmt* pFrmFmt )
     774             : {
     775           0 :     SwFlyFrmFmt* pFmt = 0;
     776           0 :     SET_CURR_SHELL( this );
     777           0 :     StartAllAction();
     778           0 :     SwShellCrsr *pStartCursor = dynamic_cast<SwShellCrsr*>(this->GetSwCrsr());
     779           0 :     SwShellCrsr *pCursor = pStartCursor;
     780           0 :     do {
     781             : 
     782             :         // Has the anchor not been set or been set incompletely?
     783           0 :         if( pFlyAttrSet )
     784             :         {
     785             :             const SfxPoolItem* pItem;
     786           0 :             if( SFX_ITEM_SET == pFlyAttrSet->GetItemState( RES_ANCHOR, sal_False,
     787           0 :                     &pItem ) )
     788             :             {
     789           0 :                 SwFmtAnchor* pAnchor = (SwFmtAnchor*)pItem;
     790           0 :                 switch( pAnchor->GetAnchorId())
     791             :                 {
     792             :                 case FLY_AT_PARA:
     793             :                 case FLY_AT_CHAR: // LAYER_IMPL
     794             :                 case FLY_AS_CHAR:
     795           0 :                     if( !pAnchor->GetCntntAnchor() )
     796             :                     {
     797           0 :                         pAnchor->SetAnchor( pCursor->GetPoint() );
     798             :                     }
     799           0 :                     break;
     800             :                 case FLY_AT_FLY:
     801           0 :                     if( !pAnchor->GetCntntAnchor() )
     802             :                     {
     803           0 :                         lcl_SetNewFlyPos( *pCursor->GetNode(),
     804           0 :                                 *pAnchor, GetCrsrDocPos() );
     805             :                     }
     806           0 :                     break;
     807             :                 case FLY_AT_PAGE:
     808           0 :                     if( !pAnchor->GetPageNum() )
     809             :                     {
     810             :                         pAnchor->SetPageNum( pCursor->GetPageNum(
     811           0 :                                 sal_True, &pCursor->GetPtPos() ) );
     812             :                     }
     813           0 :                     break;
     814             :                 default :
     815           0 :                     break;
     816             :                 }
     817             :             }
     818             :         }
     819           0 :         pFmt = GetDoc()->Insert(*pCursor, rGrfName,
     820             :                                 rFltName, pGraphic,
     821             :                                 pFlyAttrSet,
     822           0 :                                 pGrfAttrSet, pFrmFmt );
     823             :         OSL_ENSURE( pFmt, "Doc->Insert(notxt) failed." );
     824             : 
     825           0 :     } while( (pCursor = dynamic_cast<SwShellCrsr*>(pCursor->GetNext()))
     826             :              != pStartCursor );
     827             : 
     828           0 :     EndAllAction();
     829             : 
     830           0 :     if( pFmt )
     831             :     {
     832           0 :         const Point aPt( GetCrsrDocPos() );
     833           0 :         SwFlyFrm* pFrm = pFmt->GetFrm( &aPt );
     834             : 
     835           0 :         if( pFrm )
     836             :         {
     837             :             // fdo#36681: Invalidate the content and layout to refresh
     838             :             // the picture anchoring properly
     839           0 :             SwPageFrm* pPageFrm = pFrm->FindPageFrmOfAnchor();
     840           0 :             pPageFrm->InvalidateFlyLayout();
     841           0 :             pPageFrm->InvalidateCntnt();
     842             : 
     843           0 :             SelectFlyFrm( *pFrm, sal_True );
     844             :         }
     845             :         else
     846           0 :             GetLayout()->SetAssertFlyPages();
     847           0 :     }
     848           0 : }
     849             : 
     850           0 : SwFlyFrmFmt* SwFEShell::InsertObject( const svt::EmbeddedObjectRef&  xObj,
     851             :                         const SfxItemSet* pFlyAttrSet,
     852             :                         const SfxItemSet* pGrfAttrSet,
     853             :                         SwFrmFmt* pFrmFmt )
     854             : {
     855           0 :     SwFlyFrmFmt* pFmt = 0;
     856           0 :     SET_CURR_SHELL( this );
     857           0 :     StartAllAction();
     858           0 :         FOREACHPAM_START( this )
     859           0 :             pFmt = GetDoc()->Insert(*PCURCRSR, xObj,
     860           0 :                                     pFlyAttrSet, pGrfAttrSet, pFrmFmt );
     861             :             OSL_ENSURE( pFmt, "Doc->Insert(notxt) failed." );
     862             : 
     863           0 :         FOREACHPAM_END()
     864           0 :     EndAllAction();
     865             : 
     866           0 :     if( pFmt )
     867             :     {
     868           0 :         const Point aPt( GetCrsrDocPos() );
     869           0 :         SwFlyFrm* pFrm = pFmt->GetFrm( &aPt );
     870             : 
     871           0 :         if( pFrm )
     872           0 :             SelectFlyFrm( *pFrm, sal_True );
     873             :         else
     874           0 :             GetLayout()->SetAssertFlyPages();
     875             :     }
     876             : 
     877           0 :     return pFmt;
     878             : }
     879             : 
     880             : 
     881           0 : void SwFEShell::InsertDrawObj( SdrObject& rDrawObj,
     882             :                                const Point& rInsertPosition )
     883             : {
     884           0 :     SET_CURR_SHELL( this );
     885             : 
     886           0 :     SfxItemSet rFlyAttrSet( GetDoc()->GetAttrPool(), aFrmFmtSetRange );
     887           0 :     rFlyAttrSet.Put( SwFmtAnchor( FLY_AT_PARA ));
     888             :     // #i89920#
     889           0 :     rFlyAttrSet.Put( SwFmtSurround( SURROUND_THROUGHT ) );
     890           0 :     rDrawObj.SetLayer( getIDocumentDrawModelAccess()->GetHeavenId() );
     891             : 
     892             :     // find anchor position
     893           0 :     SwPaM aPam( pDoc->GetNodes() );
     894             :     {
     895           0 :         SwCrsrMoveState aState( MV_SETONLYTEXT );
     896           0 :         Point aTmpPt( rInsertPosition );
     897           0 :         GetLayout()->GetCrsrOfst( aPam.GetPoint(), aTmpPt, &aState );
     898           0 :         const SwFrm* pFrm = aPam.GetCntntNode()->getLayoutFrm( GetLayout(), 0, 0, sal_False );
     899           0 :         const Point aRelPos( rInsertPosition.X() - pFrm->Frm().Left(),
     900           0 :                              rInsertPosition.Y() - pFrm->Frm().Top() );
     901           0 :         rDrawObj.SetRelativePos( aRelPos );
     902           0 :         ::lcl_FindAnchorPos( *GetDoc(), rInsertPosition, *pFrm, rFlyAttrSet );
     903             :     }
     904             :     // insert drawing object into the document creating a new <SwDrawFrmFmt> instance
     905           0 :     SwDrawFrmFmt* pFmt = GetDoc()->Insert( aPam, rDrawObj, &rFlyAttrSet, 0 );
     906             : 
     907             :     // move object to visible layer
     908           0 :     SwContact* pContact = static_cast<SwContact*>(rDrawObj.GetUserCall());
     909           0 :     if ( pContact )
     910             :     {
     911           0 :         pContact->MoveObjToVisibleLayer( &rDrawObj );
     912             :     }
     913             : 
     914           0 :     if ( pFmt )
     915             :     {
     916             :         // select drawing object
     917           0 :         Imp()->GetDrawView()->MarkObj( &rDrawObj, Imp()->GetPageView(),
     918           0 :                                        sal_False, sal_False );
     919             :     }
     920             :     else
     921             :     {
     922           0 :         GetLayout()->SetAssertFlyPages();
     923           0 :     }
     924           0 : }
     925             : 
     926             : /***********************************************************************
     927             : #*  Class       :  SwFEShell
     928             : #*  Methode     :  GetPageObjs
     929             : #***********************************************************************/
     930             : 
     931           0 : void SwFEShell::GetPageObjs( std::vector<SwFrmFmt*>& rFillArr )
     932             : {
     933           0 :     rFillArr.clear();
     934             : 
     935           0 :     for( sal_uInt16 n = 0; n < pDoc->GetSpzFrmFmts()->size(); ++n )
     936             :     {
     937           0 :         SwFrmFmt* pFmt = (*pDoc->GetSpzFrmFmts())[n];
     938           0 :         if (FLY_AT_PAGE == pFmt->GetAnchor().GetAnchorId())
     939             :         {
     940           0 :             rFillArr.push_back( pFmt );
     941             :         }
     942             :     }
     943           0 : }
     944             : 
     945             : /***********************************************************************
     946             : #*  Class       :  SwFEShell
     947             : #*  Methode     :  SetPageFlysNewPage
     948             : #***********************************************************************/
     949             : 
     950           0 : void SwFEShell::SetPageObjsNewPage( std::vector<SwFrmFmt*>& rFillArr, int nOffset )
     951             : {
     952           0 :     if( rFillArr.empty() || !nOffset )
     953           0 :         return;
     954             : 
     955           0 :     StartAllAction();
     956           0 :     StartUndo();
     957             : 
     958             :     long nNewPage;
     959           0 :     SwRootFrm* pTmpRootFrm = GetLayout();//swmod 080317
     960           0 :     sal_uInt16 nMaxPage = pTmpRootFrm->GetPageNum();
     961           0 :     bool bTmpAssert = false;
     962           0 :     for( sal_uInt16 n = 0; n < rFillArr.size(); ++n )
     963             :     {
     964           0 :         SwFrmFmt* pFmt = rFillArr[n];
     965           0 :         if( pDoc->GetSpzFrmFmts()->Contains( pFmt ))
     966             :         {
     967             :             // FlyFmt is still valid, therefore process
     968             : 
     969           0 :             SwFmtAnchor aNewAnchor( pFmt->GetAnchor() );
     970           0 :             if ((FLY_AT_PAGE != aNewAnchor.GetAnchorId()) ||
     971           0 :                 0 >= ( nNewPage = aNewAnchor.GetPageNum() + nOffset ) )
     972             :                 // chaos::Anchor has been changed or invalid page number,
     973             :                 // therefore: do not change!
     974           0 :                 continue;
     975             : 
     976           0 :             if( sal_uInt16(nNewPage) > nMaxPage )
     977             :             {
     978           0 :                 if ( RES_DRAWFRMFMT == pFmt->Which() )
     979             :                 {
     980           0 :                     SwContact *pCon = pFmt->FindContactObj();
     981           0 :                     if( pCon )
     982           0 :                         ((SwDrawContact*)pCon)->DisconnectFromLayout();
     983             :                 }
     984             :                 else
     985           0 :                     pFmt->DelFrms();
     986           0 :                 bTmpAssert = true;
     987             :             }
     988           0 :             aNewAnchor.SetPageNum( sal_uInt16(nNewPage) );
     989           0 :             pDoc->SetAttr( aNewAnchor, *pFmt );
     990             :         }
     991             :     }
     992             : 
     993           0 :     if( bTmpAssert )
     994           0 :         pTmpRootFrm->SetAssertFlyPages();
     995             : 
     996           0 :     EndUndo();
     997           0 :     EndAllAction();
     998             : }
     999             : 
    1000             : /***********************************************************************
    1001             : #*  Class       :  SwFEShell
    1002             : #*  Methode     :  GetFlyFrmAttr
    1003             : #*  Description :  all attributes in the "baskets" will be filled
    1004             : #*                 with the attributes of the current FlyFrms.
    1005             : #*                 Attributes which cannot be filled due to being at the wrong place
    1006             : #*                 or which are ambiguous (multiple selections) will be removed.
    1007             : #*
    1008             : #***********************************************************************/
    1009             : 
    1010           0 : sal_Bool SwFEShell::GetFlyFrmAttr( SfxItemSet &rSet ) const
    1011             : {
    1012           0 :     SwFlyFrm *pFly = FindFlyFrm();
    1013           0 :     if ( !pFly )
    1014             :     {
    1015           0 :         SwFrm* pCurrFrm( GetCurrFrm() );
    1016           0 :         if ( !pCurrFrm )
    1017             :         {
    1018             :             OSL_FAIL( "<SwFEShell::GetFlyFrmAttr(..)> - missing current frame. This is a serious defect, please inform OD." );
    1019           0 :             return sal_False;
    1020             :         }
    1021           0 :         pFly = GetCurrFrm()->FindFlyFrm();
    1022           0 :         if ( !pFly )
    1023             :         {
    1024             :             OSL_ENSURE( !this, "GetFlyFrmAttr, no Fly selected." );
    1025           0 :             return sal_False;
    1026             :         }
    1027             :     }
    1028             : 
    1029           0 :     SET_CURR_SHELL( (ViewShell*)this );
    1030             : 
    1031           0 :     if( !rSet.Set( pFly->GetFmt()->GetAttrSet(), sal_True ) )
    1032           0 :         return sal_False;
    1033             : 
    1034             :     // now examine all attributes. Remove forbidden attributes, then
    1035             :     // get all remaining attributes and enter them
    1036             :     const SfxPoolItem* pItem;
    1037           0 :     if( SFX_ITEM_SET == rSet.GetItemState( RES_ANCHOR, sal_False, &pItem ) )
    1038             :     {
    1039           0 :         SwFmtAnchor* pAnchor = (SwFmtAnchor*)pItem;
    1040           0 :         RndStdIds eType = pAnchor->GetAnchorId();
    1041             : 
    1042           0 :         if ( FLY_AT_PAGE != eType )
    1043             :         {
    1044             :             // OD 12.11.2003 #i22341# - content anchor of anchor item is needed.
    1045             :             // Thus, don't overwrite anchor item by default contructed anchor item.
    1046           0 :             if ( FLY_AS_CHAR == eType )
    1047             :             {
    1048           0 :                 rSet.ClearItem( RES_OPAQUE );
    1049           0 :                 rSet.ClearItem( RES_SURROUND );
    1050             :             }
    1051             :         }
    1052             :     }
    1053           0 :     rSet.SetParent( pFly->GetFmt()->GetAttrSet().GetParent() );
    1054             :     // attributes must be removed
    1055           0 :     rSet.ClearItem( RES_FILL_ORDER );
    1056           0 :     rSet.ClearItem( RES_CNTNT );
    1057             :     //MA: remove first (Template by example etc.)
    1058           0 :     rSet.ClearItem( RES_CHAIN );
    1059           0 :     return sal_True;
    1060             : }
    1061             : /***********************************************************************
    1062             : #*  Class       :  SwFEShell
    1063             : #*  Methode     :  SetFlyFrmAttr
    1064             : #*  Description :  Attributes of the current fly will change.
    1065             : #***********************************************************************/
    1066             : 
    1067           0 : bool SwFEShell::SetFlyFrmAttr( SfxItemSet& rSet )
    1068             : {
    1069           0 :     SET_CURR_SHELL( this );
    1070           0 :     bool bRet = false;
    1071             : 
    1072           0 :     if( rSet.Count() )
    1073             :     {
    1074           0 :         SwFlyFrm *pFly = FindFlyFrm();
    1075           0 :         if( !pFly )
    1076             :         {
    1077             :             OSL_ENSURE( GetCurrFrm(), "Crsr in parking zone" );
    1078           0 :             pFly = GetCurrFrm()->FindFlyFrm();
    1079             :             OSL_ENSURE( pFly, "SetFlyFrmAttr, no Fly selected." );
    1080             :         }
    1081           0 :         if( pFly )
    1082             :         {
    1083           0 :             StartAllAction();
    1084           0 :             const Point aPt( pFly->Frm().Pos() );
    1085             : 
    1086           0 :             if( SFX_ITEM_SET == rSet.GetItemState( RES_ANCHOR, sal_False ))
    1087           0 :                 sw_ChkAndSetNewAnchor( *pFly, rSet );
    1088           0 :             SwFlyFrmFmt* pFlyFmt = (SwFlyFrmFmt*)pFly->GetFmt();
    1089             : 
    1090           0 :             if( GetDoc()->SetFlyFrmAttr( *pFlyFmt, rSet ))
    1091             :             {
    1092           0 :                 bRet = true;
    1093           0 :                 SwFlyFrm* pFrm = pFlyFmt->GetFrm( &aPt );
    1094           0 :                 if( pFrm )
    1095           0 :                     SelectFlyFrm( *pFrm, sal_True );
    1096             :                 else
    1097           0 :                     GetLayout()->SetAssertFlyPages();
    1098             :             }
    1099             : 
    1100           0 :             EndAllActionAndCall();
    1101             :         }
    1102             :     }
    1103           0 :     return bRet;
    1104             : }
    1105             : 
    1106           0 : sal_Bool SwFEShell::SetDrawingAttr( SfxItemSet& rSet )
    1107             : {
    1108           0 :     sal_Bool bRet = sal_False;
    1109           0 :     SET_CURR_SHELL( this );
    1110           0 :     if ( !rSet.Count() ||
    1111           0 :             !Imp()->HasDrawView() )
    1112           0 :         return bRet;
    1113             : 
    1114           0 :     const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
    1115           0 :     if ( rMrkList.GetMarkCount() != 1 )
    1116           0 :         return bRet;
    1117             : 
    1118           0 :     StartUndo();
    1119           0 :     SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
    1120           0 :     SwFrmFmt *pFmt = FindFrmFmt( pObj );
    1121           0 :     StartAllAction();
    1122           0 :     if( SFX_ITEM_SET == rSet.GetItemState( RES_ANCHOR, sal_False ))
    1123             :     {
    1124           0 :         RndStdIds nNew = ((SwFmtAnchor&)rSet.Get( RES_ANCHOR )).GetAnchorId();
    1125           0 :         if ( nNew != pFmt->GetAnchor().GetAnchorId() )
    1126             :         {
    1127           0 :             ChgAnchor( nNew );
    1128             :             // #i26791# - clear anchor attribute in item set,
    1129             :             // because method <ChgAnchor(..)> takes care of it.
    1130           0 :             rSet.ClearItem( RES_ANCHOR );
    1131             :         }
    1132             :     }
    1133             : 
    1134           0 :     if( GetDoc()->SetFlyFrmAttr( *pFmt, rSet ))
    1135             :     {
    1136           0 :         bRet = sal_True;
    1137           0 :         Point aTmp;
    1138           0 :         SelectObj( aTmp, 0, pObj );
    1139             :     }
    1140           0 :     EndAllActionAndCall();
    1141           0 :     EndUndo();
    1142           0 :     return bRet;
    1143             : }
    1144             : 
    1145             : 
    1146             : /***********************************************************************
    1147             : #*  Class       :  SwFEShell
    1148             : #*  Methode     :  ResetFlyFrmAttr
    1149             : #*  Description :  Reset requested attributes or the ones contained in
    1150             : #*                 the set.
    1151             : #***********************************************************************/
    1152             : 
    1153           0 : sal_Bool SwFEShell::ResetFlyFrmAttr( sal_uInt16 nWhich, const SfxItemSet* pSet )
    1154             : {
    1155           0 :     sal_Bool bRet = sal_False;
    1156             : 
    1157           0 :     if( RES_ANCHOR != nWhich && RES_CHAIN != nWhich && RES_CNTNT != nWhich )
    1158             :     {
    1159           0 :         SET_CURR_SHELL( this );
    1160             : 
    1161           0 :         SwFlyFrm *pFly = FindFlyFrm();
    1162           0 :         if( !pFly )
    1163             :         {
    1164             :             OSL_ENSURE( GetCurrFrm(), "Crsr in parking zone" );
    1165           0 :             pFly = GetCurrFrm()->FindFlyFrm();
    1166             :             OSL_ENSURE( pFly, "SetFlyFrmAttr, no Fly selected." );
    1167             :         }
    1168             : 
    1169           0 :         if( pFly )
    1170             :         {
    1171           0 :             StartAllAction();
    1172             : 
    1173           0 :             if( pSet )
    1174             :             {
    1175           0 :                 SfxItemIter aIter( *pSet );
    1176           0 :                 const SfxPoolItem* pItem = aIter.FirstItem();
    1177           0 :                 while( pItem )
    1178             :                 {
    1179           0 :                     if( !IsInvalidItem( pItem ) &&
    1180             :                         RES_ANCHOR != ( nWhich = pItem->Which() ) &&
    1181             :                         RES_CHAIN != nWhich && RES_CNTNT != nWhich )
    1182           0 :                         pFly->GetFmt()->ResetFmtAttr( nWhich );
    1183           0 :                     pItem = aIter.NextItem();
    1184           0 :                 }
    1185             :             }
    1186             :             else
    1187           0 :                 pFly->GetFmt()->ResetFmtAttr( nWhich );
    1188             : 
    1189           0 :             bRet = sal_True;
    1190           0 :             EndAllActionAndCall();
    1191           0 :             GetDoc()->SetModified();
    1192           0 :         }
    1193             :     }
    1194           0 :     return bRet;
    1195             : }
    1196             : 
    1197             : /***********************************************************************
    1198             : #*  Class       :  SwFEShell
    1199             : #*  Methode     :  GetCurFrmFmt
    1200             : #*  Description :  Returns frame-format if frame, otherwise 0
    1201             : #***********************************************************************/
    1202             : 
    1203           0 : SwFrmFmt* SwFEShell::GetCurFrmFmt() const
    1204             : {
    1205           0 :     SwFrmFmt* pRet = 0;
    1206           0 :     SwLayoutFrm *pFly = FindFlyFrm();
    1207           0 :     if( pFly && ( pRet = (SwFrmFmt*)pFly->GetFmt()->DerivedFrom() ) ==
    1208           0 :                                             GetDoc()->GetDfltFrmFmt() )
    1209           0 :         pRet = 0;
    1210           0 :     return pRet;
    1211             : }
    1212             : 
    1213             : /******************************************************************************
    1214             :  *  Methode     :   void SwFEShell::SetFrmFmt(SwFrmFmt *pNewFmt)
    1215             :  *  Description :
    1216             :  ******************************************************************************/
    1217             : 
    1218           0 : void SwFEShell::SetFrmFmt( SwFrmFmt *pNewFmt, bool bKeepOrient, Point* pDocPos )
    1219             : {
    1220           0 :     SwFlyFrm *pFly = 0;
    1221           0 :     if(pDocPos)
    1222             :     {
    1223           0 :         const SwFrmFmt* pFmt = GetFmtFromObj( *pDocPos );
    1224             : 
    1225           0 :         if(PTR_CAST(SwFlyFrmFmt, pFmt))
    1226           0 :             pFly = ((SwFlyFrmFmt*)pFmt)->GetFrm();
    1227             :     }
    1228             :     else
    1229           0 :         pFly = FindFlyFrm();
    1230             :     OSL_ENSURE( pFly, "SetFrmFmt: no frame" );
    1231           0 :     if( pFly )
    1232             :     {
    1233           0 :         StartAllAction();
    1234           0 :         SET_CURR_SHELL( this );
    1235             : 
    1236           0 :         SwFlyFrmFmt* pFlyFmt = (SwFlyFrmFmt*)pFly->GetFmt();
    1237           0 :         const Point aPt( pFly->Frm().Pos() );
    1238             : 
    1239           0 :         SfxItemSet* pSet = 0;
    1240             :         const SfxPoolItem* pItem;
    1241           0 :         if( SFX_ITEM_SET == pNewFmt->GetItemState( RES_ANCHOR, sal_False, &pItem ))
    1242             :         {
    1243           0 :             pSet = new SfxItemSet( GetDoc()->GetAttrPool(), aFrmFmtSetRange );
    1244           0 :             pSet->Put( *pItem );
    1245           0 :             if( !sw_ChkAndSetNewAnchor( *pFly, *pSet ))
    1246           0 :                 delete pSet, pSet = 0;
    1247             :         }
    1248             : 
    1249           0 :         if( GetDoc()->SetFrmFmtToFly( *pFlyFmt, *pNewFmt, pSet, bKeepOrient ))
    1250             :         {
    1251           0 :             SwFlyFrm* pFrm = pFlyFmt->GetFrm( &aPt );
    1252           0 :             if( pFrm )
    1253           0 :                 SelectFlyFrm( *pFrm, sal_True );
    1254             :             else
    1255           0 :                 GetLayout()->SetAssertFlyPages();
    1256             :         }
    1257           0 :         delete pSet;
    1258             : 
    1259           0 :         EndAllActionAndCall();
    1260             :     }
    1261           0 : }
    1262             : 
    1263             : /*************************************************************************
    1264             : |*
    1265             : |*  SwFEShell::GetFlyFrmFmt()
    1266             : |*
    1267             : *************************************************************************/
    1268             : 
    1269           0 : const SwFrmFmt* SwFEShell::GetFlyFrmFmt() const
    1270             : {
    1271           0 :     const SwFlyFrm* pFly = FindFlyFrm();
    1272           0 :     if ( !pFly )
    1273             :     {
    1274           0 :         SwFrm* pCurrFrm = GetCurrFrm();
    1275           0 :         pFly = pCurrFrm ? pCurrFrm->FindFlyFrm() : 0;
    1276             :     }
    1277           0 :     if( pFly )
    1278           0 :         return pFly->GetFmt();
    1279           0 :     return 0;
    1280             : }
    1281             : 
    1282           0 : SwFrmFmt* SwFEShell::GetFlyFrmFmt()
    1283             : {
    1284           0 :     SwFlyFrm* pFly = FindFlyFrm();
    1285           0 :     if ( !pFly )
    1286             :     {
    1287           0 :         SwFrm* pCurrFrm = GetCurrFrm();
    1288           0 :         pFly = pCurrFrm ? pCurrFrm->FindFlyFrm() : 0;
    1289             :     }
    1290           0 :     if( pFly )
    1291           0 :         return pFly->GetFmt();
    1292           0 :     return 0;
    1293             : }
    1294             : 
    1295             : /*************************************************************************
    1296             : |*
    1297             : |*  SwFEShell::GetFlyRect()
    1298             : |*
    1299             : *************************************************************************/
    1300             : 
    1301           0 : SwRect SwFEShell::GetFlyRect() const
    1302             : {
    1303           0 :     SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
    1304           0 :     SwFlyFrm *pFly = pCntnt ? pCntnt->FindFlyFrm() : 0;
    1305           0 :     if ( !pFly )
    1306             :     {
    1307           0 :         SwRect aRect;
    1308           0 :         return aRect;
    1309             :     }
    1310             :     else
    1311           0 :         return pFly->Frm();
    1312             : }
    1313             : 
    1314             : /*************************************************************************
    1315             : |*
    1316             : |*  SwFEShell::GetObjRect()
    1317             : |*
    1318             : *************************************************************************/
    1319             : 
    1320           0 : SwRect SwFEShell::GetObjRect() const
    1321             : {
    1322           0 :     if( Imp()->HasDrawView() )
    1323           0 :         return Imp()->GetDrawView()->GetAllMarkedRect();
    1324             :     else
    1325             :     {
    1326           0 :         SwRect aRect;
    1327           0 :         return aRect;
    1328             :     }
    1329             : }
    1330             : 
    1331           0 : void SwFEShell::SetObjRect( const SwRect& rRect )
    1332             : {
    1333           0 :     if ( Imp()->HasDrawView() )
    1334             :     {
    1335           0 :         Imp()->GetDrawView()->SetAllMarkedRect( rRect.SVRect() );
    1336           0 :         CallChgLnk();   // call AttrChangeNotify on the UI-side.
    1337             :     }
    1338           0 : }
    1339             : 
    1340             : /***********************************************************************
    1341             : #*  Class       :  SwFEShell
    1342             : #*  Methode     :  RequestObjectResize()
    1343             : #***********************************************************************/
    1344             : 
    1345           0 : Size SwFEShell::RequestObjectResize( const SwRect &rRect, const uno::Reference < embed::XEmbeddedObject >& xObj )
    1346             : {
    1347           0 :     Size aResult;
    1348             : 
    1349           0 :     SwFlyFrm *pFly = FindFlyFrm( xObj );
    1350           0 :     if ( !pFly )
    1351             :     {
    1352           0 :         aResult = rRect.SSize();
    1353             :         return aResult;
    1354             :     }
    1355             : 
    1356           0 :     aResult = pFly->Prt().SSize();
    1357             : 
    1358           0 :     sal_Bool bPosProt = pFly->GetFmt()->GetProtect().IsPosProtected();
    1359           0 :     sal_Bool bSizeProt = pFly->GetFmt()->GetProtect().IsSizeProtected();
    1360             : 
    1361           0 :     StartAllAction();
    1362             : 
    1363             :     // MA we do not allow to clip the Fly, as the OLE server can
    1364             :     // request various wishes. Clipping is done via the formatting.
    1365             :     // Correct display is done by scaling.
    1366             :     // Scaling is done by SwNoTxtFrm::Format by calling
    1367             :     // SwWrtShell::CalcAndSetScale()
    1368           0 :     if ( rRect.SSize() != pFly->Prt().SSize() && !bSizeProt )
    1369             :     {
    1370           0 :          Size aSz( rRect.SSize() );
    1371             : 
    1372             :         //JP 28.02.2001: Task 74707 - ask for fly in fly with automatic size
    1373             :         //
    1374             :         const SwFrm* pAnchor;
    1375             :         const SwTxtNode* pTNd;
    1376             :         const SwpHints* pHts;
    1377           0 :         const SwFmtFrmSize& rFrmSz = pFly->GetFmt()->GetFrmSize();
    1378           0 :         if( bCheckForOLEInCaption &&
    1379           0 :             0 != rFrmSz.GetWidthPercent() &&
    1380           0 :             0 != (pAnchor = pFly->GetAnchorFrm()) &&
    1381           0 :             pAnchor->IsTxtFrm() &&
    1382           0 :             !pAnchor->GetNext() && !pAnchor->GetPrev() &&
    1383           0 :             pAnchor->GetUpper()->IsFlyFrm() &&
    1384           0 :             0 != ( pTNd = ((SwTxtFrm*)pAnchor)->GetNode()->GetTxtNode()) &&
    1385             :             0 != ( pHts = pTNd->GetpSwpHints() ))
    1386             :         {
    1387             :             // search for a sequence field:
    1388             :             const SfxPoolItem* pItem;
    1389           0 :             for( sal_uInt16 n = 0, nEnd = pHts->Count(); n < nEnd; ++n )
    1390           0 :                 if( RES_TXTATR_FIELD == ( pItem =
    1391           0 :                             &(*pHts)[ n ]->GetAttr())->Which() &&
    1392           0 :                     TYP_SEQFLD == ((SwFmtFld*)pItem)->GetFld()->GetTypeId() )
    1393             :                 {
    1394             :                     // sequence field found
    1395           0 :                     SwFlyFrm* pChgFly = (SwFlyFrm*)pAnchor->GetUpper();
    1396             :                     // calculate the changed size:
    1397             :                     // width must change, height can change
    1398           0 :                     Size aNewSz( aSz.Width() + pChgFly->Frm().Width() -
    1399           0 :                                    pFly->Prt().Width(), aSz.Height() );
    1400             : 
    1401           0 :                     SwFrmFmt *pFmt = pChgFly->GetFmt();
    1402           0 :                     SwFmtFrmSize aFrmSz( pFmt->GetFrmSize() );
    1403           0 :                     aFrmSz.SetWidth( aNewSz.Width() );
    1404           0 :                     if( ATT_MIN_SIZE != aFrmSz.GetHeightSizeType() )
    1405             :                     {
    1406           0 :                         aNewSz.Height() += pChgFly->Frm().Height() -
    1407           0 :                                                pFly->Prt().Height();
    1408           0 :                         if( Abs( aNewSz.Height() - pChgFly->Frm().Height()) > 1 )
    1409           0 :                             aFrmSz.SetHeight( aNewSz.Height() );
    1410             :                     }
    1411             :                     // via Doc for the Undo!
    1412           0 :                     pFmt->GetDoc()->SetAttr( aFrmSz, *pFmt );
    1413           0 :                     break;
    1414             :                 }
    1415             :         }
    1416             : 
    1417             :         // set the new Size at the fly themself
    1418           0 :         if ( pFly->Prt().Height() > 0 && pFly->Prt().Width() > 0 )
    1419             :         {
    1420           0 :             aSz.Width() += pFly->Frm().Width() - pFly->Prt().Width();
    1421           0 :             aSz.Height()+= pFly->Frm().Height()- pFly->Prt().Height();
    1422             :         }
    1423           0 :         aResult = pFly->ChgSize( aSz );
    1424             : 
    1425             :         // if the object changes, the contour is outside the object
    1426             :         OSL_ENSURE( pFly->Lower()->IsNoTxtFrm(), "Request without NoTxt" );
    1427           0 :         SwNoTxtNode *pNd = ((SwCntntFrm*)pFly->Lower())->GetNode()->GetNoTxtNode();
    1428             :         OSL_ENSURE( pNd, "Request without Node" );
    1429           0 :         pNd->SetContour( 0 );
    1430           0 :         ClrContourCache();
    1431             :     }
    1432             : 
    1433             :     // if only the size is to be adjusted, a position is transported with
    1434             :     // allocated values
    1435           0 :     Point aPt( pFly->Prt().Pos() );
    1436           0 :     aPt += pFly->Frm().Pos();
    1437           0 :     if ( rRect.Top() != LONG_MIN && rRect.Pos() != aPt && !bPosProt )
    1438             :     {
    1439           0 :         aPt = rRect.Pos();
    1440           0 :         aPt.X() -= pFly->Prt().Left();
    1441           0 :         aPt.Y() -= pFly->Prt().Top();
    1442             : 
    1443             :         // in case of paragraph-bound Flys, starting from the new position,
    1444             :         // a new anchor is to be set. The anchor and the new RelPos are
    1445             :         // calculated by the Fly and set
    1446           0 :         if( pFly->IsFlyAtCntFrm() )
    1447           0 :             ((SwFlyAtCntFrm*)pFly)->SetAbsPos( aPt );
    1448             :         else
    1449             :         {
    1450           0 :             const SwFrmFmt *pFmt = pFly->GetFmt();
    1451           0 :             const SwFmtVertOrient &rVert = pFmt->GetVertOrient();
    1452           0 :             const SwFmtHoriOrient &rHori = pFmt->GetHoriOrient();
    1453           0 :             const long lXDiff = aPt.X() - pFly->Frm().Left();
    1454           0 :             const long lYDiff = aPt.Y() - pFly->Frm().Top();
    1455           0 :             const Point aTmp( rHori.GetPos() + lXDiff,
    1456           0 :                               rVert.GetPos() + lYDiff );
    1457           0 :             pFly->ChgRelPos( aTmp );
    1458             :         }
    1459             :     }
    1460             : 
    1461           0 :     SwFlyFrmFmt *pFlyFrmFmt = pFly->GetFmt();
    1462             :     OSL_ENSURE( pFlyFrmFmt, "fly frame format missing!" );
    1463           0 :     if ( pFlyFrmFmt )
    1464           0 :         pFlyFrmFmt->SetLastFlyFrmPrtRectPos( pFly->Prt().Pos() ); //stores the value of last Prt rect
    1465             : 
    1466           0 :     EndAllAction();
    1467             : 
    1468             :     return aResult;
    1469             : }
    1470             : 
    1471             : 
    1472             : /***********************************************************************
    1473             : #*  Class       :  SwFEShell
    1474             : #*  Methode     :  WizzardFindCurFrmFmt
    1475             : #***********************************************************************/
    1476             : 
    1477           0 : SwFrmFmt* SwFEShell::WizzardGetFly()
    1478             : {
    1479             :     // do not search the Fly via the layout. Now we can delete a frame
    1480             :     // without a valid layout. ( e.g. for the wizards )
    1481           0 :     SwFrmFmts& rSpzArr = *pDoc->GetSpzFrmFmts();
    1482           0 :     sal_uInt16 nCnt = rSpzArr.size();
    1483           0 :     if( nCnt )
    1484             :     {
    1485           0 :         SwNodeIndex& rCrsrNd = GetCrsr()->GetPoint()->nNode;
    1486           0 :         if( rCrsrNd.GetIndex() > pDoc->GetNodes().GetEndOfExtras().GetIndex() )
    1487             :             // Cursor is in the body area!
    1488           0 :             return 0;
    1489             : 
    1490           0 :         for( sal_uInt16 n = 0; n < nCnt; ++n )
    1491             :         {
    1492           0 :             SwFrmFmt* pFmt = rSpzArr[ n ];
    1493           0 :             const SwNodeIndex* pIdx = pFmt->GetCntnt( sal_False ).GetCntntIdx();
    1494             :             SwStartNode* pSttNd;
    1495           0 :             if( pIdx &&
    1496           0 :                 0 != ( pSttNd = pIdx->GetNode().GetStartNode() ) &&
    1497           0 :                 pSttNd->GetIndex() < rCrsrNd.GetIndex() &&
    1498           0 :                 rCrsrNd.GetIndex() < pSttNd->EndOfSectionIndex() )
    1499             :             {
    1500             :                 // found: return immediately
    1501           0 :                 return pFmt;
    1502             :             }
    1503             :         }
    1504             :     }
    1505           0 :     return 0;
    1506             : }
    1507             : 
    1508           0 : void SwFEShell::SetFlyName( const String& rName )
    1509             : {
    1510           0 :     SwLayoutFrm *pFly = FindFlyFrm();
    1511           0 :     if( pFly )
    1512           0 :         GetDoc()->SetFlyName( *(SwFlyFrmFmt*)pFly->GetFmt(), rName );
    1513             :     else {
    1514             :         OSL_ENSURE( !this, "no FlyFrame selected" );
    1515             :     }
    1516           0 : }
    1517             : 
    1518           0 : const String& SwFEShell::GetFlyName() const
    1519             : {
    1520           0 :     SwLayoutFrm *pFly = FindFlyFrm();
    1521           0 :     if( pFly )
    1522           0 :         return pFly->GetFmt()->GetName();
    1523             : 
    1524             :     OSL_ENSURE( !this, "no FlyFrame selected" );
    1525           0 :     return aEmptyStr;
    1526             : }
    1527             : 
    1528             : 
    1529           0 : const uno::Reference < embed::XEmbeddedObject > SwFEShell::GetOleRef() const
    1530             : {
    1531           0 :     uno::Reference < embed::XEmbeddedObject > xObj;
    1532           0 :     SwFlyFrm * pFly = FindFlyFrm();
    1533           0 :     if (pFly && pFly->Lower() && pFly->Lower()->IsNoTxtFrm())
    1534             :     {
    1535           0 :         SwOLENode *pNd = ((SwNoTxtFrm*)pFly->Lower())->GetNode()->GetOLENode();
    1536           0 :         if (pNd)
    1537           0 :             xObj = pNd->GetOLEObj().GetOleRef();
    1538             :     }
    1539           0 :     return xObj;
    1540             : }
    1541             : 
    1542             : 
    1543           0 : String SwFEShell::GetUniqueGrfName() const
    1544             : {
    1545           0 :     return GetDoc()->GetUniqueGrfName();
    1546             : }
    1547             : 
    1548           0 : const SwFrmFmt* SwFEShell::IsURLGrfAtPos( const Point& rPt, String* pURL,
    1549             :                                         String *pTargetFrameName,
    1550             :                                         String *pDescription ) const
    1551             : {
    1552           0 :     if( !Imp()->HasDrawView() )
    1553           0 :         return 0;
    1554             : 
    1555             :     SdrObject* pObj;
    1556             :     SdrPageView* pPV;
    1557           0 :     const SwFrmFmt* pRet = 0;
    1558           0 :     SwDrawView *pDView = (SwDrawView*)Imp()->GetDrawView();
    1559             : 
    1560           0 :     sal_uInt16 nOld = pDView->GetHitTolerancePixel();
    1561           0 :     pDView->SetHitTolerancePixel( 2 );
    1562             : 
    1563           0 :     if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPV,SDRSEARCH_PICKMACRO ) &&
    1564           0 :         pObj->ISA(SwVirtFlyDrawObj) )
    1565             :     {
    1566           0 :         SwFlyFrm *pFly = ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm();
    1567           0 :         const SwFmtURL &rURL = pFly->GetFmt()->GetURL();
    1568           0 :         if( rURL.GetURL().Len() || rURL.GetMap() )
    1569             :         {
    1570           0 :             bool bSetTargetFrameName = pTargetFrameName != 0;
    1571           0 :             bool bSetDescription = pDescription != 0;
    1572           0 :             if ( rURL.GetMap() )
    1573             :             {
    1574           0 :                 IMapObject *pObject = pFly->GetFmt()->GetIMapObject( rPt, pFly );
    1575           0 :                 if ( pObject && pObject->GetURL().Len() )
    1576             :                 {
    1577           0 :                     if( pURL )
    1578           0 :                         *pURL = pObject->GetURL();
    1579           0 :                     if ( bSetTargetFrameName && pObject->GetTarget().Len() )
    1580             :                     {
    1581           0 :                         bSetTargetFrameName = false;
    1582           0 :                         *pTargetFrameName = pObject->GetTarget();
    1583             :                     }
    1584           0 :                     if ( bSetDescription )
    1585             :                     {
    1586           0 :                         bSetDescription = false;
    1587           0 :                         *pDescription = pObject->GetAltText();
    1588             :                     }
    1589           0 :                     pRet = pFly->GetFmt();
    1590             :                 }
    1591             :             }
    1592             :             else
    1593             :             {
    1594           0 :                 if( pURL )
    1595             :                 {
    1596           0 :                     *pURL = rURL.GetURL();
    1597           0 :                     if( rURL.IsServerMap() )
    1598             :                     {
    1599             :                        // append the relative pixel position !!
    1600           0 :                         Point aPt( rPt );
    1601           0 :                         aPt -= pFly->Frm().Pos();
    1602             :                         // without MapMode-Offset, without Offset, o ... !!!!!
    1603             :                         aPt = GetOut()->LogicToPixel(
    1604           0 :                                 aPt, MapMode( MAP_TWIP ) );
    1605           0 :                         ((( *pURL += '?' ) += String::CreateFromInt32( aPt.X() ))
    1606           0 :                                   += ',' ) += String::CreateFromInt32(aPt.Y() );
    1607             :                     }
    1608             :                 }
    1609           0 :                 pRet = pFly->GetFmt();
    1610             :             }
    1611           0 :             if ( bSetTargetFrameName )
    1612           0 :                 *pTargetFrameName = rURL.GetTargetFrameName();
    1613           0 :             if ( bSetDescription )
    1614           0 :                 *pDescription = pFly->GetFmt()->GetName();
    1615             :         }
    1616             :     }
    1617           0 :     pDView->SetHitTolerancePixel( nOld );
    1618           0 :     return pRet;
    1619             : }
    1620             : 
    1621           0 : const Graphic *SwFEShell::GetGrfAtPos( const Point &rPt,
    1622             :                                        String &rName, sal_Bool &rbLink ) const
    1623             : {
    1624           0 :     if( !Imp()->HasDrawView() )
    1625           0 :         return 0;
    1626             : 
    1627             :     SdrObject* pObj;
    1628             :     SdrPageView* pPV;
    1629           0 :     SwDrawView *pDView = (SwDrawView*)Imp()->GetDrawView();
    1630             : 
    1631           0 :     if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPV ) && pObj->ISA(SwVirtFlyDrawObj) )
    1632             :     {
    1633           0 :         SwFlyFrm *pFly = ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm();
    1634           0 :         if ( pFly->Lower() && pFly->Lower()->IsNoTxtFrm() )
    1635             :         {
    1636           0 :             SwGrfNode *pNd = ((SwCntntFrm*)pFly->Lower())->GetNode()->GetGrfNode();
    1637           0 :             if ( pNd )
    1638             :             {
    1639           0 :                 if ( pNd->IsGrfLink() )
    1640             :                 {
    1641             :                     // halfway ready graphic?
    1642           0 :                     ::sfx2::SvLinkSource* pLnkObj = pNd->GetLink()->GetObj();
    1643           0 :                     if( pLnkObj && pLnkObj->IsPending() )
    1644           0 :                         return 0;
    1645           0 :                     rbLink = sal_True;
    1646             :                 }
    1647             : 
    1648           0 :                 pNd->GetFileFilterNms( &rName, 0 );
    1649           0 :                 if ( !rName.Len() )
    1650           0 :                     rName = pFly->GetFmt()->GetName();
    1651           0 :                 pNd->SwapIn( sal_True );
    1652           0 :                 return &pNd->GetGrf();
    1653             :             }
    1654             :         }
    1655             :     }
    1656           0 :     return 0;
    1657             : }
    1658             : 
    1659             : 
    1660           0 : const SwFrmFmt* SwFEShell::GetFmtFromObj( const Point& rPt, SwRect** pRectToFill ) const
    1661             : {
    1662           0 :     SwFrmFmt* pRet = 0;
    1663             : 
    1664           0 :     if( Imp()->HasDrawView() )
    1665             :     {
    1666             :         SdrObject* pObj;
    1667             :         SdrPageView* pPView;
    1668             : 
    1669           0 :         SwDrawView *pDView = (SwDrawView*)Imp()->GetDrawView();
    1670             : 
    1671           0 :         sal_uInt16 nOld = pDView->GetHitTolerancePixel();
    1672             :         // tolerance for Drawing-SS
    1673           0 :         pDView->SetHitTolerancePixel( pDView->GetMarkHdlSizePixel()/2 );
    1674             : 
    1675           0 :         if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPView, SDRSEARCH_PICKMARKABLE ) )
    1676             :         {
    1677             :            // first check it:
    1678           0 :             if ( pObj->ISA(SwVirtFlyDrawObj) )
    1679           0 :                 pRet = ((SwVirtFlyDrawObj*)pObj)->GetFmt();
    1680           0 :             else if ( pObj->GetUserCall() ) //not for group objects
    1681           0 :                 pRet = ((SwDrawContact*)pObj->GetUserCall())->GetFmt();
    1682           0 :             if(pRet && pRectToFill)
    1683           0 :                 **pRectToFill = pObj->GetCurrentBoundRect();
    1684             :         }
    1685           0 :         pDView->SetHitTolerancePixel( nOld );
    1686             :     }
    1687           0 :     return pRet;
    1688             : }
    1689             : 
    1690             : // returns a format too, if the point is over the text of any fly
    1691           0 : const SwFrmFmt* SwFEShell::GetFmtFromAnyObj( const Point& rPt ) const
    1692             : {
    1693           0 :     const SwFrmFmt* pRet = GetFmtFromObj( rPt );
    1694           0 :     if( !pRet || RES_FLYFRMFMT == pRet->Which() )
    1695             :     {
    1696           0 :         SwPosition aPos( *GetCrsr()->GetPoint() );
    1697           0 :         Point aPt( rPt );
    1698           0 :         GetLayout()->GetCrsrOfst( &aPos, aPt );
    1699           0 :         SwCntntNode *pNd = aPos.nNode.GetNode().GetCntntNode();
    1700           0 :         SwFrm* pFrm = pNd->getLayoutFrm( GetLayout(), &rPt, 0, sal_False )->FindFlyFrm();
    1701           0 :         pRet = pFrm ? ((SwLayoutFrm*)pFrm)->GetFmt() : 0;
    1702             :     }
    1703           0 :     return pRet;
    1704             : }
    1705             : 
    1706           0 : ObjCntType SwFEShell::GetObjCntType( const SdrObject& rObj ) const
    1707             : {
    1708           0 :     ObjCntType eType = OBJCNT_NONE;
    1709             : 
    1710             :     // investigate 'master' drawing object, if method
    1711             :     // is called for a 'virtual' drawing object.
    1712             :     const SdrObject* pInvestigatedObj;
    1713           0 :     if ( rObj.ISA(SwDrawVirtObj) )
    1714             :     {
    1715           0 :         const SwDrawVirtObj* pDrawVirtObj = static_cast<const SwDrawVirtObj*>(&rObj);
    1716           0 :         pInvestigatedObj = &(pDrawVirtObj->GetReferencedObj());
    1717             :     }
    1718             :     else
    1719             :     {
    1720           0 :         pInvestigatedObj = &rObj;
    1721             :     }
    1722             : 
    1723           0 :     if( FmFormInventor == pInvestigatedObj->GetObjInventor() )
    1724             :     {
    1725           0 :         eType = OBJCNT_CONTROL;
    1726             :         uno::Reference< awt::XControlModel >  xModel =
    1727           0 :                 ((SdrUnoObj&)(*pInvestigatedObj)).GetUnoControlModel();
    1728           0 :         if( xModel.is() )
    1729             :         {
    1730           0 :             uno::Any aVal;
    1731           0 :             OUString sName(RTL_CONSTASCII_USTRINGPARAM("ButtonType"));
    1732           0 :             uno::Reference< beans::XPropertySet >  xSet(xModel, uno::UNO_QUERY);
    1733             : 
    1734           0 :             uno::Reference< beans::XPropertySetInfo >  xInfo = xSet->getPropertySetInfo();
    1735           0 :             if(xInfo->hasPropertyByName( sName ))
    1736             :             {
    1737           0 :                 beans::Property xProperty = xInfo->getPropertyByName( sName );
    1738           0 :                 aVal = xSet->getPropertyValue( sName );
    1739           0 :                 if( aVal.getValue() && form::FormButtonType_URL == *((form::FormButtonType*)aVal.getValue()) )
    1740           0 :                     eType = OBJCNT_URLBUTTON;
    1741           0 :             }
    1742           0 :         }
    1743             :     }
    1744           0 :     else if( pInvestigatedObj->ISA(SwVirtFlyDrawObj) )
    1745             :     {
    1746           0 :         SwFlyFrm *pFly = ((SwVirtFlyDrawObj&)(*pInvestigatedObj)).GetFlyFrm();
    1747           0 :         if ( pFly->Lower() && pFly->Lower()->IsNoTxtFrm() )
    1748             :         {
    1749           0 :             if ( ((SwCntntFrm*)pFly->Lower())->GetNode()->GetGrfNode() )
    1750           0 :                 eType = OBJCNT_GRF;
    1751             :             else
    1752           0 :                 eType = OBJCNT_OLE;
    1753             :         }
    1754             :         else
    1755           0 :             eType = OBJCNT_FLY;
    1756             :     }
    1757           0 :     else if ( pInvestigatedObj->ISA( SdrObjGroup ) )
    1758             :     {
    1759           0 :         SwDrawContact* pDrawContact( dynamic_cast<SwDrawContact*>(GetUserCall( pInvestigatedObj ) ) );
    1760           0 :         if ( !pDrawContact )
    1761             :         {
    1762             :             OSL_FAIL( "<SwFEShell::GetObjCntType(..)> - missing draw contact object" );
    1763           0 :             eType = OBJCNT_NONE;
    1764             :         }
    1765             :         else
    1766             :         {
    1767           0 :             SwFrmFmt* pFrmFmt( pDrawContact->GetFmt() );
    1768           0 :             if ( !pFrmFmt )
    1769             :             {
    1770             :                 OSL_FAIL( "<SwFEShell::GetObjCntType(..)> - missing frame format" );
    1771           0 :                 eType = OBJCNT_NONE;
    1772             :             }
    1773           0 :             else if ( FLY_AS_CHAR != pFrmFmt->GetAnchor().GetAnchorId() )
    1774             :             {
    1775           0 :                 eType = OBJCNT_GROUPOBJ;
    1776             :             }
    1777             :         }
    1778             :     }
    1779             :     else
    1780           0 :         eType = OBJCNT_SIMPLE;
    1781           0 :     return eType;
    1782             : }
    1783             : 
    1784           0 : ObjCntType SwFEShell::GetObjCntType( const Point &rPt, SdrObject *&rpObj ) const
    1785             : {
    1786           0 :     ObjCntType eType = OBJCNT_NONE;
    1787             : 
    1788           0 :     if( Imp()->HasDrawView() )
    1789             :     {
    1790             :         SdrObject* pObj;
    1791             :         SdrPageView* pPView;
    1792             : 
    1793           0 :         SwDrawView *pDView = (SwDrawView*)Imp()->GetDrawView();
    1794             : 
    1795           0 :         sal_uInt16 nOld = pDView->GetHitTolerancePixel();
    1796             :         // tolerance for Drawing-SS
    1797           0 :         pDView->SetHitTolerancePixel( pDView->GetMarkHdlSizePixel()/2 );
    1798             : 
    1799           0 :         if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPView, SDRSEARCH_PICKMARKABLE ) )
    1800           0 :             eType = GetObjCntType( *(rpObj = pObj) );
    1801             : 
    1802           0 :         pDView->SetHitTolerancePixel( nOld );
    1803             :     }
    1804           0 :     return eType;
    1805             : }
    1806             : 
    1807           0 : ObjCntType SwFEShell::GetObjCntTypeOfSelection( SdrObject** ppObj ) const
    1808             : {
    1809           0 :     ObjCntType eType = OBJCNT_NONE;
    1810             : 
    1811           0 :     if( Imp()->HasDrawView() )
    1812             :     {
    1813           0 :         const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
    1814           0 :         for( sal_uInt32 i = 0, nE = rMrkList.GetMarkCount(); i < nE; ++i )
    1815             :         {
    1816           0 :             SdrObject* pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
    1817           0 :             if( !pObj )
    1818           0 :                 continue;
    1819           0 :             ObjCntType eTmp = GetObjCntType( *pObj );
    1820           0 :             if( !i )
    1821             :             {
    1822           0 :                 eType = eTmp;
    1823           0 :                 if( ppObj ) *ppObj = pObj;
    1824             :             }
    1825           0 :             else if( eTmp != eType )
    1826             :             {
    1827           0 :                 eType = OBJCNT_DONTCARE;
    1828             :                 // once DontCare, always DontCare!
    1829           0 :                 break;
    1830             :             }
    1831             :         }
    1832             :     }
    1833           0 :     return eType;
    1834             : }
    1835             : 
    1836             : 
    1837           0 : sal_Bool SwFEShell::ReplaceSdrObj( const String& rGrfName, const String& rFltName,
    1838             :                                 const Graphic* pGrf )
    1839             : {
    1840           0 :     SET_CURR_SHELL( this );
    1841             : 
    1842           0 :     sal_Bool bRet = sal_False;
    1843             :     const SdrMarkList *pMrkList;
    1844           0 :     if( Imp()->HasDrawView() &&  1 ==
    1845           0 :         ( pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList())->GetMarkCount() )
    1846             :     {
    1847           0 :         SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
    1848           0 :         SwFrmFmt *pFmt = FindFrmFmt( pObj );
    1849             : 
    1850             :         // store attributes, then set the graphic
    1851           0 :         SfxItemSet aFrmSet( pDoc->GetAttrPool(),
    1852           0 :                             pFmt->GetAttrSet().GetRanges() );
    1853           0 :         aFrmSet.Set( pFmt->GetAttrSet() );
    1854             : 
    1855             :         // set size and position?
    1856           0 :         if( !pObj->ISA(SwVirtFlyDrawObj) )
    1857             :         {
    1858             :             // then let's do it:
    1859           0 :             const Rectangle &rBound = pObj->GetSnapRect();
    1860           0 :             Point aRelPos( pObj->GetRelativePos() );
    1861             : 
    1862           0 :             const long nWidth = rBound.Right()  - rBound.Left();
    1863           0 :             const long nHeight= rBound.Bottom() - rBound.Top();
    1864             :             aFrmSet.Put( SwFmtFrmSize( ATT_MIN_SIZE,
    1865             :                                 Max( nWidth,  long(MINFLY) ),
    1866           0 :                                 Max( nHeight, long(MINFLY) )));
    1867             : 
    1868           0 :             if( SFX_ITEM_SET != aFrmSet.GetItemState( RES_HORI_ORIENT ))
    1869           0 :                 aFrmSet.Put( SwFmtHoriOrient( aRelPos.X(), text::HoriOrientation::NONE, text::RelOrientation::FRAME ));
    1870             : 
    1871           0 :             if( SFX_ITEM_SET != aFrmSet.GetItemState( RES_VERT_ORIENT ))
    1872           0 :                 aFrmSet.Put( SwFmtVertOrient( aRelPos.Y(), text::VertOrientation::NONE, text::RelOrientation::FRAME ));
    1873             : 
    1874             :         }
    1875             : 
    1876           0 :         pObj->GetOrdNum();
    1877             : 
    1878           0 :         StartAllAction();
    1879           0 :         StartUndo();
    1880             : 
    1881             :         // delete "Sdr-Object", insert the graphic instead
    1882           0 :         DelSelectedObj();
    1883             : 
    1884           0 :         pFmt = GetDoc()->Insert( *GetCrsr(), rGrfName, rFltName, pGrf, &aFrmSet, NULL, NULL );
    1885             : 
    1886           0 :         EndUndo();
    1887           0 :         EndAllAction();
    1888           0 :         bRet = sal_True;
    1889             :     }
    1890           0 :     return bRet;
    1891             : }
    1892             : 
    1893           0 : static sal_uInt16 SwFmtGetPageNum(const SwFlyFrmFmt * pFmt)
    1894             : {
    1895             :     OSL_ENSURE(pFmt != NULL, "invalid argument");
    1896             : 
    1897           0 :     SwFlyFrm * pFrm = pFmt->GetFrm();
    1898             : 
    1899             :     sal_uInt16 aResult;
    1900             : 
    1901           0 :     if (pFrm != NULL)
    1902           0 :         aResult = pFrm->GetPhyPageNum();
    1903             :     else
    1904           0 :         aResult = pFmt->GetAnchor().GetPageNum();
    1905             : 
    1906           0 :     return aResult;
    1907             : }
    1908             : 
    1909             : #include <fmtcnct.hxx>
    1910             : 
    1911           0 : void SwFEShell::GetConnectableFrmFmts(SwFrmFmt & rFmt,
    1912             :                                       const String & rReference,
    1913             :                                       sal_Bool bSuccessors,
    1914             :                                       ::std::vector< String > & aPrevPageVec,
    1915             :                                       ::std::vector< String > & aThisPageVec,
    1916             :                                       ::std::vector< String > & aNextPageVec,
    1917             :                                       ::std::vector< String > & aRestVec)
    1918             : {
    1919           0 :     StartAction();
    1920             : 
    1921           0 :     SwFmtChain rChain = rFmt.GetChain();
    1922           0 :     SwFrmFmt * pOldChainNext = (SwFrmFmt *) rChain.GetNext();
    1923           0 :     SwFrmFmt * pOldChainPrev = (SwFrmFmt *) rChain.GetPrev();
    1924             : 
    1925           0 :     if (pOldChainNext)
    1926           0 :         pDoc->Unchain(rFmt);
    1927             : 
    1928           0 :     if (pOldChainPrev)
    1929           0 :         pDoc->Unchain(*pOldChainPrev);
    1930             : 
    1931           0 :     sal_uInt16 nCnt = pDoc->GetFlyCount(FLYCNTTYPE_FRM);
    1932             : 
    1933             :     /* potential successors resp. predecessors */
    1934           0 :     ::std::vector< const SwFrmFmt * > aTmpSpzArray;
    1935             : 
    1936           0 :     pDoc->FindFlyByName(rReference);
    1937             : 
    1938           0 :     for (sal_uInt16 n = 0; n < nCnt; n++)
    1939             :     {
    1940           0 :         const SwFrmFmt & rFmt1 = *(pDoc->GetFlyNum(n, FLYCNTTYPE_FRM));
    1941             : 
    1942             :         /*
    1943             :            pFmt is a potential successor of rFmt if it is chainable after
    1944             :            rFmt.
    1945             : 
    1946             :            pFmt is a potential predecessor of rFmt if rFmt is chainable
    1947             :            after pFmt.
    1948             :         */
    1949             : 
    1950             :         int nChainState;
    1951             : 
    1952           0 :         if (bSuccessors)
    1953           0 :             nChainState = pDoc->Chainable(rFmt, rFmt1);
    1954             :         else
    1955           0 :             nChainState = pDoc->Chainable(rFmt1, rFmt);
    1956             : 
    1957           0 :         if (nChainState == SW_CHAIN_OK)
    1958             :         {
    1959           0 :             aTmpSpzArray.push_back(&rFmt1);
    1960             : 
    1961             :         }
    1962             : 
    1963             :     }
    1964             : 
    1965           0 :     if  (aTmpSpzArray.size() > 0)
    1966             :     {
    1967           0 :         aPrevPageVec.clear();
    1968           0 :         aThisPageVec.clear();
    1969           0 :         aNextPageVec.clear();
    1970           0 :         aRestVec.clear();
    1971             : 
    1972             :         /* number of page rFmt resides on */
    1973           0 :         sal_uInt16 nPageNum = SwFmtGetPageNum((SwFlyFrmFmt *) &rFmt);
    1974             : 
    1975           0 :         ::std::vector< const SwFrmFmt * >::const_iterator aIt;
    1976             : 
    1977           0 :         for (aIt = aTmpSpzArray.begin(); aIt != aTmpSpzArray.end(); ++aIt)
    1978             :         {
    1979           0 :             String  aString = (*aIt)->GetName();
    1980             : 
    1981             :             /* rFmt is not a vaild successor or predecessor of
    1982             :                itself */
    1983           0 :             if (aString != rReference && aString != rFmt.GetName())
    1984             :             {
    1985             :                 sal_uInt16 nNum1 =
    1986           0 :                     SwFmtGetPageNum((SwFlyFrmFmt *) *aIt);
    1987             : 
    1988           0 :                 if (nNum1 == nPageNum -1)
    1989           0 :                     aPrevPageVec.push_back(aString);
    1990           0 :                 else if (nNum1 == nPageNum)
    1991           0 :                     aThisPageVec.push_back(aString);
    1992           0 :                 else if (nNum1 == nPageNum + 1)
    1993           0 :                     aNextPageVec.push_back(aString);
    1994             :                 else
    1995           0 :                     aRestVec.push_back(aString);
    1996             :             }
    1997           0 :         }
    1998             : 
    1999             :     }
    2000             : 
    2001           0 :     if (pOldChainNext)
    2002           0 :         pDoc->Chain(rFmt, *pOldChainNext);
    2003             : 
    2004           0 :     if (pOldChainPrev)
    2005           0 :         pDoc->Chain(*pOldChainPrev, rFmt);
    2006             : 
    2007           0 :     EndAction();
    2008           0 : }
    2009             : 
    2010             : // #i73249#
    2011           0 : const String SwFEShell::GetObjTitle() const
    2012             : {
    2013           0 :     String aTitle;
    2014             : 
    2015           0 :     if ( Imp()->HasDrawView() )
    2016             :     {
    2017           0 :         const SdrMarkList *pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
    2018           0 :         if ( pMrkList->GetMarkCount() == 1 )
    2019             :         {
    2020           0 :             const SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
    2021           0 :             const SwFrmFmt* pFmt = FindFrmFmt( pObj );
    2022           0 :             if ( pFmt->Which() == RES_FLYFRMFMT )
    2023             :             {
    2024           0 :                 aTitle = dynamic_cast<const SwFlyFrmFmt*>(pFmt)->GetObjTitle();
    2025             :             }
    2026             :             else
    2027             :             {
    2028           0 :                 aTitle = pObj->GetTitle();
    2029             :             }
    2030             :         }
    2031             :     }
    2032             : 
    2033           0 :     return aTitle;
    2034             : }
    2035             : 
    2036           0 : void SwFEShell::SetObjTitle( const String& rTitle )
    2037             : {
    2038           0 :     if ( Imp()->HasDrawView() )
    2039             :     {
    2040           0 :         const SdrMarkList *pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
    2041           0 :         if ( pMrkList->GetMarkCount() == 1 )
    2042             :         {
    2043           0 :             SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
    2044           0 :             SwFrmFmt* pFmt = FindFrmFmt( pObj );
    2045           0 :             if ( pFmt->Which() == RES_FLYFRMFMT )
    2046             :             {
    2047             :                 GetDoc()->SetFlyFrmTitle( *(dynamic_cast<SwFlyFrmFmt*>(pFmt)),
    2048           0 :                                           rTitle );
    2049             :             }
    2050             :             else
    2051             :             {
    2052           0 :                 pObj->SetTitle( rTitle );
    2053             :             }
    2054             :         }
    2055             :     }
    2056           0 : }
    2057             : 
    2058           0 : const String SwFEShell::GetObjDescription() const
    2059             : {
    2060           0 :     String aDescription;
    2061             : 
    2062           0 :     if ( Imp()->HasDrawView() )
    2063             :     {
    2064           0 :         const SdrMarkList *pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
    2065           0 :         if ( pMrkList->GetMarkCount() == 1 )
    2066             :         {
    2067           0 :             const SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
    2068           0 :             const SwFrmFmt* pFmt = FindFrmFmt( pObj );
    2069           0 :             if ( pFmt->Which() == RES_FLYFRMFMT )
    2070             :             {
    2071           0 :                 aDescription = dynamic_cast<const SwFlyFrmFmt*>(pFmt)->GetObjDescription();
    2072             :             }
    2073             :             else
    2074             :             {
    2075           0 :                 aDescription = pObj->GetDescription();
    2076             :             }
    2077             :         }
    2078             :     }
    2079             : 
    2080           0 :     return aDescription;
    2081             : }
    2082             : 
    2083           0 : void SwFEShell::SetObjDescription( const String& rDescription )
    2084             : {
    2085           0 :     if ( Imp()->HasDrawView() )
    2086             :     {
    2087           0 :         const SdrMarkList *pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
    2088           0 :         if ( pMrkList->GetMarkCount() == 1 )
    2089             :         {
    2090           0 :             SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
    2091           0 :             SwFrmFmt* pFmt = FindFrmFmt( pObj );
    2092           0 :             if ( pFmt->Which() == RES_FLYFRMFMT )
    2093             :             {
    2094             :                 GetDoc()->SetFlyFrmDescription( *(dynamic_cast<SwFlyFrmFmt*>(pFmt)),
    2095           0 :                                                 rDescription );
    2096             :             }
    2097             :             else
    2098             :             {
    2099           0 :                 pObj->SetDescription( rDescription );
    2100             :             }
    2101             :         }
    2102             :     }
    2103           0 : }
    2104             : 
    2105             : 
    2106           0 : void SwFEShell::AlignFormulaToBaseline( const uno::Reference < embed::XEmbeddedObject >& xObj, SwFlyFrm * pFly )
    2107             : {
    2108             : #if OSL_DEBUG_LEVEL > 0
    2109             :     SvGlobalName aCLSID( xObj->getClassID() );
    2110             :     const bool bStarMath = ( SotExchange::IsMath( aCLSID ) != 0 );
    2111             :     OSL_ENSURE( bStarMath, "AlignFormulaToBaseline should only be called for Math objects" );
    2112             : 
    2113             :     if ( !bStarMath )
    2114             :         return;
    2115             : #endif
    2116             : 
    2117           0 :     if (!pFly)
    2118           0 :         pFly = FindFlyFrm( xObj );
    2119             :     OSL_ENSURE( pFly , "No fly frame!" );
    2120           0 :     SwFrmFmt * pFrmFmt = pFly ? pFly->GetFmt() : 0;
    2121             : 
    2122             :     // baseline to baseline alignment should only be applied to formulas anchored as char
    2123           0 :     if ( pFly && pFrmFmt && FLY_AS_CHAR == pFrmFmt->GetAnchor().GetAnchorId() )
    2124             :     {
    2125             :         // get baseline from Math object
    2126           0 :         uno::Any aBaseline;
    2127           0 :         if( svt::EmbeddedObjectRef::TryRunningState( xObj ) )
    2128             :         {
    2129           0 :             uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
    2130           0 :             if ( xSet.is() )
    2131             :             {
    2132             :                 try
    2133             :                 {
    2134           0 :                     aBaseline = xSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BaseLine") ) );
    2135             :                 }
    2136           0 :                 catch ( uno::Exception& )
    2137             :                 {
    2138             :                     OSL_FAIL( "Baseline could not be retrieved from Starmath!" );
    2139             :                 }
    2140           0 :             }
    2141             :         }
    2142             : 
    2143           0 :         sal_Int32 nBaseline = ::comphelper::getINT32(aBaseline);
    2144           0 :         const MapMode aSourceMapMode( MAP_100TH_MM );
    2145           0 :         const MapMode aTargetMapMode( MAP_TWIP );
    2146           0 :         nBaseline = OutputDevice::LogicToLogic( nBaseline, aSourceMapMode.GetMapUnit(), aTargetMapMode.GetMapUnit() );
    2147             : 
    2148             :         OSL_ENSURE( nBaseline > 0, "Wrong value of Baseline while retrieving from Starmath!" );
    2149             :         //nBaseline must be moved by aPrt position
    2150           0 :         const SwFlyFrmFmt *pFlyFrmFmt = pFly->GetFmt();
    2151             :         OSL_ENSURE( pFlyFrmFmt, "fly frame format missing!" );
    2152           0 :         if ( pFlyFrmFmt )
    2153           0 :             nBaseline += pFlyFrmFmt->GetLastFlyFrmPrtRectPos().Y();
    2154             : 
    2155           0 :         const SwFmtVertOrient &rVert = pFrmFmt->GetVertOrient();
    2156           0 :         SwFmtVertOrient aVert( rVert );
    2157           0 :         aVert.SetPos( -nBaseline );
    2158           0 :         aVert.SetVertOrient( com::sun::star::text::VertOrientation::NONE );
    2159             : 
    2160           0 :         pFrmFmt->LockModify();
    2161           0 :         pFrmFmt->SetFmtAttr( aVert );
    2162           0 :         pFrmFmt->UnlockModify();
    2163           0 :         pFly->InvalidatePos();
    2164             :     }
    2165           0 : }
    2166             : 
    2167             : 
    2168           0 : void SwFEShell::AlignAllFormulasToBaseline()
    2169             : {
    2170           0 :     StartAllAction();
    2171             : 
    2172             :     SwStartNode *pStNd;
    2173           0 :     SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
    2174           0 :     while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
    2175             :     {
    2176           0 :         ++aIdx;
    2177           0 :         SwOLENode *pOleNode = dynamic_cast< SwOLENode * >( &aIdx.GetNode() );
    2178           0 :         if ( pOleNode )
    2179             :         {
    2180           0 :             const uno::Reference < embed::XEmbeddedObject > & xObj( pOleNode->GetOLEObj().GetOleRef() );
    2181           0 :             if (xObj.is())
    2182             :             {
    2183           0 :                 SvGlobalName aCLSID( xObj->getClassID() );
    2184           0 :                 if ( SotExchange::IsMath( aCLSID ) )
    2185           0 :                     AlignFormulaToBaseline( xObj );
    2186           0 :             }
    2187             :         }
    2188             : 
    2189           0 :         aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
    2190             :     }
    2191             : 
    2192           0 :     EndAllAction();
    2193           0 : }
    2194             : 
    2195             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10