Author: orw
Date: Tue Feb 18 11:47:13 2014
New Revision: 1569286

URL: http://svn.apache.org/r1569286
Log:
124188: <SwDoc::InsertDrawObj(..)> - assure correct insertion of text attribute 
for as-character anchored drawing objects

        Thx to Andre for his deep analysis.


Modified:
    openoffice/trunk/main/sw/inc/IDocumentContentOperations.hxx
    openoffice/trunk/main/sw/inc/doc.hxx
    openoffice/trunk/main/sw/source/core/doc/doclay.cxx
    openoffice/trunk/main/sw/source/core/frmedt/fecopy.cxx
    openoffice/trunk/main/sw/source/core/frmedt/fefly1.cxx
    openoffice/trunk/main/sw/source/core/unocore/unodraw.cxx
    openoffice/trunk/main/sw/source/filter/html/htmldraw.cxx
    openoffice/trunk/main/sw/source/filter/rtf/swparrtf.cxx
    openoffice/trunk/main/sw/source/filter/ww8/ww8graf.cxx
    openoffice/trunk/main/sw/source/filter/ww8/ww8graf2.cxx
    openoffice/trunk/main/sw/source/filter/ww8/ww8par4.cxx

Modified: openoffice/trunk/main/sw/inc/IDocumentContentOperations.hxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sw/inc/IDocumentContentOperations.hxx?rev=1569286&r1=1569285&r2=1569286&view=diff
==============================================================================
--- openoffice/trunk/main/sw/inc/IDocumentContentOperations.hxx (original)
+++ openoffice/trunk/main/sw/inc/IDocumentContentOperations.hxx Tue Feb 18 
11:47:13 2014
@@ -138,7 +138,7 @@ public:
     /** Einfuegen eines DrawObjectes. Das Object muss bereits im DrawModel
     angemeldet sein.
     */
-    virtual SwDrawFrmFmt* Insert(const SwPaM &rRg, SdrObject& rDrawObj, const 
SfxItemSet* pFlyAttrSet, SwFrmFmt*) = 0;
+    virtual SwDrawFrmFmt* InsertDrawObj( const SwPaM &rRg, SdrObject& 
rDrawObj, const SfxItemSet& rFlyAttrSet ) = 0;
 
     /** Einfuegen von OLE-Objecten.
     */

Modified: openoffice/trunk/main/sw/inc/doc.hxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sw/inc/doc.hxx?rev=1569286&r1=1569285&r2=1569286&view=diff
==============================================================================
--- openoffice/trunk/main/sw/inc/doc.hxx (original)
+++ openoffice/trunk/main/sw/inc/doc.hxx Tue Feb 18 11:47:13 2014
@@ -891,7 +891,10 @@ public:
                                                const SfxItemSet* pFlyAttrSet, 
const SfxItemSet* pGrfAttrSet, SwFrmFmt*);
        virtual SwFlyFrmFmt* Insert(const SwPaM& rRg, const GraphicObject& 
rGrfObj,     const SfxItemSet* pFlyAttrSet,
                                                const SfxItemSet* pGrfAttrSet, 
SwFrmFmt*);
-    virtual SwDrawFrmFmt* Insert(const SwPaM &rRg, SdrObject& rDrawObj, const 
SfxItemSet* pFlyAttrSet, SwFrmFmt*);
+    virtual SwDrawFrmFmt* InsertDrawObj(
+        const SwPaM &rRg,
+        SdrObject& rDrawObj,
+        const SfxItemSet& rFlyAttrSet );
     virtual SwFlyFrmFmt* Insert(const SwPaM &rRg, const 
svt::EmbeddedObjectRef& xObj, const SfxItemSet* pFlyAttrSet,
                                                const SfxItemSet* pGrfAttrSet, 
SwFrmFmt*);
 

Modified: openoffice/trunk/main/sw/source/core/doc/doclay.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/core/doc/doclay.cxx?rev=1569286&r1=1569285&r2=1569286&view=diff
==============================================================================
--- openoffice/trunk/main/sw/source/core/doc/doclay.cxx (original)
+++ openoffice/trunk/main/sw/source/core/doc/doclay.cxx Tue Feb 18 11:47:13 2014
@@ -923,97 +923,100 @@ if( GetIDocumentUndoRedo().DoesUndo() )
 }
 
 
-       //Einfuegen eines DrawObjectes. Das Object muss bereits im DrawModel
-       // angemeldet sein.
-SwDrawFrmFmt* SwDoc::Insert( const SwPaM &rRg,
-                                                        SdrObject& rDrawObj,
-                                                        const SfxItemSet* 
pFlyAttrSet,
-                                                        SwFrmFmt* pDefFmt )
-{
-       SwDrawFrmFmt *pFmt = MakeDrawFrmFmt( aEmptyStr,
-                                                                               
pDefFmt ? pDefFmt : GetDfltFrmFmt() );
-
-       const SwFmtAnchor* pAnchor = 0;
-       if( pFlyAttrSet )
-       {
-               pFlyAttrSet->GetItemState( RES_ANCHOR, sal_False,
-                                                                       (const 
SfxPoolItem**)&pAnchor );
-        pFmt->SetFmtAttr( *pFlyAttrSet );
-       }
+// Insert drawing object, which has to be already inserted in the DrawModel
+SwDrawFrmFmt* SwDoc::InsertDrawObj(
+    const SwPaM &rRg,
+    SdrObject& rDrawObj,
+    const SfxItemSet& rFlyAttrSet )
+{
+    SwDrawFrmFmt* pFmt = MakeDrawFrmFmt( aEmptyStr, GetDfltFrmFmt() );
+
+    const SwFmtAnchor* pAnchor = 0;
+    rFlyAttrSet.GetItemState( RES_ANCHOR, sal_False, (const SfxPoolItem**) 
&pAnchor );
+    pFmt->SetFmtAttr( rFlyAttrSet );
 
-       RndStdIds eAnchorId = pAnchor ? pAnchor->GetAnchorId()
-                                                                 : 
pFmt->GetAnchor().GetAnchorId();
-
-       // Anker noch nicht gesetzt ?
-       // DrawObjecte duerfen niemals in Kopf-/Fusszeilen landen.
+    RndStdIds eAnchorId = pAnchor != NULL ? pAnchor->GetAnchorId() : 
pFmt->GetAnchor().GetAnchorId();
     const bool bIsAtCntnt = (FLY_AT_PAGE != eAnchorId);
 
-       const SwNodeIndex* pChkIdx = 0;
-       if( !pAnchor )
+    const SwNodeIndex* pChkIdx = 0;
+    if ( pAnchor == NULL )
     {
-               pChkIdx = &rRg.GetPoint()->nNode;
+        pChkIdx = &rRg.GetPoint()->nNode;
     }
-       else if( bIsAtCntnt )
+    else if ( bIsAtCntnt )
     {
-               pChkIdx = pAnchor->GetCntntAnchor()
-                                       ? &pAnchor->GetCntntAnchor()->nNode
-                                       : &rRg.GetPoint()->nNode;
+        pChkIdx =
+            pAnchor->GetCntntAnchor() ? &pAnchor->GetCntntAnchor()->nNode : 
&rRg.GetPoint()->nNode;
     }
 
-    // OD 24.06.2003 #108784# - allow drawing objects in header/footer, but
-    // control objects aren't allowed in header/footer.
-    if( pChkIdx &&
-        ::CheckControlLayer( &rDrawObj ) &&
-        IsInHeaderFooter( *pChkIdx ) )
+    // allow drawing objects in header/footer, but control objects aren't 
allowed in header/footer.
+    if( pChkIdx != NULL
+        && ::CheckControlLayer( &rDrawObj )
+        && IsInHeaderFooter( *pChkIdx ) )
     {
-       pFmt->SetFmtAttr( SwFmtAnchor( eAnchorId = FLY_AT_PAGE ) );
+        // apply at-page anchor format
+        eAnchorId = FLY_AT_PAGE;
+        pFmt->SetFmtAttr( SwFmtAnchor( eAnchorId ) );
     }
-    else if( !pAnchor || (bIsAtCntnt && !pAnchor->GetCntntAnchor() ))
-       {
-               // dann setze ihn, wird im Undo gebraucht
-               SwFmtAnchor aAnch( pAnchor ? *pAnchor : pFmt->GetAnchor() );
-               eAnchorId = aAnch.GetAnchorId();
-               if( FLY_AT_FLY == eAnchorId )
-               {
-                       SwPosition aPos( *rRg.GetNode()->FindFlyStartNode() );
-                       aAnch.SetAnchor( &aPos );
-               }
-               else
-               {
-                       aAnch.SetAnchor( rRg.GetPoint() );
-            if ( FLY_AT_PAGE == eAnchorId )
-                       {
-                               eAnchorId = rDrawObj.ISA( SdrUnoObj )
-                                    ? FLY_AS_CHAR : FLY_AT_PARA;
-                               aAnch.SetType( eAnchorId );
-                       }
-               }
+    else if( pAnchor == NULL
+             || ( bIsAtCntnt
+                  && pAnchor->GetCntntAnchor() == NULL ) )
+    {
+        // apply anchor format
+        SwFmtAnchor aAnch( pAnchor != NULL ? *pAnchor : pFmt->GetAnchor() );
+        eAnchorId = aAnch.GetAnchorId();
+        if ( eAnchorId == FLY_AT_FLY )
+        {
+            SwPosition aPos( *rRg.GetNode()->FindFlyStartNode() );
+            aAnch.SetAnchor( &aPos );
+        }
+        else
+        {
+            aAnch.SetAnchor( rRg.GetPoint() );
+            if ( eAnchorId == FLY_AT_PAGE )
+            {
+                eAnchorId = rDrawObj.ISA( SdrUnoObj ) ? FLY_AS_CHAR : 
FLY_AT_PARA;
+                aAnch.SetType( eAnchorId );
+            }
+        }
         pFmt->SetFmtAttr( aAnch );
-       }
+    }
 
-       // bei als Zeichen gebundenen Draws das Attribut im Absatz setzen
-    if ( FLY_AS_CHAR == eAnchorId )
+    // insert text attribute for as-character anchored drawing object
+    if ( eAnchorId == FLY_AS_CHAR )
     {
-               xub_StrLen nStt = rRg.GetPoint()->nContent.GetIndex();
-        SwFmtFlyCnt aFmt( pFmt );
-        rRg.GetPoint()->nNode.GetNode().GetTxtNode()->InsertItem(
-                aFmt, nStt, nStt );
+        bool bAnchorAtPageAsFallback = true;
+        const SwFmtAnchor& rDrawObjAnchorFmt = pFmt->GetAnchor();
+        if ( rDrawObjAnchorFmt.GetCntntAnchor() != NULL )
+        {
+            SwTxtNode* pAnchorTxtNode =
+                    
rDrawObjAnchorFmt.GetCntntAnchor()->nNode.GetNode().GetTxtNode();
+            if ( pAnchorTxtNode != NULL )
+            {
+                const xub_StrLen nStt = 
rDrawObjAnchorFmt.GetCntntAnchor()->nContent.GetIndex();
+                SwFmtFlyCnt aFmt( pFmt );
+                pAnchorTxtNode->InsertItem( aFmt, nStt, nStt );
+                bAnchorAtPageAsFallback = false;
+            }
+        }
+
+        if ( bAnchorAtPageAsFallback )
+        {
+            ASSERT( false, "SwDoc::InsertDrawObj(..) - missing content anchor 
for as-character anchored drawing object --> anchor at-page" );
+            pFmt->SetFmtAttr( SwFmtAnchor( FLY_AT_PAGE ) );
+        }
     }
 
     SwDrawContact* pContact = new SwDrawContact( pFmt, &rDrawObj );
 
-       // ggfs. Frames anlegen
-       if( GetCurrentViewShell() )
+    if ( GetCurrentViewShell() )
     {
-               pFmt->MakeFrms();
-        // --> OD 2005-02-09 #i42319# - follow-up of #i35635#
-        // move object to visible layer
-        // --> OD 2007-07-10 #i79391#
+        // create layout representation
+        pFmt->MakeFrms();
         if ( pContact->GetAnchorFrm() )
         {
             pContact->MoveObjToVisibleLayer( &rDrawObj );
         }
-        // <--
     }
 
     if (GetIDocumentUndoRedo().DoesUndo())
@@ -1021,8 +1024,8 @@ SwDrawFrmFmt* SwDoc::Insert( const SwPaM
         GetIDocumentUndoRedo().AppendUndo( new SwUndoInsLayFmt(pFmt, 0, 0) );
     }
 
-       SetModified();
-       return pFmt;
+    SetModified();
+    return pFmt;
 }
 
 /*************************************************************************

Modified: openoffice/trunk/main/sw/source/core/frmedt/fecopy.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/core/frmedt/fecopy.cxx?rev=1569286&r1=1569285&r2=1569286&view=diff
==============================================================================
--- openoffice/trunk/main/sw/source/core/frmedt/fecopy.cxx (original)
+++ openoffice/trunk/main/sw/source/core/frmedt/fecopy.cxx Tue Feb 18 11:47:13 
2014
@@ -211,7 +211,7 @@ sal_Bool SwFEShell::Copy( SwDoc* pClpDoc
                     pClpDoc->CloneSdrObj( *pObj, sal_False, sal_True );
 
                 SwPaM aTemp(aPos);
-                pClpDoc->Insert(aTemp, *pNew, &aSet, NULL);
+                pClpDoc->InsertDrawObj(aTemp, *pNew, aSet );
                        }
                        else
                        {
@@ -396,8 +396,7 @@ sal_Bool SwFEShell::CopyDrawSel( SwFEShe
                                        aSet.Put( aAnchor );
                                        SdrObject* pNew = 
pDestDoc->CloneSdrObj( *pObj, bIsMove &&
                                                                                
                GetDoc() == pDestDoc, sal_True );
-                                       pFmt = pDestDoc->Insert( 
*pDestShell->GetCrsr(),
-                                                                               
        *pNew, &aSet, NULL );
+                                       pFmt = pDestDoc->InsertDrawObj( 
*pDestShell->GetCrsr(), *pNew, aSet );
                                }
                                else
                     pFmt = pDestDoc->CopyLayoutFmt( *pFmt, aAnchor, true, true 
);
@@ -1456,7 +1455,7 @@ void SwFEShell::Paste( SvStream& rStrm, 
 
                                        DelSelectedObj();
 
-                                       pFmt = GetDoc()->Insert( *GetCrsr(), 
*pNewObj, &aFrmSet, NULL );
+                                       pFmt = GetDoc()->InsertDrawObj( 
*GetCrsr(), *pNewObj, aFrmSet );
                                }
                                else
                 {

Modified: openoffice/trunk/main/sw/source/core/frmedt/fefly1.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/core/frmedt/fefly1.cxx?rev=1569286&r1=1569285&r2=1569286&view=diff
==============================================================================
--- openoffice/trunk/main/sw/source/core/frmedt/fefly1.cxx (original)
+++ openoffice/trunk/main/sw/source/core/frmedt/fefly1.cxx Tue Feb 18 11:47:13 
2014
@@ -965,7 +965,7 @@ void SwFEShell::InsertDrawObj( SdrObject
         ::lcl_FindAnchorPos( *this, *GetDoc(), rInsertPosition, *pFrm, 
rFlyAttrSet );
     }
     // insert drawing object into the document creating a new <SwDrawFrmFmt> 
instance
-    SwDrawFrmFmt* pFmt = GetDoc()->Insert( aPam, rDrawObj, &rFlyAttrSet, 0 );
+    SwDrawFrmFmt* pFmt = GetDoc()->InsertDrawObj( aPam, rDrawObj, rFlyAttrSet 
);
 
     // move object to visible layer
     SwContact* pContact = static_cast<SwContact*>(rDrawObj.GetUserCall());

Modified: openoffice/trunk/main/sw/source/core/unocore/unodraw.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/core/unocore/unodraw.cxx?rev=1569286&r1=1569285&r2=1569286&view=diff
==============================================================================
--- openoffice/trunk/main/sw/source/core/unocore/unodraw.cxx (original)
+++ openoffice/trunk/main/sw/source/core/unocore/unodraw.cxx Tue Feb 18 
11:47:13 2014
@@ -759,7 +759,7 @@ void SwXDrawPage::add(const uno::Referen
        if ( !pTemp )
                pTemp = pPam;
        UnoActionContext aAction(pDoc);
-       pDoc->Insert( *pTemp, *pObj, &aSet, NULL );
+       pDoc->InsertDrawObj( *pTemp, *pObj, aSet );
        SwFrmFmt* pFmt = ::FindFrmFmt( pObj );
        if(pFmt)
                pFmt->Add(pShape);

Modified: openoffice/trunk/main/sw/source/filter/html/htmldraw.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/filter/html/htmldraw.cxx?rev=1569286&r1=1569285&r2=1569286&view=diff
==============================================================================
--- openoffice/trunk/main/sw/source/filter/html/htmldraw.cxx (original)
+++ openoffice/trunk/main/sw/source/filter/html/htmldraw.cxx Tue Feb 18 
11:47:13 2014
@@ -220,7 +220,7 @@ void SwHTMLParser::InsertDrawObject( Sdr
     }
        aFrmSet.Put( aAnchor );
 
-       pDoc->Insert( *pPam, *pNewDrawObj, &aFrmSet, NULL );
+       pDoc->InsertDrawObj( *pPam, *pNewDrawObj, aFrmSet );
 }
 
 /*  */

Modified: openoffice/trunk/main/sw/source/filter/rtf/swparrtf.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/filter/rtf/swparrtf.cxx?rev=1569286&r1=1569285&r2=1569286&view=diff
==============================================================================
--- openoffice/trunk/main/sw/source/filter/rtf/swparrtf.cxx (original)
+++ openoffice/trunk/main/sw/source/filter/rtf/swparrtf.cxx Tue Feb 18 11:47:13 
2014
@@ -1311,7 +1311,7 @@ void SwRTFParser::ReadDrawingObject()
 
         pStroke->SetSnapRect(aRect);
 
-        /* SwFrmFmt* pRetFrmFmt = */pDoc->Insert(*pPam, *pStroke, &aFlySet, 
NULL);
+        /* SwFrmFmt* pRetFrmFmt = */pDoc->InsertDrawObj(*pPam, *pStroke, 
aFlySet );
     }
 }
 
@@ -1343,7 +1343,7 @@ void SwRTFParser::InsertShpObject(SdrObj
         SdrPage* pDrawPg = pDrawModel->GetPage(0);
         pDrawPg->InsertObject(pStroke);
         pDrawPg->SetObjectOrdNum(pStroke->GetOrdNum(), _nZOrder);
-        /* SwFrmFmt* pRetFrmFmt = */pDoc->Insert(*pPam, *pStroke, &aFlySet, 
NULL);
+        /* SwFrmFmt* pRetFrmFmt = */pDoc->InsertDrawObj(*pPam, *pStroke, 
aFlySet );
 }
 
 ::basegfx::B2DPoint rotate(const ::basegfx::B2DPoint& rStart, const 
::basegfx::B2DPoint& rEnd)

Modified: openoffice/trunk/main/sw/source/filter/ww8/ww8graf.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/filter/ww8/ww8graf.cxx?rev=1569286&r1=1569285&r2=1569286&view=diff
==============================================================================
--- openoffice/trunk/main/sw/source/filter/ww8/ww8graf.cxx (original)
+++ openoffice/trunk/main/sw/source/filter/ww8/ww8graf.cxx Tue Feb 18 11:47:13 
2014
@@ -1409,7 +1409,7 @@ void SwWW8ImplReader::ReadGrafLayer1( WW
         if (SdrObject *pObject = ReadGrafPrimitive( nLeft, &aDo, aSet ))
         {
             pWWZOrder->InsertDrawingObject(pObject, SVBT16ToShort(aDo.dhgt));
-            SwFrmFmt *pFrm = rDoc.Insert( *pPaM, *pObject, &aSet, NULL);
+            SwFrmFmt *pFrm = rDoc.InsertDrawObj( *pPaM, *pObject, aSet );
             pObject->SetMergedItemSet(aSet);
             pAnchorStck->AddAnchor(*pPaM->GetPoint(), pFrm);
         }
@@ -2839,7 +2839,7 @@ SwFrmFmt* SwWW8ImplReader::Read_GrafLaye
                 pWWZOrder->InsertTextLayerObject(pObject);
             }
 
-            pRetFrmFmt = rDoc.Insert(*pPaM, *pObject, &aFlySet, NULL);
+            pRetFrmFmt = rDoc.InsertDrawObj(*pPaM, *pObject, aFlySet );
 
             ASSERT(pRetFrmFmt->GetAnchor().GetAnchorId() ==
                 eAnchor, "Not the anchor type requested!");

Modified: openoffice/trunk/main/sw/source/filter/ww8/ww8graf2.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/filter/ww8/ww8graf2.cxx?rev=1569286&r1=1569285&r2=1569286&view=diff
==============================================================================
--- openoffice/trunk/main/sw/source/filter/ww8/ww8graf2.cxx (original)
+++ openoffice/trunk/main/sw/source/filter/ww8/ww8graf2.cxx Tue Feb 18 11:47:13 
2014
@@ -696,7 +696,7 @@ SwFrmFmt* SwWW8ImplReader::ImportGraf(Sd
                             }
                         }
                         else
-                            pRet = rDoc.Insert(*pPaM, *pObject, &aAttrSet, 
NULL);
+                            pRet = rDoc.InsertDrawObj(*pPaM, *pObject, 
aAttrSet );
                     }
                 }
 

Modified: openoffice/trunk/main/sw/source/filter/ww8/ww8par4.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/filter/ww8/ww8par4.cxx?rev=1569286&r1=1569285&r2=1569286&view=diff
==============================================================================
--- openoffice/trunk/main/sw/source/filter/ww8/ww8par4.cxx (original)
+++ openoffice/trunk/main/sw/source/filter/ww8/ww8par4.cxx Tue Feb 18 11:47:13 
2014
@@ -310,7 +310,7 @@ SwFrmFmt* SwWW8ImplReader::ImportOle(con
             SdrObject::Free( pRet );        // das brauchen wir nicht mehr
         }
         else
-            pFmt = rDoc.Insert(*pPaM, *pRet, pFlySet, NULL);
+            pFmt = rDoc.InsertDrawObj(*pPaM, *pRet, *pFlySet );
     }
     else if (
                 GRAPHIC_GDIMETAFILE == aGraph.GetType() ||


Reply via email to