tdf#89783: sal_uInt16 replacement by size_t: sections

These replacements allow LO to load, save and mail merge documents having
more than 65536 sections in total.

Change-Id: I0e70889b1edc6e472a39f1f2638ac3c70a0d7058

Signed-off-by: Katarina Behrens <Katarina.Behrens@cib.de>
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 6daed2f..c935ede 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1375,7 +1375,7 @@ public:
    const SwSectionFmts& GetSections() const { return *mpSectionFmtTbl; }
    SwSectionFmt *MakeSectionFmt( SwSectionFmt *pDerivedFrom );
    void DelSectionFmt( SwSectionFmt *pFmt, bool bDelNodes = false );
    void UpdateSection(sal_uInt16 const nSect, SwSectionData &,
    void UpdateSection(size_t const nSect, SwSectionData &,
            SfxItemSet const*const = 0, bool const bPreventLinkUpdate = false);
    OUString GetUniqueSectionName( const OUString* pChkStr = 0 ) const;

diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index 93590f6..386bf51 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -99,10 +99,10 @@ public:
        this->erase( begin() + aStartIdx, begin() + aEndIdx);
    }

    sal_uInt16 GetPos(Value const& p) const
    size_t GetPos(Value const& p) const
    {
        const_iterator const it = std::find(begin(), end(), p);
        return it == end() ? USHRT_MAX : it - begin();
        return it == end() ? SIZE_MAX : it - begin();
    }

    bool Contains(Value const& p) const
@@ -126,7 +126,7 @@ public:
    virtual Value GetFmt(size_t idx) const SAL_OVERRIDE
        { return std::vector<Value>::operator[](idx); }

    inline sal_uInt16 GetPos(const SwFmt *p) const
    inline size_t GetPos(const SwFmt *p) const
        { return SwVectorModifyBase<Value>::GetPos( static_cast<Value>( const_cast<SwFmt*>( p ) ) ); }
    inline bool Contains(const SwFmt *p) const {
        Value p2 = dynamic_cast<Value>(const_cast<SwFmt*>(p));
diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index 4e3ca7e..cca79a1 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -820,11 +820,11 @@ public:
     and not an inner one. */
    SwSection* GetAnySection( bool bOutOfTab = false, const Point* pPt = 0 );

    sal_uInt16 GetSectionFmtCount() const;
    sal_uInt16 GetSectionFmtPos( const SwSectionFmt& ) const;
    const SwSectionFmt& GetSectionFmt(sal_uInt16 nFmt) const;
    void DelSectionFmt( sal_uInt16 nFmt );
    void UpdateSection(sal_uInt16 const nSect, SwSectionData &,
    size_t GetSectionFmtCount() const;
    size_t GetSectionFmtPos(const SwSectionFmt&) const;
    const SwSectionFmt& GetSectionFmt(size_t nFmt) const;
    void DelSectionFmt( size_t nFmt);
    void UpdateSection( size_t const nSect, SwSectionData &,
            SfxItemSet const*const  = 0);
    bool IsAnySectionInDoc( bool bChkReadOnly = false,
                            bool bChkHidden = false,
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 65a476a..eaf0410 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1378,7 +1378,7 @@ bool SwDoc::RemoveInvisibleContent()
                SwSectionData aSectionData( *pSect );
                aSectionData.SetCondition( OUString() );
                aSectionData.SetHidden( false );
                UpdateSection( static_cast<sal_uInt16>(n), aSectionData );
                UpdateSection( n, aSectionData );
            }
        }

diff --git a/sw/source/core/docnode/ndsect.cxx b/sw/source/core/docnode/ndsect.cxx
index 1504807..9bb5888 100644
--- a/sw/source/core/docnode/ndsect.cxx
+++ b/sw/source/core/docnode/ndsect.cxx
@@ -606,8 +606,8 @@ void SwDoc::DelSectionFmt( SwSectionFmt *pFmt, bool bDelNodes )
    getIDocumentState().SetModified();
}

void SwDoc::UpdateSection(sal_uInt16 const nPos, SwSectionData & rNewData,
        SfxItemSet const*const pAttr, bool const bPreventLinkUpdate)
void SwDoc::UpdateSection( size_t const nPos, SwSectionData & rNewData,
        SfxItemSet const*const pAttr, bool const bPreventLinkUpdate )
{
    SwSectionFmt* pFmt = (*mpSectionFmtTbl)[ nPos ];
    SwSection* pSection = pFmt->GetSection();
diff --git a/sw/source/core/edit/edsect.cxx b/sw/source/core/edit/edsect.cxx
index dc046d3..028a6f2 100644
--- a/sw/source/core/edit/edsect.cxx
+++ b/sw/source/core/edit/edsect.cxx
@@ -110,7 +110,7 @@ SwSection* SwEditShell::GetAnySection( bool bOutOfTab, const Point* pPt )
    return NULL;
}

sal_uInt16 SwEditShell::GetSectionFmtCount() const
size_t SwEditShell::GetSectionFmtCount() const
{
    return GetDoc()->GetSections().size();
}
@@ -137,18 +137,18 @@ bool SwEditShell::IsAnySectionInDoc( bool bChkReadOnly, bool bChkHidden, bool bC
    return false;
}

sal_uInt16 SwEditShell::GetSectionFmtPos( const SwSectionFmt& rFmt ) const
size_t SwEditShell::GetSectionFmtPos( const SwSectionFmt& rFmt ) const
{
    SwSectionFmt* pFmt = const_cast<SwSectionFmt*>(&rFmt);
    return GetDoc()->GetSections().GetPos( pFmt );
}

const SwSectionFmt& SwEditShell::GetSectionFmt( sal_uInt16 nFmt ) const
const SwSectionFmt& SwEditShell::GetSectionFmt(size_t nFmt) const
{
    return *GetDoc()->GetSections()[ nFmt ];
}

void SwEditShell::DelSectionFmt( sal_uInt16 nFmt )
void SwEditShell::DelSectionFmt(size_t nFmt)
{
    StartAllAction();
    GetDoc()->DelSectionFmt( GetDoc()->GetSections()[ nFmt ] );
@@ -157,7 +157,7 @@ void SwEditShell::DelSectionFmt( sal_uInt16 nFmt )
    EndAllAction();
}

void SwEditShell::UpdateSection(sal_uInt16 const nSect,
void SwEditShell::UpdateSection(size_t const nSect,
        SwSectionData & rNewData, SfxItemSet const*const pAttr)
{
    StartAllAction();
diff --git a/sw/source/core/unocore/unosect.cxx b/sw/source/core/unocore/unosect.cxx
index a55cd80..2a4de5c 100644
--- a/sw/source/core/unocore/unosect.cxx
+++ b/sw/source/core/unocore/unosect.cxx
@@ -1682,7 +1682,7 @@ throw (uno::RuntimeException, std::exception)
        aSection.SetSectionName(rName);

        const SwSectionFmts& rFmts = pFmt->GetDoc()->GetSections();
        sal_uInt16 nApplyPos = USHRT_MAX;
        size_t nApplyPos = SIZE_MAX;
        for( size_t i = 0; i < rFmts.size(); ++i )
        {
            if(rFmts[i]->GetSection() == pSect)
@@ -1694,7 +1694,7 @@ throw (uno::RuntimeException, std::exception)
                throw uno::RuntimeException();
            }
        }
        if(nApplyPos != USHRT_MAX)
        if (nApplyPos != SIZE_MAX)
        {
            {
                UnoActionContext aContext(pFmt->GetDoc());
diff --git a/sw/source/ui/dialog/uiregionsw.cxx b/sw/source/ui/dialog/uiregionsw.cxx
index d72739d..2281069 100644
--- a/sw/source/ui/dialog/uiregionsw.cxx
+++ b/sw/source/ui/dialog/uiregionsw.cxx
@@ -73,8 +73,8 @@ static void lcl_FillList( SwWrtShell& rSh, ComboBox& rSubRegions, ComboBox* pAva
{
    if( !pNewFmt )
    {
        const sal_uInt16 nCount = rSh.GetSectionFmtCount();
        for(sal_uInt16 i=0;i<nCount;i++)
        const size_t nCount = rSh.GetSectionFmtCount();
        for (size_t i = 0; i<nCount; i++)
        {
            SectionType eTmpType;
            const SwSectionFmt* pFmt = &rSh.GetSectionFmt(i);
@@ -142,7 +142,7 @@ private:
    SwFmtNoBalancedColumns  m_Balance;
    SvxFrameDirectionItem   m_FrmDirItem;
    SvxLRSpaceItem          m_LRSpaceItem;
    sal_uInt16                  m_nArrPos;
    size_t                  m_nArrPos;
    // shows, if maybe textcontent is in the region
    bool                    m_bContent  : 1;
    // for multiselection, mark at first, then work with TreeListBox!
@@ -150,7 +150,7 @@ private:
    uno::Sequence<sal_Int8> m_TempPasswd;

public:
    SectRepr(sal_uInt16 nPos, SwSection& rSect);
    SectRepr(size_t nPos, SwSection& rSect);

    bool    operator< (const SectRepr& rSectRef) const
            { return m_nArrPos <  rSectRef.GetArrPos(); }
@@ -164,7 +164,7 @@ public:
    SvxFrameDirectionItem&  GetFrmDir()         { return m_FrmDirItem; }
    SvxLRSpaceItem&         GetLRSpace()        { return m_LRSpaceItem; }

    sal_uInt16              GetArrPos() const { return m_nArrPos; }
    size_t              GetArrPos() const { return m_nArrPos; }
    OUString            GetFile() const;
    OUString            GetSubRegion() const;
    void                SetFile(OUString const& rFile);
@@ -182,7 +182,7 @@ public:
        { m_TempPasswd = rPasswd; }
};

SectRepr::SectRepr( sal_uInt16 nPos, SwSection& rSect )
SectRepr::SectRepr( size_t nPos, SwSection& rSect )
    : m_SectionData( rSect )
    , m_Brush( RES_BACKGROUND )
    , m_FrmDirItem( FRMDIR_ENVIRONMENT, RES_FRAMEDIR )
@@ -443,8 +443,8 @@ void SwEditRegionDlg::RecurseList( const SwSectionFmt* pFmt, SvTreeListEntry* pE
    SvTreeListEntry* pSelEntry = 0;
    if (!pFmt)
    {
        const sal_uInt16 nCount=rSh.GetSectionFmtCount();
        for ( sal_uInt16 n=0; n < nCount; n++ )
        const size_t nCount=rSh.GetSectionFmtCount();
        for ( size_t n = 0; n < nCount; n++ )
        {
            SectionType eTmpType;
            if( !( pFmt = &rSh.GetSectionFmt(n))->GetParent() &&
@@ -503,15 +503,15 @@ void SwEditRegionDlg::RecurseList( const SwSectionFmt* pFmt, SvTreeListEntry* pE
    }
}

sal_uInt16 SwEditRegionDlg::FindArrPos(const SwSectionFmt* pFmt )
size_t SwEditRegionDlg::FindArrPos(const SwSectionFmt* pFmt )
{
    const sal_uInt16 nCount=rSh.GetSectionFmtCount();
    for (sal_uInt16 i=0;i<nCount;i++)
        if (pFmt==&rSh.GetSectionFmt(i))
    const size_t nCount=rSh.GetSectionFmtCount();
    for ( size_t i = 0; i < nCount; i++ )
        if ( pFmt == &rSh.GetSectionFmt(i) )
            return i;

    OSL_FAIL("SectionFormat not on the list" );
    return USHRT_MAX;
    return SIZE_MAX;
}

SwEditRegionDlg::~SwEditRegionDlg( )
@@ -784,8 +784,8 @@ IMPL_LINK_NOARG(SwEditRegionDlg, OkHdl)
        {
            pRepr->GetSectionData().SetPassword(uno::Sequence<sal_Int8 >());
        }
        sal_uInt16 nNewPos = rDocFmts.GetPos( pFmt );
        if( USHRT_MAX != nNewPos )
        size_t nNewPos = rDocFmts.GetPos(pFmt);
        if ( SIZE_MAX != nNewPos )
        {
            boost::scoped_ptr<SfxItemSet> pSet(pFmt->GetAttrSet().Clone( false ));
            if( pFmt->GetCol() != pRepr->GetCol() )
@@ -819,8 +819,8 @@ IMPL_LINK_NOARG(SwEditRegionDlg, OkHdl)
    for (SectReprArr::reverse_iterator aI = aSectReprArr.rbegin(), aEnd = aSectReprArr.rend(); aI != aEnd; ++aI)
    {
        SwSectionFmt* pFmt = aOrigArray[ aI->GetArrPos() ];
        const sal_uInt16 nNewPos = rDocFmts.GetPos( pFmt );
        if( USHRT_MAX != nNewPos )
        const size_t nNewPos = rDocFmts.GetPos( pFmt );
        if( SIZE_MAX != nNewPos )
            rSh.DelSectionFmt( nNewPos );
    }

diff --git a/sw/source/ui/frmdlg/column.cxx b/sw/source/ui/frmdlg/column.cxx
index c4b915a..ff77810 100644
--- a/sw/source/ui/frmdlg/column.cxx
+++ b/sw/source/ui/frmdlg/column.cxx
@@ -332,7 +332,7 @@ IMPL_LINK_NOARG(SwColumnDlg, OkHdl)
    {
        const SwSection* pCurrSection = rWrtShell.GetCurrSection();
        const SwSectionFmt* pFmt = pCurrSection->GetFmt();
        const sal_uInt16 nNewPos = rWrtShell.GetSectionFmtPos( *pFmt );
        const size_t nNewPos = rWrtShell.GetSectionFmtPos( *pFmt );
        SwSectionData aData(*pCurrSection);
        rWrtShell.UpdateSection( nNewPos, aData, pSectionSet );
    }
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index a9b95cf..d315405 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -782,8 +782,8 @@ static void lcl_CopyFollowPageDesc(
static void lcl_RemoveSectionLinks( SwWrtShell& rWorkShell )
{
    //reset all links of the sections of synchronized labels
    sal_uInt16 nSections = rWorkShell.GetSectionFmtCount();
    for( sal_uInt16 nSection = 0; nSection < nSections; ++nSection )
    size_t nSections = rWorkShell.GetSectionFmtCount();
    for (size_t nSection = 0; nSection < nSections; ++nSection)
    {
        SwSectionData aSectionData( *rWorkShell.GetSectionFmt( nSection ).GetSection() );
        if( aSectionData.GetType() == FILE_LINK_SECTION )
diff --git a/sw/source/uibase/inc/regionsw.hxx b/sw/source/uibase/inc/regionsw.hxx
index 633362531..91dcb6f 100644
--- a/sw/source/uibase/inc/regionsw.hxx
+++ b/sw/source/uibase/inc/regionsw.hxx
@@ -103,7 +103,7 @@ class SwEditRegionDlg : public SfxModalDialog
    Image  BuildBitmap(bool bProtect, bool bHidden);

    void    RecurseList( const SwSectionFmt* pFmt, SvTreeListEntry* pEntry);
    sal_uInt16  FindArrPos(const SwSectionFmt* pFmt);
    size_t  FindArrPos(const SwSectionFmt* pFmt);

    DECL_LINK( GetFirstEntryHdl, SvTreeListBox * );
    DECL_LINK( DeselectHdl, SvTreeListBox * );