You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by or...@apache.org on 2012/09/17 14:46:17 UTC

svn commit: r1386590 - in /incubator/ooo/trunk: ./ main/sw/inc/ main/sw/source/core/doc/ main/sw/source/core/tox/ main/sw/source/filter/ww8/ main/sw/source/filter/ww8/dump/ main/sw/source/ui/index/ test/ test/testcommon/source/org/openoffice/test/vcl/

Author: orw
Date: Mon Sep 17 12:46:16 2012
New Revision: 1386590

URL: http://svn.apache.org/viewvc?rev=1386590&view=rev
Log:
#119963#,#120877# - WW8 filter enhancement: import and export actual TOC content

         Patch by: zhengfan, Oliver
         Review by: Oliver

reintegrate from branch writer001

Modified:
    incubator/ooo/trunk/   (props changed)
    incubator/ooo/trunk/main/sw/inc/tox.hxx
    incubator/ooo/trunk/main/sw/source/core/doc/doctxm.cxx
    incubator/ooo/trunk/main/sw/source/core/tox/tox.cxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/attributeoutputbase.hxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/dump/ww8scan.cxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/writerwordglue.cxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/wrtw8nds.cxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/wrtww8.cxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/ww8atr.cxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/ww8attributeoutput.hxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par.cxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par.hxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par5.cxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par6.cxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/ww8scan.cxx
    incubator/ooo/trunk/main/sw/source/filter/ww8/ww8scan.hxx
    incubator/ooo/trunk/main/sw/source/ui/index/toxmgr.cxx
    incubator/ooo/trunk/test/   (props changed)
    incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/vcl/   (props changed)

Propchange: incubator/ooo/trunk/
------------------------------------------------------------------------------
  Merged /incubator/ooo/branches/writer001:r1356067-1386577

Modified: incubator/ooo/trunk/main/sw/inc/tox.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/inc/tox.hxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/inc/tox.hxx (original)
+++ incubator/ooo/trunk/main/sw/inc/tox.hxx Mon Sep 17 12:46:16 2012
@@ -501,6 +501,13 @@ class SW_DLLPUBLIC SwTOXBase : public Sw
 	sal_Bool 		bFromObjectNames : 1; 	// create a table or object index
 									// from the names rather than the caption
 	sal_Bool		bLevelFromChapter : 1; // User index: get the level from the source chapter
+
+protected:
+    // Add a data member, for record the TOC field expression of MS Word binary format
+    // For keeping fedality and may giving a better exporting performance
+    String maMSTOCExpression;
+    sal_Bool mbKeepExpression;
+
 public:
 	SwTOXBase( const SwTOXType* pTyp, const SwForm& rForm,
 			   sal_uInt16 nCreaType, const String& rTitle );
@@ -520,6 +527,12 @@ public:
 	const String&		GetTOXName() const {return aName;}
 	void				SetTOXName(const String& rSet) {aName = rSet;}
 
+    // for record the TOC field expression of MS Word binary format
+    const String&		GetMSTOCExpression() const{return maMSTOCExpression;}
+    void				SetMSTOCExpression(const String& rExp) {maMSTOCExpression = rExp;}
+    void				EnableKeepExpression() {mbKeepExpression = sal_True;}
+    void				DisableKeepExpression() {mbKeepExpression = sal_False;}
+
     const String&       GetTitle() const;           // Title
     const String&       GetTypeName() const;        // Name
     const SwForm&       GetTOXForm() const;         // description of the lines

Modified: incubator/ooo/trunk/main/sw/source/core/doc/doctxm.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/core/doc/doctxm.cxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/core/doc/doctxm.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/core/doc/doctxm.cxx Mon Sep 17 12:46:16 2012
@@ -793,19 +793,26 @@ sal_Bool SwTOXBaseSection::SetPosAtStart
 void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
                               const bool        _bNewTOX )//swmodtest 080307
 {
-	const SwSectionNode* pSectNd;
-	if( !SwTOXBase::GetRegisteredIn()->GetDepends() ||
-		!GetFmt() || 0 == (pSectNd = GetFmt()->GetSectionNode() ) ||
-		!pSectNd->GetNodes().IsDocNodes() ||
-		IsHiddenFlag() )
-		return;
+    const SwSectionNode* pSectNd;
+    if( !SwTOXBase::GetRegisteredIn()->GetDepends() ||
+        !GetFmt() || 0 == (pSectNd = GetFmt()->GetSectionNode() ) ||
+        !pSectNd->GetNodes().IsDocNodes() ||
+        IsHiddenFlag() )
+    {
+        return;
+    }
+
+    if ( !mbKeepExpression )
+    {
+        maMSTOCExpression = String();
+    }
 
-	SwDoc* pDoc = (SwDoc*)pSectNd->GetDoc();
+    SwDoc* pDoc = (SwDoc*)pSectNd->GetDoc();
 
     DBG_ASSERT(pDoc != NULL, "Where is the document?");
 
-	if(pAttr && pDoc && GetFmt())
-		pDoc->ChgFmt(*GetFmt(), *pAttr);
+    if(pAttr && pDoc && GetFmt())
+        pDoc->ChgFmt(*GetFmt(), *pAttr);
 
     // OD 18.03.2003 #106329# - determine default page description, which
     // will be used by the content nodes, if no approriate one is found.

Modified: incubator/ooo/trunk/main/sw/source/core/tox/tox.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/core/tox/tox.cxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/core/tox/tox.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/core/tox/tox.cxx Mon Sep 17 12:46:16 2012
@@ -510,17 +510,19 @@ void SwForm::AdjustTabStops(SwDoc& rDoc,
 
 SwTOXBase::SwTOXBase(const SwTOXType* pTyp, const SwForm& rForm,
                      sal_uInt16 nCreaType, const String& rTitle )
-    : SwClient((SwModify*)pTyp),
-    aForm(rForm),
-    aTitle(rTitle),
-    eLanguage((LanguageType)::GetAppLanguage()),
-    nCreateType(nCreaType),
-    nOLEOptions(0),
-    eCaptionDisplay(CAPTION_COMPLETE),
-    bProtected( sal_True ),
-    bFromChapter(sal_False),
-    bFromObjectNames(sal_False),
-    bLevelFromChapter(sal_False)
+    : SwClient((SwModify*)pTyp)
+    , aForm(rForm)
+    , aTitle(rTitle)
+    , eLanguage((LanguageType)::GetAppLanguage())
+    , nCreateType(nCreaType)
+    , nOLEOptions(0)
+    , eCaptionDisplay(CAPTION_COMPLETE)
+    , bProtected( sal_True )
+    , bFromChapter(sal_False)
+    , bFromObjectNames(sal_False)
+    , bLevelFromChapter(sal_False)
+    , maMSTOCExpression()
+    , mbKeepExpression(sal_True)
 {
     aData.nOptions = 0;
 }
@@ -528,6 +530,7 @@ SwTOXBase::SwTOXBase(const SwTOXType* pT
 
 SwTOXBase::SwTOXBase( const SwTOXBase& rSource, SwDoc* pDoc )
     : SwClient( rSource.GetRegisteredInNonConst() )
+    , mbKeepExpression(sal_True)
 {
     CopyTOXBase( pDoc, rSource );
 }
@@ -539,6 +542,7 @@ void SwTOXBase::RegisterToTOXType( SwTOX
 
 SwTOXBase& SwTOXBase::CopyTOXBase( SwDoc* pDoc, const SwTOXBase& rSource )
 {
+    maMSTOCExpression = rSource.maMSTOCExpression;
     SwTOXType* pType = (SwTOXType*)rSource.GetTOXType();
     if( pDoc && USHRT_MAX == pDoc->GetTOXTypes().GetPos( pType ))
     {

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/attributeoutputbase.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/attributeoutputbase.hxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/attributeoutputbase.hxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/attributeoutputbase.hxx Mon Sep 17 12:46:16 2012
@@ -187,7 +187,9 @@ public:
 
     void StartTOX( const SwSection& rSect );
 
-    void EndTOX( const SwSection& rSect );
+    void EndTOX( const SwSection& rSect,bool bCareEnd=true );
+
+    virtual void OnTOXEnding() {}
 
     virtual void TOXMark( const SwTxtNode& rNode, const SwTOXMark& rAttr );
 

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/dump/ww8scan.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/dump/ww8scan.cxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/dump/ww8scan.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/dump/ww8scan.cxx Mon Sep 17 12:46:16 2012
@@ -3541,7 +3541,7 @@ bool WW8PLCFx_FLD::StartPosIsFieldStart(
     return true;
 }
 
-bool WW8PLCFx_FLD::EndPosIsFieldEnd()
+bool WW8PLCFx_FLD::EndPosIsFieldEnd(WW8_CP& nCP)
 {
     bool bRet = false;
 
@@ -3554,7 +3554,10 @@ bool WW8PLCFx_FLD::EndPosIsFieldEnd()
         void* pData;
         long nTest;
         if ( pPLCF->Get(nTest, pData) && ((((sal_uInt8*)pData)[0] & 0x1f) == 0x15) )
+        {
+            nCP = nTest;
             bRet = true;
+        }
 
         pPLCF->SetIdx(n);
     }

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/writerwordglue.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/writerwordglue.cxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/writerwordglue.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/writerwordglue.cxx Mon Sep 17 12:46:16 2012
@@ -522,6 +522,10 @@ namespace sw
                 return true;
             if (nB == RES_TXTATR_CHARFMT)
                 return false;
+            if (nA == RES_TXTATR_INETFMT)
+                return true;
+            if (nB == RES_TXTATR_INETFMT)
+               return false;
             return nA < nB;
         }
 

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/wrtw8nds.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/wrtw8nds.cxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/wrtw8nds.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/wrtw8nds.cxx Mon Sep 17 12:46:16 2012
@@ -1955,7 +1955,7 @@ void MSWordExportBase::OutputTextNode( c
                     if ( pTOXSect )
                     {
                         m_aCurrentCharPropStarts.pop();
-                        AttrOutput().EndTOX( *pTOXSect );
+                        AttrOutput().EndTOX( *pTOXSect ,false);
                     }
                     WriteCR( pTextNodeInfoInner );
                 }
@@ -1993,6 +1993,7 @@ void MSWordExportBase::OutputTextNode( c
                 aAttrIter.OutFlys( nEnd );
                 // insert final bookmarks if any before CR and after flys
                 AppendBookmarks( rNode, nEnd, 1 );
+                WriteCR( pTextNodeInfoInner );
 
                 if ( pTOXSect )
                 {
@@ -2000,8 +2001,6 @@ void MSWordExportBase::OutputTextNode( c
                     AttrOutput().EndTOX( *pTOXSect );
                 }
 
-                WriteCR( pTextNodeInfoInner );
-
                 if ( bRedlineAtEnd )
                 {
                     AttrOutput().Redline( aAttrIter.GetRedline( nEnd ) );
@@ -2523,7 +2522,8 @@ void MSWordExportBase::OutputSectionNode
 
     SwNodeIndex aIdx( rSectionNode, 1 );
     const SwNode& rNd = aIdx.GetNode();
-    if ( !rNd.IsSectionNode() && !IsInTable() ) //No sections in table
+    if ( !rNd.IsSectionNode() && !IsInTable() 
+		&& rSection.GetType() != TOX_CONTENT_SECTION && rSection.GetType() != TOX_HEADER_SECTION) //No sections in table
     {
         // Bug 74245 - if the first Node inside the section has an own
         //              PageDesc or PageBreak attribut, then dont write

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/wrtww8.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/wrtww8.cxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/wrtww8.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/wrtww8.cxx Mon Sep 17 12:46:16 2012
@@ -33,6 +33,9 @@
 
 #include <algorithm>
 
+#include <map>
+#include <set>
+
 #include <hintids.hxx>
 #include <string.h>             // memcpy()
 #include <osl/endian.h>
@@ -187,30 +190,143 @@ public:
     WW8_FC GetStartFc() const       { return nStartFc; }
 };
 
+typedef std::map<String,long> BKMKNames;
+typedef BKMKNames::iterator BKMKNmItr;
+typedef std::pair<bool,String> BKMK;
+typedef std::pair<long,BKMK> BKMKCP;
+typedef std::multimap<long,BKMKCP*> BKMKCPs;
+typedef BKMKCPs::iterator CPItr;
+
 class WW8_WrtBookmarks
 {
 private:
-    SvULongs aSttCps, aEndCps;      // Array of Start- and End CPs
-    SvBools aFieldMarks;       // If the bookmark is in a field result
-    std::vector<String> maSwBkmkNms;    // Array of Sw - Bookmarknames
-    typedef std::vector<String>::iterator myIter;
-
-    sal_uInt16 GetPos( const String& rNm );
-
-    //No copying
+    BKMKCPs aSttCps,aEndCps;
+    BKMKNames maSwBkmkNms;
     WW8_WrtBookmarks(const WW8_WrtBookmarks&);
     WW8_WrtBookmarks& operator=(const WW8_WrtBookmarks&);
+
 public:
     WW8_WrtBookmarks();
     ~WW8_WrtBookmarks();
-
     void Append( WW8_CP nStartCp, const String& rNm, const ::sw::mark::IMark* pBkmk=NULL );
     void Write( WW8Export& rWrt );
     void MoveFieldMarks(sal_uLong nFrom,sal_uLong nTo);
-
-//  String GetWWBkmkName( const String& rName ) const;
 };
 
+WW8_WrtBookmarks::WW8_WrtBookmarks()
+{}
+
+WW8_WrtBookmarks::~WW8_WrtBookmarks()
+{
+    CPItr aEnd = aSttCps.end();
+    for (CPItr aItr = aSttCps.begin();aItr!=aEnd;aItr++) 
+    {
+        if (aItr->second)
+        {
+            delete aItr->second;
+            aItr->second = NULL;
+        }
+    }
+}
+
+void WW8_WrtBookmarks::Append( WW8_CP nStartCp, const String& rNm, const ::sw::mark::IMark*)
+{
+    std::pair<BKMKNmItr,bool> aResult = maSwBkmkNms.insert(std::pair<String,long>(rNm,0L));
+    if (aResult.second)
+    {
+        BKMK aBK(false,rNm);
+        BKMKCP* pBKCP = new BKMKCP((long)nStartCp,aBK);
+        aSttCps.insert(std::pair<long,BKMKCP*>(nStartCp,pBKCP));
+        aResult.first->second = (long)nStartCp;
+    }
+    else
+    {
+        std::pair<CPItr,CPItr> aRange = aSttCps.equal_range(aResult.first->second);
+        for (CPItr aItr = aRange.first;aItr != aRange.second;aItr++)
+        {
+            if (aItr->second && aItr->second->second.second == rNm)
+            {
+                if (aItr->second->second.first)
+                    nStartCp--;
+                aItr->second->first = (long)nStartCp;
+                break;
+            }
+        }
+    }
+}
+
+void WW8_WrtBookmarks::Write( WW8Export& rWrt)
+{
+    if (!aSttCps.size())
+        return;
+    CPItr aItr;
+    long n;
+    std::vector<String> aNames;
+    SvMemoryStream aTempStrm1(65535,65535);
+    SvMemoryStream aTempStrm2(65535,65535);
+    for (aItr = aSttCps.begin();aItr!=aSttCps.end();aItr++)
+    {
+        if (aItr->second)
+        {
+            aEndCps.insert(std::pair<long,BKMKCP*>(aItr->second->first,aItr->second));
+            aNames.push_back(aItr->second->second.second);
+            SwWW8Writer::WriteLong( aTempStrm1, aItr->first);
+        }
+    }
+
+    aTempStrm1.Seek(0L);
+    for (aItr = aEndCps.begin(), n = 0;aItr != aEndCps.end();aItr++,n++)
+    {
+        if (aItr->second)
+        {
+            aItr->second->first = n;
+            SwWW8Writer::WriteLong( aTempStrm2, aItr->first);
+        }
+    }
+
+    aTempStrm2.Seek(0L);
+    rWrt.WriteAsStringTable(aNames, rWrt.pFib->fcSttbfbkmk,rWrt.pFib->lcbSttbfbkmk);
+    SvStream& rStrm = rWrt.bWrtWW8 ? *rWrt.pTableStrm : rWrt.Strm();
+    rWrt.pFib->fcPlcfbkf = rStrm.Tell();
+    rStrm<<aTempStrm1;
+    SwWW8Writer::WriteLong(rStrm, rWrt.pFib->ccpText + rWrt.pFib->ccpTxbx);
+    for (aItr = aSttCps.begin();aItr!=aSttCps.end();aItr++)
+    {
+        if (aItr->second)
+        {
+            SwWW8Writer::WriteLong(rStrm, aItr->second->first);
+        }
+    }
+    rWrt.pFib->lcbPlcfbkf = rStrm.Tell() - rWrt.pFib->fcPlcfbkf;
+    rWrt.pFib->fcPlcfbkl = rStrm.Tell();
+    rStrm<<aTempStrm2;
+    SwWW8Writer::WriteLong(rStrm, rWrt.pFib->ccpText + rWrt.pFib->ccpTxbx);
+    rWrt.pFib->lcbPlcfbkl = rStrm.Tell() - rWrt.pFib->fcPlcfbkl;
+}
+
+void WW8_WrtBookmarks::MoveFieldMarks(sal_uLong nFrom,sal_uLong nTo)
+{
+    std::pair<CPItr,CPItr> aRange = aSttCps.equal_range(nFrom);
+    CPItr aItr = aRange.first;
+    while (aItr != aRange.second)
+    {
+        if (aItr->second)
+        {
+            if (aItr->second->first == nFrom)
+            {
+                aItr->second->second.first = true;
+                aItr->second->first = nTo;
+            }
+            aSttCps.insert(std::pair<long,BKMKCP*>(nTo,aItr->second));
+            aItr->second = NULL;
+            aRange = aSttCps.equal_range(nFrom);
+            aItr = aRange.first;
+            continue;
+        }
+        aItr++;
+    }
+}
+
 #define ANZ_DEFAULT_STYLES 16
 
 // die Namen der StorageStreams
@@ -1253,136 +1369,6 @@ WW8_CP WW8_WrPct::Fc2Cp( sal_uLong nFc )
     return nFc + pPcts->GetObject( pPcts->Count() - 1 )->GetStartCp();
 }
 
-//--------------------------------------------------------------------------
-/*  */
-
-WW8_WrtBookmarks::WW8_WrtBookmarks()
-    : aSttCps( 0, 16 ), aEndCps( 0, 16 )
-{
-}
-
-WW8_WrtBookmarks::~WW8_WrtBookmarks()
-{
-}
-
-void WW8_WrtBookmarks::Append( WW8_CP nStartCp, const String& rNm,  const ::sw::mark::IMark* )
-{
-    sal_uInt16 nPos = GetPos( rNm );
-    if( USHRT_MAX == nPos )
-    {
-        // new -> insert as start position
-        nPos = aSttCps.Count();
-        myIter aIter = maSwBkmkNms.end();
-        // sort by startposition
-        //      theory: write continuous -> then the new position is at end
-        while( nPos && aSttCps[ nPos - 1 ] > sal_uLong( nStartCp ))
-        {
-            --nPos;
-            --aIter;
-        }
-
-        aSttCps.Insert(nStartCp, nPos);
-        aEndCps.Insert(nStartCp, nPos);
-        aFieldMarks.insert(aFieldMarks.begin() + nPos, sal_Bool(false));
-        maSwBkmkNms.insert(aIter, rNm);
-    }
-    else
-    {
-        // old -> its the end position
-        ASSERT( aEndCps[ nPos ] == aSttCps[ nPos ], "end position is valid" );
-
-        //If this bookmark was around a field in writer, then we want to move
-        //it to the field result in word. The end is therefore one cp
-        //backwards from the 0x15 end mark that was inserted.
-        if (aFieldMarks[nPos])
-            --nStartCp;
-
-        aEndCps.Replace( nStartCp, nPos );
-    }
-}
-
-
-void WW8_WrtBookmarks::Write( WW8Export& rWrt )
-{
-    sal_uInt16 nCount = aSttCps.Count(), i;
-    if( nCount )
-    {
-        SvULongs aEndSortTab( 255 < nCount ? 255 : nCount, 4 );
-        // sort then endpositions
-        for( i = 0; i < nCount; ++i )
-        {
-            sal_uLong nCP = aEndCps[ i ];
-            sal_uInt16 nPos = i;
-            while( nPos && aEndSortTab[ nPos - 1 ] > nCP )
-                --nPos;
-            aEndSortTab.Insert( nCP, nPos );
-        }
-
-        // we have some bookmarks found in the document -> write them
-        // first the Bookmark Name Stringtable
-        rWrt.WriteAsStringTable(maSwBkmkNms, rWrt.pFib->fcSttbfbkmk,
-            rWrt.pFib->lcbSttbfbkmk);
-
-        // second the Bookmark start positions as pcf of longs
-        SvStream& rStrm = rWrt.bWrtWW8 ? *rWrt.pTableStrm : rWrt.Strm();
-        rWrt.pFib->fcPlcfbkf = rStrm.Tell();
-        for( i = 0; i < nCount; ++i )
-            SwWW8Writer::WriteLong( rStrm, aSttCps[ i ] );
-        SwWW8Writer::WriteLong(rStrm, rWrt.pFib->ccpText + rWrt.pFib->ccpTxbx);
-        for( i = 0; i < nCount; ++i )
-        {
-            sal_uLong nEndCP = aEndCps[ i ];
-            sal_uInt16 nPos = i;
-            if( aEndSortTab[ nPos ] > nEndCP )
-            {
-                while( aEndSortTab[ --nPos ] != nEndCP )
-                    ;
-            }
-            else if( aEndSortTab[ nPos ] < nEndCP )
-                while( aEndSortTab[ ++nPos ] != nEndCP )
-                    ;
-
-            SwWW8Writer::WriteLong( rStrm, nPos );
-        }
-        rWrt.pFib->lcbPlcfbkf = rStrm.Tell() - rWrt.pFib->fcPlcfbkf;
-
-        // third the Bookmark end positions
-        rWrt.pFib->fcPlcfbkl = rStrm.Tell();
-        for( i = 0; i < nCount; ++i )
-            SwWW8Writer::WriteLong( rStrm, aEndSortTab[ i ] );
-        SwWW8Writer::WriteLong(rStrm, rWrt.pFib->ccpText + rWrt.pFib->ccpTxbx);
-        rWrt.pFib->lcbPlcfbkl = rStrm.Tell() - rWrt.pFib->fcPlcfbkl;
-    }
-}
-
-sal_uInt16 WW8_WrtBookmarks::GetPos( const String& rNm )
-{
-    sal_uInt16 nRet = USHRT_MAX, n;
-    for (n = 0; n < aSttCps.Count(); ++n)
-        if (rNm == maSwBkmkNms[n])
-        {
-            nRet = n;
-            break;
-        }
-    return nRet;
-}
-
-void WW8_WrtBookmarks::MoveFieldMarks(sal_uLong nFrom, sal_uLong nTo)
-{
-    for (sal_uInt16 nI=0;nI<aSttCps.Count();++nI)
-    {
-        if (aSttCps[nI] == nFrom)
-        {
-            aSttCps[nI] = nTo;
-            if (aEndCps[nI] == nFrom)
-            {
-                aFieldMarks[nI] = true;
-                aEndCps[nI] = nTo;
-            }
-        }
-    }
-}
-
 void WW8Export::AppendBookmarks( const SwTxtNode& rNd,
     xub_StrLen nAktPos, xub_StrLen nLen )
 {
@@ -2561,7 +2547,8 @@ void MSWordExportBase::WriteText()
                 ;
             else if ( aIdx.GetNode().IsSectionNode() )
                 ;
-            else if ( !IsInTable() ) //No sections in table
+            else if ( !IsInTable() 
+				&& (rSect.GetType() != TOX_CONTENT_SECTION && rSect.GetType() != TOX_HEADER_SECTION )) //No sections in table
             {
        			//#120140# Do not need to insert a page/section break after a section end. Check this case first
 				sal_Bool bNeedExportBreakHere = sal_True;

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/ww8atr.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/ww8atr.cxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/ww8atr.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/ww8atr.cxx Mon Sep 17 12:46:16 2012
@@ -967,7 +967,8 @@ void WW8AttributeOutput::RTLAndCJKState(
 
 void WW8AttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pTextNodeInfoInner )
 {
-    m_rWW8Export.pPapPlc->AppendFkpEntry( m_rWW8Export.Strm().Tell(), m_rWW8Export.pO->Count(), m_rWW8Export.pO->GetData() );
+    m_rWW8Export.pPapPlc->AppendFkpEntry( m_rWW8Export.Strm().Tell() - (mbOnTOXEnding?2:0), m_rWW8Export.pO->Count(), m_rWW8Export.pO->GetData() );
+    mbOnTOXEnding = false;
     m_rWW8Export.pO->Remove( 0, m_rWW8Export.pO->Count() ); // delete
 
     if ( pTextNodeInfoInner.get() != NULL )
@@ -1014,6 +1015,11 @@ void WW8AttributeOutput::StartRun( const
     }
 }
 
+void WW8AttributeOutput::OnTOXEnding()
+{
+	mbOnTOXEnding = true;
+}
+
 void WW8AttributeOutput::EndRunProperties( const SwRedlineData* pRedlineData )
 {
     Redline( pRedlineData );
@@ -2106,347 +2112,289 @@ void AttributeOutputBase::StartTOX( cons
         static const sal_Char sEntryEnd[] = "\" ";
 
         ww::eField eCode = ww::eTOC;
-        String sStr;
-        switch (pTOX->GetType())
+        String sStr = pTOX->GetMSTOCExpression();
+        if ( !sStr.Len() )
         {
-        case TOX_INDEX:
-            eCode = ww::eINDEX;
-            sStr = FieldString(eCode);
-
-            if (pTOX->GetTOXForm().IsCommaSeparated())
-                sStr.APPEND_CONST_ASC("\\r ");
-
-            if (nsSwTOIOptions::TOI_ALPHA_DELIMITTER & pTOX->GetOptions())
-                sStr.APPEND_CONST_ASC("\\h \"A\" ");
-
+            switch (pTOX->GetType())
             {
-			    String aFillTxt;
-                for (sal_uInt8 n = 1; n <= 3; ++n)
-                {
-                    String aTxt;
-                    int nRet = ::lcl_CheckForm(pTOX->GetTOXForm(), n, aTxt);
+            case TOX_INDEX:
+                eCode = ww::eINDEX;
+                sStr = FieldString(eCode);
 
-                    if( 3 == nRet )
-                        aFillTxt = aTxt;
-                    else if ((4 == nRet) || (2 == nRet)) //#109414#
-                        aFillTxt = '\t';
-                    else
-                        aFillTxt.Erase();
-                }
-                sStr.APPEND_CONST_ASC("\\e \"");
-                sStr += aFillTxt;
-                sStr.AppendAscii(sEntryEnd);
-            }
-            break;
+                if (pTOX->GetTOXForm().IsCommaSeparated())
+                    sStr.APPEND_CONST_ASC("\\r ");
 
-//      case TOX_AUTHORITIES:   eCode = eTOA; sStr = ???; break;
+                if (nsSwTOIOptions::TOI_ALPHA_DELIMITTER & pTOX->GetOptions())
+                    sStr.APPEND_CONST_ASC("\\h \"A\" ");
 
-        case TOX_ILLUSTRATIONS:
-        case TOX_OBJECTS:
-        case TOX_TABLES:
-            if (!pTOX->IsFromObjectNames())
-            {
-                sStr = FieldString(eCode);
-
-                sStr.APPEND_CONST_ASC("\\c \"");
-                sStr += pTOX->GetSequenceName();
-                sStr.AppendAscii(sEntryEnd);
-
-                String aTxt;
-                int nRet = ::lcl_CheckForm( pTOX->GetTOXForm(), 1, aTxt );
-                if (1 == nRet)
-                    sStr.APPEND_CONST_ASC("\\n ");
-                else if( 3 == nRet || 4 == nRet )
                 {
-                    sStr.APPEND_CONST_ASC("\\p \"");
-                    sStr += aTxt;
+                    String aFillTxt;
+                    for (sal_uInt8 n = 1; n <= 3; ++n)
+                    {
+                        String aTxt;
+                        int nRet = ::lcl_CheckForm(pTOX->GetTOXForm(), n, aTxt);
+
+                        if( 3 == nRet )
+                            aFillTxt = aTxt;
+                        else if ((4 == nRet) || (2 == nRet)) //#109414#
+                            aFillTxt = '\t';
+                        else
+                            aFillTxt.Erase();
+                    }
+                    sStr.APPEND_CONST_ASC("\\e \"");
+                    sStr += aFillTxt;
                     sStr.AppendAscii(sEntryEnd);
                 }
-            }
-            break;
-
-//      case TOX_USER:
-//      case TOX_CONTENT:
-        default:
-            {
-                sStr = FieldString(eCode);
+                break;
 
-                String sTOption;
-                sal_uInt16 n, nTOXLvl = pTOX->GetLevel();
-                if( !nTOXLvl )
-                    ++nTOXLvl;
+                //      case TOX_AUTHORITIES:   eCode = eTOA; sStr = ???; break;
 
-                if( nsSwTOXElement::TOX_MARK & pTOX->GetCreateType() )
+            case TOX_ILLUSTRATIONS:
+            case TOX_OBJECTS:
+            case TOX_TABLES:
+                if (!pTOX->IsFromObjectNames())
                 {
-                    sStr.APPEND_CONST_ASC( "\\f " );
+                    sStr = FieldString(eCode);
+
+                    sStr.APPEND_CONST_ASC("\\c \"");
+                    sStr += pTOX->GetSequenceName();
+                    sStr.AppendAscii(sEntryEnd);
 
-                    if( TOX_USER == pTOX->GetType() )
+                    String aTxt;
+                    int nRet = ::lcl_CheckForm( pTOX->GetTOXForm(), 1, aTxt );
+                    if (1 == nRet)
+                        sStr.APPEND_CONST_ASC("\\n ");
+                    else if( 3 == nRet || 4 == nRet )
                     {
-                         sStr += '\"';
-                         sStr += (sal_Char)( 'A' + GetExport( ).GetId( *pTOX->GetTOXType() ) );
-                         sStr.AppendAscii( sEntryEnd );
+                        sStr.APPEND_CONST_ASC("\\p \"");
+                        sStr += aTxt;
+                        sStr.AppendAscii(sEntryEnd);
                     }
+                }
+                break;
 
-                if( nsSwTOXElement::TOX_OUTLINELEVEL & pTOX->GetCreateType() )
+                //      case TOX_USER:
+                //      case TOX_CONTENT:
+            default:
                 {
-                    // --> OD 2009-02-27 #i99641#
-                    // The following code does not determine the minimum outline
-                    // level for the TOC
-//                    // Search over all the outline styles used and figure out
-//                    // what is the minimum outline level we need to display
-//                    // (ignoring headline styles 1-9)
-//                    //sal_uInt8 nLvl = 0, nMinLvl = 0; //#outline level, removed by zhaojianwei
-//                    int nLvl = 0, nMinLvl = 0;      //<-end,add by zhaojianwei
-//                    const SwTxtFmtColls& rColls = *GetExport().pDoc->GetTxtFmtColls();
-//                    const SwTxtFmtColl* pColl;
-//                    for( n = rColls.Count(); n; )
-//                    {
-//                        pColl = rColls[ --n ];
-//                        //nLvl = pColl->GetOutlineLevel();    //#outline level,zhaojianwei
-//                        //sal_uInt16 nPoolId = pColl->GetPoolFmtId();
-//                        //if( MAXLEVEL > nLvl && nMinLvl < nLvl &&        //<-end, ->add by zhaojianwei
-//                        sal_uInt16 nPoolId = pColl->GetPoolFmtId();
-//                        if( pColl->IsAssignedToListLevelOfOutlineStyle() &&
-//                          nMinLvl < (nLvl = pColl->GetAssignedOutlineStyleLevel()) && //<-end,zhaojianwei
-//                            ( RES_POOLCOLL_HEADLINE1 > nPoolId ||
-//                              RES_POOLCOLL_HEADLINE9 < nPoolId ))
-//                        {
-//                            // If we are using the default heading styles then use nTOXLvl
-//                            if(!nMinLvl)
-//                                nLvl = nTOXLvl;
-//                            else
-//                                nLvl = nMinLvl < nTOXLvl ? nMinLvl : (sal_uInt8)nTOXLvl;
-//                            nMinLvl = nLvl;
-//                        }
-//                    }
-                    const int nMinLvl = nTOXLvl;
+                    sStr = FieldString(eCode);
+
+                    String sTOption;
+                    sal_uInt16 n, nTOXLvl = pTOX->GetLevel();
+                    if( !nTOXLvl )
+                        ++nTOXLvl;
 
-//                    if( nLvl )
-                    if ( nMinLvl > 0 )
+                    if( nsSwTOXElement::TOX_MARK & pTOX->GetCreateType() )
                     {
-                        int nTmpLvl = nMinLvl;
-                        if (nTmpLvl > WW8ListManager::nMaxLevel)
-                            nTmpLvl = WW8ListManager::nMaxLevel;
+                        sStr.APPEND_CONST_ASC( "\\f " );
 
-                        sStr.APPEND_CONST_ASC( "\\o \"1-" );
-                        sStr += String::CreateFromInt32( nTmpLvl );
-                        sStr.AppendAscii(sEntryEnd);
+                        if( TOX_USER == pTOX->GetType() )
+                        {
+                            sStr += '\"';
+                            sStr += (sal_Char)( 'A' + GetExport( ).GetId( *pTOX->GetTOXType() ) );
+                            sStr.AppendAscii( sEntryEnd );
+                        }
 
-                    }
-                    // <--
+                        if( nsSwTOXElement::TOX_OUTLINELEVEL & pTOX->GetCreateType() )
+                        {
+                            const int nMinLvl = nTOXLvl;
+                            if ( nMinLvl > 0 )
+                            {
+                                int nTmpLvl = nMinLvl;
+                                if (nTmpLvl > WW8ListManager::nMaxLevel)
+                                    nTmpLvl = WW8ListManager::nMaxLevel;
+
+                                sStr.APPEND_CONST_ASC( "\\o \"1-" );
+                                sStr += String::CreateFromInt32( nTmpLvl );
+                                sStr.AppendAscii(sEntryEnd);
 
-                    // --> OD 2009-02-27 #i99641#
-                    // not needed to additional export paragraph style with
-                    // an outline level to the /t option
-//                    if( nMinLvl > 0 )
-//                    // <--
-//                    {
-//                        // collect this templates into the \t otion
-//                        const SwTxtFmtColls& rColls = *pDoc->GetTxtFmtColls();
-//                        const SwTxtFmtColl* pColl;
-//                        int nLvl = 0;
-//                        for( n = rColls.Count(); n;)
-//                        {
-//                            pColl = rColls[--n];
-//                            //nLvl =  pColl->GetOutlineLevel();         //#outline level, removed by zhaojianwei
-//                            //if (MAXLEVEL > nLvl && nMinLvl <= nLvl)
-//                            //{                                         //<-end, ->add by zhaojianwei
-//                            if( pColl->IsAssignedToListLevelOfOutlineStyle() &&
-//                                nMinLvl <= ( nLvl = pColl->GetAssignedOutlineStyleLevel()))
-//                            {                                           //<-end,zhaojianwei
-//                                if( sTOption.Len() )
-//                                    sTOption += ';';
-//                                (( sTOption += pColl->GetName() ) += ';' )
-//                                        += String::CreateFromInt32( nLvl + 1 );
-//                            }
-//                        }
-//                    }
+                            }
+                        }
 
-                }
-				
 
-		if( nsSwTOXElement::TOX_OUTLINELEVEL & pTOX->GetCreateType() )
-                  {
-		    // Take the TOC value of the max level to evaluate to as
-		    // the starting point for the \o flag, but reduce it to the 
-		    // value of the highest outline level filled by a *standard*
-		    // Heading 1 - 9 style because \o "Builds a table of
-		    // contents from paragraphs formatted with built-in heading
-		    // styles". And afterward fill in any outline styles left
-		    // uncovered by that range to the \t flag
-		    //
-		    // i.e. for
-		    // Heading 1
-		    // Heading 2
-		    // custom-style
-		    // Heading 4
-		    // output
-		    // \o 1-2 \tcustom-style,3,Heading 3,4
- 
-		    // Search over all the outline styles used and figure out
-		    // what is the minimum outline level (if any) filled by a
-		    // non-standard style for that level, i.e. ignore headline
-		    // styles 1-9 and find the lowest valid outline level
-		    sal_uInt8 nPosOfLowestNonStandardLvl = MAXLEVEL;
-		    const SwTxtFmtColls& rColls = *GetExport().pDoc->GetTxtFmtColls();
-		    for( n = rColls.Count(); n; )
-                      {
-			const SwTxtFmtColl* pColl = rColls[ --n ];
-			sal_uInt16 nPoolId = pColl->GetPoolFmtId();
-			if (
-			    //Is a Non-Standard Outline Style
-			    (RES_POOLCOLL_HEADLINE1 > nPoolId || RES_POOLCOLL_HEADLINE9 < nPoolId) &&
-			    //Has a valid outline level
-			    (pColl->IsAssignedToListLevelOfOutlineStyle()) &&
-			    // Is less than the lowest known non-standard level
-			    (pColl->GetAssignedOutlineStyleLevel() < nPosOfLowestNonStandardLvl)
-                            )
-                          {
-							  nPosOfLowestNonStandardLvl = ::sal::static_int_cast<sal_uInt8>(pColl->GetAssignedOutlineStyleLevel());
-                          }
-                      }
-  
-		    sal_uInt8 nMaxMSAutoEvaluate = nPosOfLowestNonStandardLvl < nTOXLvl ? nPosOfLowestNonStandardLvl : (sal_uInt8)nTOXLvl;
-  
-		    //output \o 1-X where X is the highest normal outline style to be included in the toc
-		    if ( nMaxMSAutoEvaluate )
-		      {
-			if (nMaxMSAutoEvaluate > WW8ListManager::nMaxLevel)
-			  nMaxMSAutoEvaluate = WW8ListManager::nMaxLevel;
-  
-			sStr.APPEND_CONST_ASC( "\\o \"1-" );
-			sStr += String::CreateFromInt32( nMaxMSAutoEvaluate );
-			sStr.AppendAscii(sEntryEnd);
-                      }
-  
-		    //collect up any other styles in the writer TOC which will
-		    //not already appear in the MS TOC and place then into the
-		    //\t option
-		    if( nMaxMSAutoEvaluate < nTOXLvl )
-                      {
-			// collect this templates into the \t otion
-			for( n = rColls.Count(); n;)
-                          {
-			    const SwTxtFmtColl* pColl = rColls[ --n ];
-			    if (!pColl->IsAssignedToListLevelOfOutlineStyle())
-			      continue;
-				sal_uInt8 nTestLvl =  ::sal::static_int_cast<sal_uInt8>(pColl->GetAssignedOutlineStyleLevel());
-			    if (nTestLvl < nTOXLvl && nTestLvl >= nMaxMSAutoEvaluate)
-			      {
-				if( sTOption.Len() )
-				  sTOption += ',';
-				(( sTOption += pColl->GetName() ) += ',' )
-				  += String::CreateFromInt32( nTestLvl + 1 );
-			      }
-			  }
-		      }
-				  }
-
-                if( nsSwTOXElement::TOX_TEMPLATE & pTOX->GetCreateType() )
-                    // --> OD 2009-02-27 #i99641#
-                    // Consider additional styles regardless of TOX-outlinelevel
-                    for( n = 0; n < MAXLEVEL; ++n )
-                    // <--
-                    {
-                        const String& rStyles = pTOX->GetStyleNames( n );
-                        if( rStyles.Len() )
+                        if( nsSwTOXElement::TOX_OUTLINELEVEL & pTOX->GetCreateType() )
                         {
-                            xub_StrLen nPos = 0;
-                            String sLvl( ',' );
-                            sLvl += String::CreateFromInt32( n + 1 );
-                            do {
-                                String sStyle( rStyles.GetToken( 0,
-                                            TOX_STYLE_DELIMITER, nPos ));
-                                if( sStyle.Len() )
+                            // Take the TOC value of the max level to evaluate to as
+                            // the starting point for the \o flag, but reduce it to the 
+                            // value of the highest outline level filled by a *standard*
+                            // Heading 1 - 9 style because \o "Builds a table of
+                            // contents from paragraphs formatted with built-in heading
+                            // styles". And afterward fill in any outline styles left
+                            // uncovered by that range to the \t flag
+                            //
+                            // i.e. for
+                            // Heading 1
+                            // Heading 2
+                            // custom-style
+                            // Heading 4
+                            // output
+                            // \o 1-2 \tcustom-style,3,Heading 3,4
+
+                            // Search over all the outline styles used and figure out
+                            // what is the minimum outline level (if any) filled by a
+                            // non-standard style for that level, i.e. ignore headline
+                            // styles 1-9 and find the lowest valid outline level
+                            sal_uInt8 nPosOfLowestNonStandardLvl = MAXLEVEL;
+                            const SwTxtFmtColls& rColls = *GetExport().pDoc->GetTxtFmtColls();
+                            for( n = rColls.Count(); n; )
+                            {
+                                const SwTxtFmtColl* pColl = rColls[ --n ];
+                                sal_uInt16 nPoolId = pColl->GetPoolFmtId();
+                                if (
+                                    //Is a Non-Standard Outline Style
+                                    (RES_POOLCOLL_HEADLINE1 > nPoolId || RES_POOLCOLL_HEADLINE9 < nPoolId) &&
+                                    //Has a valid outline level
+                                    (pColl->IsAssignedToListLevelOfOutlineStyle()) &&
+                                    // Is less than the lowest known non-standard level
+                                    (pColl->GetAssignedOutlineStyleLevel() < nPosOfLowestNonStandardLvl)
+                                    )
                                 {
-                                    SwTxtFmtColl* pColl = GetExport().pDoc->FindTxtFmtCollByName(sStyle);
-                                    if (!pColl->IsAssignedToListLevelOfOutlineStyle() || pColl->GetAssignedOutlineStyleLevel() < nTOXLvl)
+                                    nPosOfLowestNonStandardLvl = ::sal::static_int_cast<sal_uInt8>(pColl->GetAssignedOutlineStyleLevel());
+                                }
+                            }
+
+                            sal_uInt8 nMaxMSAutoEvaluate = nPosOfLowestNonStandardLvl < nTOXLvl ? nPosOfLowestNonStandardLvl : (sal_uInt8)nTOXLvl;
+
+                            //output \o 1-X where X is the highest normal outline style to be included in the toc
+                            if ( nMaxMSAutoEvaluate )
+                            {
+                                if (nMaxMSAutoEvaluate > WW8ListManager::nMaxLevel)
+                                    nMaxMSAutoEvaluate = WW8ListManager::nMaxLevel;
+
+                                sStr.APPEND_CONST_ASC( "\\o \"1-" );
+                                sStr += String::CreateFromInt32( nMaxMSAutoEvaluate );
+                                sStr.AppendAscii(sEntryEnd);
+                            }
+
+                            //collect up any other styles in the writer TOC which will
+                            //not already appear in the MS TOC and place then into the
+                            //\t option
+                            if( nMaxMSAutoEvaluate < nTOXLvl )
+                            {
+                                // collect this templates into the \t otion
+                                for( n = rColls.Count(); n;)
+                                {
+                                    const SwTxtFmtColl* pColl = rColls[ --n ];
+                                    if (!pColl->IsAssignedToListLevelOfOutlineStyle())
+                                        continue;
+                                    sal_uInt8 nTestLvl =  ::sal::static_int_cast<sal_uInt8>(pColl->GetAssignedOutlineStyleLevel());
+                                    if (nTestLvl < nTOXLvl && nTestLvl >= nMaxMSAutoEvaluate)
                                     {
                                         if( sTOption.Len() )
                                             sTOption += ',';
-                                        ( sTOption += sStyle ) += sLvl;
+                                        (( sTOption += pColl->GetName() ) += ',' )
+                                            += String::CreateFromInt32( nTestLvl + 1 );
                                     }
                                 }
-                            } while( STRING_NOTFOUND != nPos );
+                            }
                         }
-                    }
 
-                {
-                    String aFillTxt;
-                    sal_uInt8 nNoPgStt = MAXLEVEL, nNoPgEnd = MAXLEVEL;
-                    bool bFirstFillTxt = true, bOnlyText = true;
-                    for( n = 0; n < nTOXLvl; ++n )
-                    {
-                        String aTxt;
-                        int nRet = ::lcl_CheckForm( pTOX->GetTOXForm(),
-                                                    static_cast< sal_uInt8 >(n+1), aTxt );
-                        if( 1 == nRet )
-                        {
-                            bOnlyText = false;
-                            if( MAXLEVEL == nNoPgStt )
-                                nNoPgStt = static_cast< sal_uInt8 >(n+1);
-                        }
-                        else
-                        {
-                            if( MAXLEVEL != nNoPgStt &&
-                                MAXLEVEL == nNoPgEnd )
-                                nNoPgEnd = sal_uInt8(n);
+                        if( nsSwTOXElement::TOX_TEMPLATE & pTOX->GetCreateType() )
+                            // --> OD 2009-02-27 #i99641#
+                            // Consider additional styles regardless of TOX-outlinelevel
+                            for( n = 0; n < MAXLEVEL; ++n )
+                                // <--
+                            {
+                                const String& rStyles = pTOX->GetStyleNames( n );
+                                if( rStyles.Len() )
+                                {
+                                    xub_StrLen nPos = 0;
+                                    String sLvl( ',' );
+                                    sLvl += String::CreateFromInt32( n + 1 );
+                                    do {
+                                        String sStyle( rStyles.GetToken( 0,
+                                            TOX_STYLE_DELIMITER, nPos ));
+                                        if( sStyle.Len() )
+                                        {
+                                            SwTxtFmtColl* pColl = GetExport().pDoc->FindTxtFmtCollByName(sStyle);
+                                            if (!pColl->IsAssignedToListLevelOfOutlineStyle() || pColl->GetAssignedOutlineStyleLevel() < nTOXLvl)
+                                            {
+                                                if( sTOption.Len() )
+                                                    sTOption += ',';
+                                                ( sTOption += sStyle ) += sLvl;
+                                            }
+                                        }
+                                    } while( STRING_NOTFOUND != nPos );
+                                }
+                            }
+
+                            {
+                                String aFillTxt;
+                                sal_uInt8 nNoPgStt = MAXLEVEL, nNoPgEnd = MAXLEVEL;
+                                bool bFirstFillTxt = true, bOnlyText = true;
+                                for( n = 0; n < nTOXLvl; ++n )
+                                {
+                                    String aTxt;
+                                    int nRet = ::lcl_CheckForm( pTOX->GetTOXForm(),
+                                        static_cast< sal_uInt8 >(n+1), aTxt );
+                                    if( 1 == nRet )
+                                    {
+                                        bOnlyText = false;
+                                        if( MAXLEVEL == nNoPgStt )
+                                            nNoPgStt = static_cast< sal_uInt8 >(n+1);
+                                    }
+                                    else
+                                    {
+                                        if( MAXLEVEL != nNoPgStt &&
+                                            MAXLEVEL == nNoPgEnd )
+                                            nNoPgEnd = sal_uInt8(n);
+
+                                        bOnlyText = bOnlyText && 3 == nRet;
+                                        if( 3 == nRet || 4 == nRet )
+                                        {
+                                            if( bFirstFillTxt )
+                                                aFillTxt = aTxt;
+                                            else if( aFillTxt != aTxt )
+                                                aFillTxt.Erase();
+                                            bFirstFillTxt = false;
+                                        }
+                                    }
+                                }
+                                if( MAXLEVEL != nNoPgStt )
+                                {
+                                    if (WW8ListManager::nMaxLevel < nNoPgEnd)
+                                        nNoPgEnd = WW8ListManager::nMaxLevel;
+                                    sStr.APPEND_CONST_ASC( "\\n " );
+                                    sStr += String::CreateFromInt32( nNoPgStt );
+                                    sStr += '-';
+                                    sStr += String::CreateFromInt32( nNoPgEnd  );
+                                    sStr += ' ';
+                                }
+                                if( bOnlyText )
+                                {
+                                    sStr.APPEND_CONST_ASC( "\\p \"" );
+                                    sStr += aFillTxt;
+                                    sStr.AppendAscii(sEntryEnd);
+                                }
+                            }
 
-                            bOnlyText = bOnlyText && 3 == nRet;
-                            if( 3 == nRet || 4 == nRet )
+                            if( sTOption.Len() )
                             {
-                                if( bFirstFillTxt )
-                                    aFillTxt = aTxt;
-                                else if( aFillTxt != aTxt )
-                                    aFillTxt.Erase();
-                                bFirstFillTxt = false;
+                                sStr.APPEND_CONST_ASC( "\\t \"" );
+                                sStr += sTOption;
+                                sStr.AppendAscii(sEntryEnd);
                             }
-                        }
-                    }
-                    if( MAXLEVEL != nNoPgStt )
-                    {
-                        if (WW8ListManager::nMaxLevel < nNoPgEnd)
-                            nNoPgEnd = WW8ListManager::nMaxLevel;
-                        sStr.APPEND_CONST_ASC( "\\n " );
-                        sStr += String::CreateFromInt32( nNoPgStt );
-                        sStr += '-';
-                        sStr += String::CreateFromInt32( nNoPgEnd  );
-                        sStr += ' ';
-                    }
-                    if( bOnlyText )
-                    {
-                        sStr.APPEND_CONST_ASC( "\\p \"" );
-                        sStr += aFillTxt;
-                        sStr.AppendAscii(sEntryEnd);
-                    }
-                }
 
-                if( sTOption.Len() )
-                {
-                    sStr.APPEND_CONST_ASC( "\\t \"" );
-                    sStr += sTOption;
-                    sStr.AppendAscii(sEntryEnd);
+                            if (lcl_IsHyperlinked(pTOX->GetTOXForm(), nTOXLvl))
+                                sStr.APPEND_CONST_ASC("\\h");
+                    }
+                    break;
                 }
-
-                if (lcl_IsHyperlinked(pTOX->GetTOXForm(), nTOXLvl))
-                    sStr.APPEND_CONST_ASC("\\h");
             }
-            break;
-			}
-		}
+        }
 
-        if( sStr.Len() )
+        if ( sStr.Len() )
         {
             GetExport( ).bInWriteTOX = true;
-            GetExport( ).OutputField( 0, eCode, sStr, WRITEFIELD_START | WRITEFIELD_CMD_START |
-                WRITEFIELD_CMD_END );
+            GetExport( ).OutputField( 0, eCode, sStr, 
+                                      WRITEFIELD_START | WRITEFIELD_CMD_START | WRITEFIELD_CMD_END );
         }
     }
-		
+
     GetExport( ).bStartTOX = false;
 }
 
-void AttributeOutputBase::EndTOX( const SwSection& rSect )
+void AttributeOutputBase::EndTOX( const SwSection& rSect,bool bCareEnd )
 {
     const SwTOXBase* pTOX = rSect.GetTOXBase();
     if ( pTOX )
@@ -2455,6 +2403,8 @@ void AttributeOutputBase::EndTOX( const 
         GetExport( ).OutputField( 0, eCode, aEmptyStr, WRITEFIELD_CLOSE );
     }
     GetExport( ).bInWriteTOX = false;
+    if (bCareEnd)
+        OnTOXEnding();
 }
 
 bool MSWordExportBase::GetNumberFmt(const SwField& rFld, String& rStr)

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/ww8attributeoutput.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/ww8attributeoutput.hxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/ww8attributeoutput.hxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/ww8attributeoutput.hxx Mon Sep 17 12:46:16 2012
@@ -52,6 +52,8 @@ public:
     ///
     virtual void StartRun( const SwRedlineData* pRedlineData );
 
+    virtual void OnTOXEnding();
+
     /// End of the text run.
     ///
     /// No-op for binary filters.
@@ -435,8 +437,10 @@ protected:
     /// of the field results if we were forced to split text.
     sal_uInt16 m_nFieldResults;
 
+    bool mbOnTOXEnding;
+
 public:
-    WW8AttributeOutput( WW8Export &rWW8Export ) : AttributeOutputBase(), m_rWW8Export( rWW8Export ) {}
+    WW8AttributeOutput( WW8Export &rWW8Export ) : AttributeOutputBase(), m_rWW8Export( rWW8Export ),mbOnTOXEnding(false) {}
     virtual ~WW8AttributeOutput() {}
 
     /// Return the right export class.

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par.cxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par.cxx Mon Sep 17 12:46:16 2012
@@ -2747,7 +2747,13 @@ bool SwWW8ImplReader::ReadChar(long nPos
             break;
         case 0x15:
             if( !bSpec )        // Juristenparagraph
-                cInsert = '\xa7';
+            {
+                cp_set::iterator aItr = maTOXEndCps.find((WW8_CP)nPosCp);
+	         if (aItr == maTOXEndCps.end())
+                    cInsert = '\xa7';
+	         else
+		      maTOXEndCps.erase(aItr);
+            }
             break;
         case 0x9:
             cInsert = '\x9';    // Tab
@@ -3166,14 +3172,28 @@ bool SwWW8ImplReader::ReadText(long nSta
         // create a new txtnode and join the two paragraphs together
 
         if (bStartLine && !pPreviousNode) // Zeilenende
-		{
-			//Modify here for #119405, by easyfan, 2012-05-24
-			//We will record the CP of a paragraph end ('0x0D'), if current loading contents is from main stream;
-			if (mbOnLoadingMain)
-				maEndParaPos.push_back(l-1);
-			//End of modification, by easyfan
-            AppendTxtNode(*pPaM->GetPoint());
-		}
+        {
+            bool bSplit = true;
+            if (mbCareFirstParaEndInToc)
+            {
+                mbCareFirstParaEndInToc = false;
+                if (pPaM->End() && pPaM->End()->nNode.GetNode().GetTxtNode() &&  pPaM->End()->nNode.GetNode().GetTxtNode()->Len() == 0)
+                    bSplit = false;
+            }
+            if (mbCareLastParaEndInToc)
+            {
+                mbCareLastParaEndInToc = false;
+                if (pPaM->End() && pPaM->End()->nNode.GetNode().GetTxtNode() &&  pPaM->End()->nNode.GetNode().GetTxtNode()->Len() == 0)
+                    bSplit = false;
+            }
+            if (bSplit)
+            {
+                // #119405# - We will record the CP of a paragraph end ('0x0D'), if current loading contents is from main stream;
+                if (mbOnLoadingMain)
+                    maEndParaPos.push_back(l-1);
+                AppendTxtNode(*pPaM->GetPoint());
+            }
+        }
 
         if (pPreviousNode && bStartLine)
         {
@@ -3310,31 +3330,37 @@ bool SwWW8ImplReader::ReadText(long nSta
 
 SwWW8ImplReader::SwWW8ImplReader(sal_uInt8 nVersionPara, SvStorage* pStorage,
     SvStream* pSt, SwDoc& rD, const String& rBaseURL, bool bNewDoc) 
-    : mpDocShell(rD.GetDocShell()),
-      maTracer(*(mpDocShell->GetMedium())),
-      pStg(pStorage),
-      pStrm(pSt),
-      pTableStream(0),
-      pDataStream(0),
-      rDoc(rD),
-      maSectionManager(*this),
-      maInsertedTables(rD),
-      maSectionNameGenerator(rD,CREATE_CONST_ASC("WW")),
-      maGrfNameGenerator(bNewDoc,String('G')),
-      maParaStyleMapper(rD),
-      maCharStyleMapper(rD),
-      maTxtNodesHavingFirstLineOfstSet(),
-      maTxtNodesHavingLeftIndentSet(),
-      pMSDffManager(0),
-      mpAtnNames(0),
-      pAuthorInfos(0),
-      sBaseURL(rBaseURL),
-      m_bRegardHindiDigits( false ),
-      mbNewDoc(bNewDoc),
-      nDropCap(0),
-      nIdctHint(0),
-      bBidi(false),
-      bReadTable(false)
+    : mpDocShell(rD.GetDocShell())
+    , maTracer(*(mpDocShell->GetMedium()))
+    , pStg(pStorage)
+    , pStrm(pSt)
+    , pTableStream(0)
+    , pDataStream(0)
+    , rDoc(rD)
+    , maSectionManager(*this)
+    , maInsertedTables(rD)
+    , maSectionNameGenerator(rD,CREATE_CONST_ASC("WW"))
+    , maGrfNameGenerator(bNewDoc,String('G'))
+    , maParaStyleMapper(rD)
+    , maCharStyleMapper(rD)
+    , maTxtNodesHavingFirstLineOfstSet()
+    , maTxtNodesHavingLeftIndentSet()
+    , pMSDffManager(0)
+    , mpAtnNames(0)
+    , pAuthorInfos(0)
+    , sBaseURL(rBaseURL)
+    , m_bRegardHindiDigits( false )
+    , mbNewDoc(bNewDoc)
+    , nDropCap(0)
+    , nIdctHint(0)
+    , bBidi(false)
+    , bReadTable(false)
+    , mbLoadingTOCCache(false)
+    , mbLoadingTOCHyperlink(false)
+    , mpPosAfterTOC(0)
+    , mbCareFirstParaEndInToc(false)
+    , mbCareLastParaEndInToc(false)
+    , maTOXEndCps()
 	//Modify here for #119405, by easyfan, 2012-05-24
 	,maCurrAttrCP(-1),
 	mbOnLoadingMain(false)
@@ -3660,11 +3686,11 @@ void wwSectionManager::InsertSegments()
         bool bInsertSection = (aIter != aStart) ? (aIter->IsContinous() &&  bThisAndPreviousAreCompatible): false;
         bool bInsertPageDesc = !bInsertSection;
         bool bProtected = SectionIsProtected(*aIter); // do we really  need this ?? I guess I have a different logic in editshell which disales this...
-	if (bUseEnhFields && mrReader.pWDop->fProtEnabled && aIter->IsNotProtected()) {
-	    // here we have the special case that the whole document is protected, with the execption of this section.
-	    // I want to address this when I do the section rework, so for the moment we disable the overall protection then...
-	    mrReader.rDoc.set(IDocumentSettingAccess::PROTECT_FORM, false );
-	}
+        if (bUseEnhFields && mrReader.pWDop->fProtEnabled && aIter->IsNotProtected()) {
+            // here we have the special case that the whole document is protected, with the execption of this section.
+            // I want to address this when I do the section rework, so for the moment we disable the overall protection then...
+            mrReader.rDoc.set(IDocumentSettingAccess::PROTECT_FORM, false );
+        }
 
 
         if (bInsertPageDesc)

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par.hxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par.hxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par.hxx Mon Sep 17 12:46:16 2012
@@ -798,9 +798,9 @@ struct WW8PostProcessAttrsInfo
 //-----------------------------------------
 //            Storage-Reader
 //-----------------------------------------
-//Modify here for #119405, by easyfan, 2012-05-24
+typedef std::set<WW8_CP> cp_set;
+
 typedef std::vector<WW8_CP> cp_vector;
-//End of modification, by easyfan
 
 class SwWW8ImplReader
 {
@@ -1092,7 +1092,7 @@ private:
                             //     the very 1st Line Numbering and ignore the rest)
 
     bool bFirstPara;        // first paragraph?
-	bool bFirstParaOfPage;//cs2c--xushanchuan add for bug11210
+    bool bFirstParaOfPage;//cs2c--xushanchuan add for bug11210
     bool bParaAutoBefore;
     bool bParaAutoAfter;
 
@@ -1100,15 +1100,23 @@ private:
     int nDropCap;
 
     int nIdctHint;
-	bool bBidi;
+    bool bBidi;
     bool bReadTable;
     boost::shared_ptr<SwPaM> mpTableEndPaM;
-
-	//Modify here for #119405, by easyfan, 2012-05-24
-	cp_vector maEndParaPos;
-	WW8_CP maCurrAttrCP;
-	bool mbOnLoadingMain:1;
-	//End of modification, by easyfan
+    // Indicate that currently on loading a TOC, managed by Read_F_TOX() and End_Field()
+    bool mbLoadingTOCCache;
+    // Indicate that current on loading a hyperlink, which is inside a TOC; Managed by Read_F_Hyperlink() and End_Field()
+    bool mbLoadingTOCHyperlink;
+    // a document position recorded the after-position of TOC section, managed by Read_F_TOX() and End_Field()
+    SwPaM* mpPosAfterTOC;
+
+    bool mbCareFirstParaEndInToc;
+    bool mbCareLastParaEndInToc;
+    cp_set maTOXEndCps;
+
+    cp_vector maEndParaPos;
+    WW8_CP maCurrAttrCP;
+    bool mbOnLoadingMain:1;
 //---------------------------------------------
 
     const SprmReadInfo& GetSprmReadInfo(sal_uInt16 nId) const;

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par5.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par5.cxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par5.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par5.cxx Mon Sep 17 12:46:16 2012
@@ -86,8 +86,6 @@
 
 #include <algorithm> // #i24377#
 
-//#define WW_NATIVE_TOC 0
-
 #define MAX_FIELDLEN 64000
 
 #define WW8_TOX_LEVEL_DELIM     ':'
@@ -317,13 +315,15 @@ long SwWW8ImplReader::Read_Book(WW8PLCFM
         return 0;
     }
 
-    //"_Toc*" and "_Hlt*" are unnecessary
+    // "_Hlt*" are unnecessary
     const String* pName = pB->GetName();
-#if !defined(WW_NATIVE_TOC)
-    if(    !pName || pName->EqualsIgnoreCaseAscii( "_Toc", 0, 4 )
-        || pName->EqualsIgnoreCaseAscii( "_Hlt", 0, 4 ) )
+    // Now, as we read the TOC field completely, we also need the hyperlinks inside keep available.
+    // So the hidden bookmarks inside for hyperlink jumping also should be kept.
+    if ( !pName || 
+         pName->EqualsIgnoreCaseAscii( "_Hlt", 0, 4 ) )
+    {
         return 0;
-#endif 
+    }
 
     //JP 16.11.98: ToUpper darf auf keinen Fall gemacht werden, weil der
     //Bookmark- name ein Hyperlink-Ziel sein kann!
@@ -662,7 +662,8 @@ sal_uInt16 SwWW8ImplReader::End_Field()
     sal_uInt16 nRet = 0;
     WW8PLCFx_FLD* pF = pPlcxMan->GetFld();
     ASSERT(pF, "WW8PLCFx_FLD - Pointer nicht da");
-    if (!pF || !pF->EndPosIsFieldEnd())
+    WW8_CP nCP = 0;
+    if (!pF || !pF->EndPosIsFieldEnd(nCP))
         return nRet;
 
     const SvtFilterOptions* pOpt = SvtFilterOptions::Get();
@@ -693,28 +694,43 @@ sal_uInt16 SwWW8ImplReader::End_Field()
             }
         }
         break;
-#if defined(WW_NATIVE_TOC)
-        case 8: // TOX_INDEX
-        case 13: // TOX_CONTENT
-        case 88: // HYPERLINK
-        case 37: // REF
-        if (pPaM!=NULL && pPaM->GetPoint()!=NULL) {
-
-            SwPosition aEndPos = *pPaM->GetPoint();
-            SwPaM aFldPam( maFieldStack.back().GetPtNode(), maFieldStack.back().GetPtCntnt(), aEndPos.nNode, aEndPos.nContent.GetIndex());
-            SwFieldBookmark *pFieldmark=(SwFieldBookmark*)rDoc.makeFieldBookmark(aFldPam, maFieldStack.back().GetBookmarkName(), maFieldStack.back().GetBookmarkType());
-            ASSERT(pFieldmark!=NULL, "hmmm; why was the bookmark not created?");
-            if (pFieldmark!=NULL) {
-                const IFieldmark::parameter_map_t& pParametersToAdd = maFieldStack.back().getParameters();
-                pFieldmark->GetParameters()->insert(pParameters.begin(), pParameters.end());
-            }
-        }
-        break;
-#else
+            // Doing corresponding status management for TOC field, index field, hyperlink field and page reference field
+            case 13://TOX
+            case 8://index
+                if (mbLoadingTOCCache)
+                {
+                    maTOXEndCps.insert(nCP);
+                    mbLoadingTOCCache = false;
+                    if ( pPaM->End() && 
+                         pPaM->End()->nNode.GetNode().GetTxtNode() && 
+                         pPaM->End()->nNode.GetNode().GetTxtNode()->Len() == 0 )
+                    {
+                            JoinNode(*pPaM);
+                    }
+                    else
+                    {
+                            mbCareLastParaEndInToc = true;
+                    }
+                    
+                    if (mpPosAfterTOC)
+                    {
+                        *pPaM = *mpPosAfterTOC;
+                        delete mpPosAfterTOC;
+                        mpPosAfterTOC = 0;
+                    }
+                }
+                break;
+            case 37://REF
+                if (mbLoadingTOCCache && !mbLoadingTOCHyperlink)
+                {
+                    pCtrlStck->SetAttr(*pPaM->GetPoint(),RES_TXTATR_INETFMT);
+                }
+                break;
             case 88:
+                if (mbLoadingTOCHyperlink)
+                    mbLoadingTOCHyperlink = false;
                 pCtrlStck->SetAttr(*pPaM->GetPoint(),RES_TXTATR_INETFMT);
-            break;
-#endif
+                break;
             case 36:
             case 68:
                 //Move outside the section associated with this type of field
@@ -732,19 +748,15 @@ bool AcceptableNestedField(sal_uInt16 nF
 {
     switch (nFieldCode)
     {
-#if defined(WW_NATIVE_TOC)
-    case 8:  // allow recursive field in TOC...
-    case 13: // allow recursive field in TOC...
-#endif
+        case 8:  // allow recursive field in TOC...
+        case 13: // allow recursive field in TOC...
         case 36:
         case 68:
         case 79:
         case 88:
-        // --> OD 2007-01-02 #b6504125#
         // Accept AutoTextList field as nested field.
         // Thus, the field result is imported as plain text.
         case 89:
-        // <--
             return true;
         default:
             return false;
@@ -2137,27 +2149,37 @@ eF_ResT SwWW8ImplReader::Read_F_PgRef( W
     _ReadFieldParams aReadParam( rStr );
     while( -1 != ( nRet = aReadParam.SkipToNextToken() ))
     {
-        switch( nRet )
+        if ( nRet == -2 &&
+             !sOrigName.Len() )
         {
-        case -2:
-            if( !sOrigName.Len() )
-                sOrigName = aReadParam.GetResult();
-            break;
+            sOrigName = aReadParam.GetResult();
         }
     }
 
     String sName(GetMappedBookmark(sOrigName));
 
-#if defined(WW_NATIVE_TOC)
-    if (1) {
-    ::rtl::OUString aBookmarkName=::rtl::OUString::createFromAscii("_REF");
-    maFieldStack.back().SetBookmarkName(aBookmarkName);
-    maFieldStack.back().SetBookmarkType(::rtl::OUString::createFromAscii(ODF_PAGEREF));
-    maFieldStack.back().AddParam(rtl::OUString(), sName);
-    return FLD_TEXT;
+    //loading page reference field in TOC
+    if (mbLoadingTOCCache )
+    {
+        //Step 1. Insert page ref representation as plain text
+        //Step 2. If there is no hyperlink settings for current toc, assign link to current ref area
+        if ( !mbLoadingTOCHyperlink)
+        {
+            String sURL,sTarget;
+            if( sName.Len() )
+                ( sURL += INET_MARK_TOKEN ) += sName;
+            SwFmtINetFmt aURL( sURL, sTarget );
+            String sLinkStyle = String::CreateFromAscii("Index Link");
+            sal_uInt16 nPoolId =
+                SwStyleNameMapper::GetPoolIdFromUIName( sLinkStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
+            aURL.SetVisitedFmt(sLinkStyle);
+            aURL.SetINetFmt(sLinkStyle);
+            aURL.SetVisitedFmtId(nPoolId);
+            aURL.SetINetFmtId(nPoolId);
+            pCtrlStck->NewAttr( *pPaM->GetPoint(), aURL );
+        }
+        return FLD_TEXT;
     }
-#endif
-
 
     SwGetRefField aFld(
         (SwGetRefFieldType*)rDoc.GetSysFldType( RES_GETREFFLD ), sName,
@@ -2175,7 +2197,7 @@ bool ConvertMacroSymbol( const String& r
 	if( rReference.EqualsAscii( "(" ) )
 	{
 		bConverted = true;
-		sal_Unicode cSymbol;
+		sal_Unicode cSymbol = 0x0000;
 		if( rName.EqualsAscii( "CheckIt" ) )
 			cSymbol = 0xF06F;
 		else if( rName.EqualsAscii( "UncheckIt" ) )
@@ -2966,15 +2988,7 @@ sal_uInt16 lcl_GetMaxValidWordTOCLevel(c
 
 eF_ResT SwWW8ImplReader::Read_F_Tox( WW8FieldDesc* pF, String& rStr )
 {
-#if defined(WW_NATIVE_TOC)
-    if (1) {
-    ::rtl::OUString aBookmarkName=::rtl::OUString::createFromAscii("_TOC");
-    maFieldStack.back().SetBookmarkName(aBookmarkName);
-    maFieldStack.back().SetBookmarkType(::rtl::OUString::createFromAscii(ODF_TOC));
-//     maFieldStack.back().AddParam(::rtl::OUString::createFromAscii("Description"), aFormula.sToolTip);
-    return FLD_TEXT;
-    }
-#endif
+    mbLoadingTOCCache = true;
 
     if (pF->nLRes < 3)
         return FLD_TEXT;      // ignore (#i25440#)
@@ -3105,6 +3119,7 @@ eF_ResT SwWW8ImplReader::Read_F_Tox( WW8
     case TOX_CONTENT:
         {
             bool bIsHyperlink = false;
+            bool bShowPage = true;
             // TOX_OUTLINELEVEL setzen wir genau dann, wenn
             // die Parameter \o in 1 bis 9 liegen
             // oder der Parameter \f existiert
@@ -3214,6 +3229,7 @@ eF_ResT SwWW8ImplReader::Read_F_Tox( WW8
                 case 'n': // don't print page numbers
                     {
                         // read START and END param
+                        bShowPage = false;
                         sal_uInt16 nStart, nEnd;
                         if( !aReadParam.GetTokenSttFromTo(  &nStart, &nEnd,
                             WW8ListManager::nMaxLevel ) )
@@ -3276,27 +3292,37 @@ eF_ResT SwWW8ImplReader::Read_F_Tox( WW8
                 }
             }
 
-            if (bIsHyperlink)
-            {
-                SwForm aForm(pBase->GetTOXForm());
-                sal_uInt16 nEnd = aForm.GetFormMax()-1;
-                SwFormToken aLinkStart(TOKEN_LINK_START);
-                SwFormToken aLinkEnd(TOKEN_LINK_END);
+            // For loading the expression of TOC field, we need to mapping its parameters to TOX entries tokens
+            // also include the hyperlinks and page references
+            SwFormToken aLinkStart(TOKEN_LINK_START);
+            SwFormToken aLinkEnd(TOKEN_LINK_END);
+            aLinkStart.sCharStyleName = String::CreateFromAscii("Index Link");
+            aLinkEnd.sCharStyleName = String::CreateFromAscii("Index Link");
+            SwForm aForm(pBase->GetTOXForm());
+            sal_uInt16 nEnd = aForm.GetFormMax()-1;
 
-                // -> #i21237#
-                for(sal_uInt16 nLevel = 1; nLevel <= nEnd; ++nLevel)
+            for(sal_uInt16 nLevel = 1; nLevel <= nEnd; ++nLevel)
+            {
+                SwFormTokens aPattern = aForm.GetPattern(nLevel);
+                if ( bIsHyperlink )
                 {
-                    SwFormTokens aPattern = aForm.GetPattern(nLevel);
-
                     aPattern.insert(aPattern.begin(), aLinkStart);
-                    aPattern.push_back(aLinkEnd);
-
-                    aForm.SetPattern(nLevel, aPattern);
-
                 }
-                // <- #i21237#
-                pBase->SetTOXForm(aForm);
+                else if ( bShowPage )
+                {
+                    for (SwFormTokens::iterator aItr = aPattern.begin();aItr!= aPattern.end();aItr++)
+                    {
+                        if (aItr->eTokenType == TOKEN_PAGE_NUMS)
+                        {
+                            aPattern.insert(aItr,aLinkStart);
+                            break;
+                        }
+                    }
+                }
+                aPattern.push_back(aLinkEnd);
+                aForm.SetPattern(nLevel, aPattern);
             }
+            pBase->SetTOXForm(aForm);
 
             if (!nMaxLevel)
                 nMaxLevel = WW8ListManager::nMaxLevel;
@@ -3413,8 +3439,8 @@ eF_ResT SwWW8ImplReader::Read_F_Tox( WW8
         break;
     } // ToxBase fertig
 
-    // Update fuer TOX anstossen
-    rDoc.SetUpdateTOX(true);
+    // no Update of TOC anymore as its actual content is imported and kept.
+    //rDoc.SetUpdateTOX(true);
 
     // #i21237#
     // propagate tab stops from paragraph styles used in TOX to
@@ -3423,6 +3449,14 @@ eF_ResT SwWW8ImplReader::Read_F_Tox( WW8
 
     //#i10028# inserting a toc implicltly acts like a parabreak
     //in word and writer
+
+    if ( pPaM->End() && 
+         pPaM->End()->nNode.GetNode().GetTxtNode() && 
+         pPaM->End()->nNode.GetNode().GetTxtNode()->Len() != 0 )
+    {
+        mbCareFirstParaEndInToc = true;
+    }
+
     if (pPaM->GetPoint()->nContent.GetIndex())
         AppendTxtNode(*pPaM->GetPoint());
 
@@ -3453,14 +3487,22 @@ eF_ResT SwWW8ImplReader::Read_F_Tox( WW8
 
     rDoc.InsertTableOf(*pPaM->GetPoint(), *aFltTOX.GetBase());
 
-    //inserting a toc inserts a section before this point, so adjust pos
-    //for future page/section segment insertion
+    //The TOC field representation contents should be inserted into TOC section, but not after TOC section.
+    //So we need update the document position when loading TOC representation and after loading TOC;
+    if (mpPosAfterTOC)
+    {
+        delete mpPosAfterTOC;
+    }
+    mpPosAfterTOC = new SwPaM(*pPaM);
+    (*pPaM).Move(fnMoveBackward);
     SwPaM aRegion(*pPaM);
-    aRegion.Move(fnMoveBackward);
+
     ASSERT(rDoc.GetCurTOX(*aRegion.GetPoint()), "Misunderstood how toc works");
     if (SwTOXBase* pBase2 = (SwTOXBase*)rDoc.GetCurTOX(*aRegion.GetPoint()))
     {
-        if(nIndexCols>1)
+        pBase2->SetMSTOCExpression(rStr);
+
+        if ( nIndexCols > 1 )
         {
             // Set the column number for index
             SfxItemSet aSet( rDoc.GetAttrPool(), RES_COL, RES_COL );
@@ -3470,8 +3512,9 @@ eF_ResT SwWW8ImplReader::Read_F_Tox( WW8
             pBase2->SetAttrSet( aSet );
         }
 
-        maSectionManager.PrependedInlineNode(*pPaM->GetPoint(),
-            *aRegion.GetNode());
+        // inserting a toc inserts a section before this point, so adjust pos
+        // for future page/section segment insertion
+        maSectionManager.PrependedInlineNode( *mpPosAfterTOC->GetPoint(), *aRegion.GetNode() );
     }
 
     // Setze Ende in Stack
@@ -3479,7 +3522,11 @@ eF_ResT SwWW8ImplReader::Read_F_Tox( WW8
 
     if (!maApos.back()) //a para end in apo doesn't count
         bWasParaEnd = true;
-    return FLD_OK;
+
+    //Return FLD_TEXT, instead of FLD_OK
+    //FLD_TEXT means the following content, commonly indicate the field representation content should be parsed
+    //FLD_OK means the current field loading is finished. The rest part should be ignored.
+    return FLD_TEXT;
 }
 
 eF_ResT SwWW8ImplReader::Read_F_Shape(WW8FieldDesc* /*pF*/, String& /*rStr*/)
@@ -3494,16 +3541,6 @@ eF_ResT SwWW8ImplReader::Read_F_Shape(WW
 
 eF_ResT SwWW8ImplReader::Read_F_Hyperlink( WW8FieldDesc* /*pF*/, String& rStr )
 {
-#if defined(WW_NATIVE_TOC)
-    if (1) {
-    ::rtl::OUString aBookmarkName=::rtl::OUString::createFromAscii("_HYPERLINK");
-    maFieldStack.back().SetBookmarkName(aBookmarkName);
-    maFieldStack.back().SetBookmarkType(::rtl::OUString::createFromAscii(ODF_HYPERLINK));
-//     maFieldStack.back().AddParam(::rtl::OUString::createFromAscii("Description"), aFormula.sToolTip);
-    return FLD_TEXT;
-    }
-#endif
-
     String sURL, sTarget, sMark;
     bool bDataImport = false;
     //HYPERLINk "filename" [switches]
@@ -3538,6 +3575,10 @@ eF_ResT SwWW8ImplReader::Read_F_Hyperlin
                         if( sMark.Len() && '"' == sMark.GetChar( sMark.Len()-1 ))
                             sMark.Erase( sMark.Len() - 1 );
 
+                        if (mbLoadingTOCCache)
+                        {
+                            mbLoadingTOCHyperlink = true;//on loading a TOC field nested hyperlink field
+                        }
                     }
                     break;
                 case 't':
@@ -3563,6 +3604,17 @@ eF_ResT SwWW8ImplReader::Read_F_Hyperlin
         ( sURL += INET_MARK_TOKEN ) += sMark;
 
     SwFmtINetFmt aURL( sURL, sTarget );
+    // If on loading TOC field, change the default style into the "index link"
+    if (mbLoadingTOCCache)
+    {
+        String sLinkStyle = String::CreateFromAscii("Index Link");
+        sal_uInt16 nPoolId =
+            SwStyleNameMapper::GetPoolIdFromUIName( sLinkStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
+        aURL.SetVisitedFmt(sLinkStyle);
+        aURL.SetINetFmt(sLinkStyle);
+        aURL.SetVisitedFmtId(nPoolId);
+        aURL.SetINetFmtId(nPoolId);
+    }
 
     //As an attribute this needs to be closed, and that'll happen from
     //EndExtSprm in conjunction with the maFieldStack If there are are flyfrms

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par6.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par6.cxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par6.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/ww8par6.cxx Mon Sep 17 12:46:16 2012
@@ -3884,6 +3884,15 @@ void SwWW8ImplReader::Read_CColl( sal_uI
         || pCollA[nId].bColl )              // oder Para-Style ?
         return;                             // dann ignorieren
 
+    // if current on loading a TOC field, and current trying to apply a hyperlink character style, 
+    // just ignore. For the hyperlinks inside TOC in MS Word is not same with a common hyperlink
+    // Character styles: without underline and blue font color. And such type style will be applied in others
+    // processes.
+    if (mbLoadingTOCCache && pCollA[nId].GetWWStyleId() == ww::stiHyperlink)
+    {
+        return;
+    }
+
     NewAttr( SwFmtCharFmt( (SwCharFmt*)pCollA[nId].pFmt ) );
     nCharFmt = (short) nId;
 }

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/ww8scan.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/ww8scan.cxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/ww8scan.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/ww8scan.cxx Mon Sep 17 12:46:16 2012
@@ -3786,7 +3786,7 @@ bool WW8PLCFx_FLD::StartPosIsFieldStart(
     return true;
 }
 
-bool WW8PLCFx_FLD::EndPosIsFieldEnd()
+bool WW8PLCFx_FLD::EndPosIsFieldEnd(WW8_CP& nCP)
 {
     bool bRet = false;
 
@@ -3799,7 +3799,10 @@ bool WW8PLCFx_FLD::EndPosIsFieldEnd()
         void* pData;
         sal_Int32 nTest;
         if ( pPLCF->Get(nTest, pData) && ((((sal_uInt8*)pData)[0] & 0x1f) == 0x15) )
+        {
+            nCP = nTest;
             bRet = true;
+        }
 
         pPLCF->SetIdx(n);
     }
@@ -4116,7 +4119,14 @@ WW8PLCFx& WW8PLCFx_Book::operator ++( in
         else if( l1 < l0 )
             nIsEnd = 1;
         else
-            nIsEnd = ( nIsEnd ) ? 0 : 1;
+        {
+            const void * p = pBook[0]->GetData(pBook[0]->GetIdx());
+            long nPairFor = (p == NULL)? 0L : SVBT16ToShort(*((SVBT16*) p));
+            if (nPairFor == pBook[1]->GetIdx())
+                nIsEnd = 0;
+            else
+                nIsEnd = ( nIsEnd ) ? 0 : 1;
+        }
     }
     return *this;
 }

Modified: incubator/ooo/trunk/main/sw/source/filter/ww8/ww8scan.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/filter/ww8/ww8scan.hxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/filter/ww8/ww8scan.hxx (original)
+++ incubator/ooo/trunk/main/sw/source/filter/ww8/ww8scan.hxx Mon Sep 17 12:46:16 2012
@@ -701,7 +701,7 @@ public:
     virtual void GetSprms(WW8PLCFxDesc* p);
     virtual WW8PLCFx& operator ++( int );
     bool StartPosIsFieldStart();
-    bool EndPosIsFieldEnd();
+    bool EndPosIsFieldEnd(WW8_CP&);
     bool GetPara(long nIdx, WW8FieldDesc& rF);
 };
 

Modified: incubator/ooo/trunk/main/sw/source/ui/index/toxmgr.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sw/source/ui/index/toxmgr.cxx?rev=1386590&r1=1386589&r2=1386590&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sw/source/ui/index/toxmgr.cxx (original)
+++ incubator/ooo/trunk/main/sw/source/ui/index/toxmgr.cxx Mon Sep 17 12:46:16 2012
@@ -459,7 +459,9 @@ sal_Bool SwTOXMgr::UpdateOrInsertTOX(con
         if (pNewTOX != NULL) // => pTOX != NULL
             pDoc->ChgTOX(*pTOX, *pNewTOX);
 
-		bRet = pSh->UpdateTableOf(*pTOX, pSet);
+        pTOX->DisableKeepExpression();
+        bRet = pSh->UpdateTableOf(*pTOX, pSet);
+        pTOX->EnableKeepExpression();
 
         if (pDoc->GetIDocumentUndoRedo().DoesUndo())
         {

Propchange: incubator/ooo/trunk/test/
------------------------------------------------------------------------------
  Merged /incubator/ooo/branches/AOO34/test:r1346776-1346777,1347535,1348052,1350569,1352456,1369110,1371068
  Merged /incubator/ooo/branches/writer001/test:r1386501-1386577
  Merged /incubator/ooo/branches/alg/svgreplacement/test:r1205420-1220782
  Merged /incubator/ooo/branches/alg/linecap/test:r1226811-1232461
  Merged /incubator/ooo/trunk/test:r1353792-1374969

Propchange: incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/vcl/
------------------------------------------------------------------------------
  Merged /incubator/ooo/branches/alg/linecap/main/test/testcommon/source/org/openoffice/test/vcl:r1226811-1232461
  Merged /incubator/ooo/branches/AOO34/main/test/testcommon/source/org/openoffice/test/vcl:r1346776-1346777,1347535,1348052,1350569,1352456,1369110,1371068
  Merged /incubator/ooo/branches/alg/svgreplacement/main/test/testcommon/source/org/openoffice/test/vcl:r1205420-1220782
  Merged /incubator/ooo/branches/writer001/test/testcommon/source/org/openoffice/test/vcl:r1386501-1386577



Re: svn commit: r1386590 - in /incubator/ooo/trunk: ./ main/sw/inc/ main/sw/source/core/doc/ main/sw/source/core/tox/ main/sw/source/filter/ww8/ main/sw/source/filter/ww8/dump/ main/sw/source/ui/index/ test/ test/testcommon/source/org/openoffice/test/vcl/

Posted by Pavel Janík <Pa...@Janik.cz>.
Hi,

On Sep 17, 2012, at 2:46 PM, orw@apache.org wrote:

> +void WW8_WrtBookmarks::MoveFieldMarks(sal_uLong nFrom,sal_uLong nTo)
> +{
> +    std::pair<CPItr,CPItr> aRange = aSttCps.equal_range(nFrom);
> +    CPItr aItr = aRange.first;
> +    while (aItr != aRange.second)
> +    {
> +        if (aItr->second)
> +        {
> +            if (aItr->second->first == nFrom)

the last line is a source of compiler warning:

sw/source/filter/ww8/wrtww8.cxx: In member function ‘void WW8_WrtBookmarks::MoveFieldMarks(sal_uLong, sal_uLong)’:
sw/source/filter/ww8/wrtww8.cxx:315: warning: comparison between signed and unsigned integer expressions

Can you please fix it?
-- 
Pavel Janík