[Libreoffice-commits] core.git: Branch 'feature/refactor-god-objects' - sw/inc sw/Library_sw.mk sw/source

Valentin Kettner vakevk+libreoffice at gmail.com
Wed Jun 25 04:58:10 PDT 2014


 sw/Library_sw.mk                            |    1 
 sw/inc/IDocumentListsAccess.hxx             |    1 
 sw/inc/doc.hxx                              |   26 --
 sw/inc/listfunc.hxx                         |   32 ---
 sw/source/core/attr/swatrset.cxx            |    9 -
 sw/source/core/doc/DocumentListsManager.cxx |  243 ++++++++++++++++++++++++++++
 sw/source/core/doc/doc.cxx                  |   12 +
 sw/source/core/doc/docnew.cxx               |   29 ---
 sw/source/core/doc/docnum.cxx               |  212 +-----------------------
 sw/source/core/doc/number.cxx               |    4 
 sw/source/core/inc/DocumentListsManager.hxx |   73 ++++++++
 sw/source/core/txtnode/ndtxt.cxx            |    7 
 sw/source/uibase/app/docst.cxx              |    5 
 sw/source/uibase/app/docstyle.cxx           |    4 
 14 files changed, 364 insertions(+), 294 deletions(-)

New commits:
commit 24696b0a602c42bfeefcafe38b3573e2e5fcefa9
Author: Valentin Kettner <vakevk+libreoffice at gmail.com>
Date:   Wed Jun 25 13:54:25 2014 +0200

    Refactored IDocumentListsAccess out of SwDoc.
    
    In the new class DocumentListsManager.
    The method listfunc::CreateUniqueListId was also moved there.
    Added a new method deleteListsByDefaultListStyle to the Interface,
    which is needed for SwDoc::DelNumRule.
    
    Change-Id: I75ea554a57d9402d2fcfeaedf9fbe50fbae2b020

diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index c28c6ed..86c7986 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -191,6 +191,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
     sw/source/core/doc/DocumentTimerManager \
     sw/source/core/doc/DocumentLinksAdministrationManager \
     sw/source/core/doc/DocumentListItemsManager \
+    sw/source/core/doc/DocumentListsManager \
     sw/source/core/doc/extinput \
     sw/source/core/doc/fmtcol \
     sw/source/core/doc/ftnidx \
diff --git a/sw/inc/IDocumentListsAccess.hxx b/sw/inc/IDocumentListsAccess.hxx
index 590ec8c..f53cfa8 100644
--- a/sw/inc/IDocumentListsAccess.hxx
+++ b/sw/inc/IDocumentListsAccess.hxx
@@ -37,6 +37,7 @@ class IDocumentListsAccess
         virtual SwList* createListForListStyle( const OUString& rListStyleName ) = 0;
         virtual SwList* getListForListStyle( const OUString& rListStyleName ) const = 0;
         virtual void deleteListForListStyle( const OUString& rListStyleName ) = 0;
+        virtual void deleteListsByDefaultListStyle( const OUString& rListStyleName ) = 0;
         // #i91400#
         virtual void trackChangeOfListStyleName( const OUString& rListStyleName,
                                                  const OUString& rNewListStyleName ) = 0;
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 6694ec1..a5e2c1b 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -31,10 +31,6 @@
 #include <IDocumentState.hxx>
 #include <IDocumentLayoutAccess.hxx>
 #include <IDocumentOutlineNodes.hxx>
-
-#include <IDocumentListsAccess.hxx>
-class SwList;
-
 #include <IDocumentExternalData.hxx>
 #include <com/sun/star/embed/XEmbeddedObject.hpp>
 #include <com/sun/star/embed/XStorage.hpp>
@@ -187,6 +183,7 @@ class SwPrintData;
 class SwRenderData;
 class SwPageFrm;
 class SwViewOption;
+class SwList;
 class IDocumentUndoRedo;
 class IDocumentSettingAccess;
 class IDocumentDeviceAccess;
@@ -195,6 +192,7 @@ class IDocumentChartDataProviderAccess;
 class IDocumentTimerAccess;
 class IDocumentLinksAdministration;
 class IDocumentListItems;
+class IDocumentListsAccess;
 class _SetGetExpFlds;
 
 namespace sw { namespace mark {
@@ -211,6 +209,7 @@ namespace sw {
     class DocumentTimerManager;
     class DocumentLinksAdministrationManager;
     class DocumentListItemsManager;
+    class DocumentListsManager;
 }
 
 namespace com { namespace sun { namespace star {
@@ -257,7 +256,6 @@ class SW_DLLPUBLIC SwDoc :
     public IDocumentState,
     public IDocumentLayoutAccess,
     public IDocumentOutlineNodes,
-    public IDocumentListsAccess,
     public IDocumentExternalData
 {
 
@@ -292,6 +290,7 @@ class SW_DLLPUBLIC SwDoc :
     const ::boost::scoped_ptr< ::sw::DocumentTimerManager > m_pDocumentTimerManager;
     const ::boost::scoped_ptr< ::sw::DocumentLinksAdministrationManager > m_pDocumentLinksAdministrationManager;
     const ::boost::scoped_ptr< ::sw::DocumentListItemsManager > m_pDocumentListItemsManager;
+    const ::boost::scoped_ptr< ::sw::DocumentListsManager > m_pDocumentListsManager;
 
     // Pointer
     SwFrmFmt        *mpDfltFrmFmt;       //< Default formats.
@@ -341,12 +340,6 @@ class SW_DLLPUBLIC SwDoc :
     // Hash map to find numrules by name
     mutable boost::unordered_map<OUString, SwNumRule *, OUStringHash> maNumRuleMap;
 
-    typedef boost::unordered_map<OUString, SwList*, OUStringHash> tHashMapForLists;
-    // container to hold the lists of the text document
-    tHashMapForLists maLists;
-    // relation between list style and its default list
-    tHashMapForLists maListStyleLists;
-
     SwRedlineTbl        *mpRedlineTbl;           //< List of all Ranged Redlines.
     SwExtraRedlineTbl   *mpExtraRedlineTbl;      //< List of all Extra Redlines.
     OUString            *mpAutoFmtRedlnComment;  //< Comment for Redlines inserted via AutoFormat.
@@ -780,15 +773,8 @@ public:
     virtual void getOutlineNodes( IDocumentOutlineNodes::tSortedOutlineNodeList& orOutlineNodeList ) const SAL_OVERRIDE;
 
     // IDocumentListsAccess
-    virtual SwList* createList( const OUString& rListId,
-                                const OUString& rDefaultListStyleName ) SAL_OVERRIDE;
-    virtual void deleteList( const OUString& rListId ) SAL_OVERRIDE;
-    virtual SwList* getListByName( const OUString& rListId ) const SAL_OVERRIDE;
-    virtual SwList* createListForListStyle( const OUString& rListStyleName ) SAL_OVERRIDE;
-    virtual SwList* getListForListStyle( const OUString& rListStyleName ) const SAL_OVERRIDE;
-    virtual void deleteListForListStyle( const OUString& rListStyleName ) SAL_OVERRIDE;
-    virtual void trackChangeOfListStyleName( const OUString& rListStyleName,
-                                             const OUString& rNewListStyleName ) SAL_OVERRIDE;
+    IDocumentListsAccess const & getIDocumentListsAccess() const;
+    IDocumentListsAccess & getIDocumentListsAccess();
 
     // IDocumentExternalData
     virtual void setExternalData(::sw::tExternalDataType eType,
diff --git a/sw/inc/listfunc.hxx b/sw/inc/listfunc.hxx
deleted file mode 100644
index 4057e193..0000000
--- a/sw/inc/listfunc.hxx
+++ /dev/null
@@ -1,32 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef INCLUDED_SW_INC_LISTFUNC_HXX
-#define INCLUDED_SW_INC_LISTFUNC_HXX
-
-class SwDoc;
-
-namespace listfunc
-{
-    const OUString CreateUniqueListId( const SwDoc& rDoc );
-}
-
-#endif // INCLUDED_SW_INC_LISTFUNC_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/attr/swatrset.cxx b/sw/source/core/attr/swatrset.cxx
index 073abb7..89586a3 100644
--- a/sw/source/core/attr/swatrset.cxx
+++ b/sw/source/core/attr/swatrset.cxx
@@ -21,6 +21,7 @@
 #include <charfmt.hxx>
 #include <cmdid.h>
 #include <doc.hxx>
+#include <IDocumentListsAccess.hxx>
 #include <editeng/colritem.hxx>
 #include <editeng/brushitem.hxx>
 #include <editeng/lineitem.hxx>
@@ -339,9 +340,9 @@ void SwAttrSet::CopyToModify( SwModify& rMod ) const
                 const OUString& sListId =
                         dynamic_cast<const SfxStringItem*>(pItem)->GetValue();
                 if ( !sListId.isEmpty() &&
-                     !pDstDoc->getListByName( sListId ) )
+                     !pDstDoc->getIDocumentListsAccess().getListByName( sListId ) )
                 {
-                    const SwList* pList = pSrcDoc->getListByName( sListId );
+                    const SwList* pList = pSrcDoc->getIDocumentListsAccess().getListByName( sListId );
                     // copy list style, if needed
                     const OUString sDefaultListStyleName =
                                             pList->GetDefaultListStyleName();
@@ -371,10 +372,10 @@ void SwAttrSet::CopyToModify( SwModify& rMod ) const
                     // check again, if list exist, because <SwDoc::MakeNumRule(..)>
                     // could have also created it.
                     if ( pNewListIdItem == 0 &&
-                         !pDstDoc->getListByName( sListId ) )
+                         !pDstDoc->getIDocumentListsAccess().getListByName( sListId ) )
                     {
                         // copy list
-                        pDstDoc->createList( sListId, sDefaultListStyleName );
+                        pDstDoc->getIDocumentListsAccess().createList( sListId, sDefaultListStyleName );
                     }
                 }
             }
diff --git a/sw/source/core/doc/DocumentListsManager.cxx b/sw/source/core/doc/DocumentListsManager.cxx
new file mode 100644
index 0000000..1e0a02f
--- /dev/null
+++ b/sw/source/core/doc/DocumentListsManager.cxx
@@ -0,0 +1,243 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#include <DocumentListsManager.hxx>
+#include <doc.hxx>
+#include <list.hxx>
+#include <numrule.hxx>
+#include <rtl/random.h>
+#include <vector>
+
+
+namespace sw
+{
+
+DocumentListsManager::DocumentListsManager( SwDoc& i_rSwdoc ) : m_rSwdoc( i_rSwdoc ), maLists(), maListStyleLists()
+{
+}
+
+SwList* DocumentListsManager::createList( const OUString& rListId,
+                           const OUString& sDefaultListStyleName )
+{
+    OUString sListId = rListId;
+    if ( sListId.isEmpty() )
+    {
+        sListId = CreateUniqueListId();
+    }
+
+    if ( getListByName( sListId ) )
+    {
+        OSL_FAIL( "<DocumentListsManager::createList(..)> - provided list id already used. Serious defect -> please inform OD." );
+        return 0;
+    }
+
+    SwNumRule* pDefaultNumRuleForNewList = m_rSwdoc.FindNumRulePtr( sDefaultListStyleName );
+    if ( !pDefaultNumRuleForNewList )
+    {
+        OSL_FAIL( "<DocumentListsManager::createList(..)> - for provided default list style name no list style is found. Serious defect -> please inform OD." );
+        return 0;
+    }
+
+    SwList* pNewList = new SwList( sListId, *pDefaultNumRuleForNewList, m_rSwdoc.GetNodes() );
+    maLists[sListId] = pNewList;
+
+    return pNewList;
+}
+
+void DocumentListsManager::deleteList( const OUString& sListId )
+{
+    SwList* pList = getListByName( sListId );
+    if ( pList )
+    {
+        maLists.erase( sListId );
+        delete pList;
+    }
+}
+
+SwList* DocumentListsManager::getListByName( const OUString& sListId ) const
+{
+    SwList* pList = 0;
+
+    boost::unordered_map< OUString, SwList*, OUStringHash >::const_iterator
+                                            aListIter = maLists.find( sListId );
+    if ( aListIter != maLists.end() )
+    {
+        pList = (*aListIter).second;
+    }
+
+    return pList;
+}
+
+SwList* DocumentListsManager::createListForListStyle( const OUString& sListStyleName )
+{
+    if ( sListStyleName.isEmpty() )
+    {
+        OSL_FAIL( "<DocumentListsManager::createListForListStyle(..)> - no list style name provided. Serious defect -> please inform OD." );
+        return 0;
+    }
+
+    if ( getListForListStyle( sListStyleName ) )
+    {
+        OSL_FAIL( "<DocumentListsManager::createListForListStyle(..)> - a list for the provided list style name already exists. Serious defect -> please inform OD." );
+        return 0;
+    }
+
+    SwNumRule* pNumRule = m_rSwdoc.FindNumRulePtr( sListStyleName );
+    if ( !pNumRule )
+    {
+        OSL_FAIL( "<DocumentListsManager::createListForListStyle(..)> - for provided list style name no list style is found. Serious defect -> please inform OD." );
+        return 0;
+    }
+
+    OUString sListId( pNumRule->GetDefaultListId() ); // can be empty String
+    if ( getListByName( sListId ) )
+    {
+        sListId = OUString();
+    }
+    SwList* pNewList = createList( sListId, sListStyleName );
+    maListStyleLists[sListStyleName] = pNewList;
+    pNumRule->SetDefaultListId( pNewList->GetListId() );
+
+    return pNewList;
+}
+
+SwList* DocumentListsManager::getListForListStyle( const OUString& sListStyleName ) const
+{
+    SwList* pList = 0;
+
+    boost::unordered_map< OUString, SwList*, OUStringHash >::const_iterator
+                            aListIter = maListStyleLists.find( sListStyleName );
+    if ( aListIter != maListStyleLists.end() )
+    {
+        pList = (*aListIter).second;
+    }
+
+    return pList;
+}
+
+void DocumentListsManager::deleteListForListStyle( const OUString& sListStyleName )
+{
+    OUString sListId;
+    {
+        SwList* pList = getListForListStyle( sListStyleName );
+        OSL_ENSURE( pList,
+                "<DocumentListsManager::deleteListForListStyle(..)> - misusage of method: no list found for given list style name" );
+        if ( pList )
+        {
+            sListId = pList->GetListId();
+        }
+    }
+    if ( !sListId.isEmpty() )
+    {
+        maListStyleLists.erase( sListStyleName );
+        deleteList( sListId );
+    }
+}
+
+void DocumentListsManager::deleteListsByDefaultListStyle( const OUString& rListStyleName )
+{
+    std::vector< SwList* > aListsForDeletion;
+    tHashMapForLists::iterator aListIter = maLists.begin();
+    while ( aListIter != maLists.end() )
+    {
+        SwList* pList = (*aListIter).second;
+        if ( pList->GetDefaultListStyleName() == rListStyleName )
+        {
+            aListsForDeletion.push_back( pList );
+        }
+        ++aListIter;
+    }
+    while ( !aListsForDeletion.empty() )
+    {
+        SwList* pList = aListsForDeletion.back();
+        aListsForDeletion.pop_back();
+        deleteList( pList->GetListId() );
+    }
+}
+
+void DocumentListsManager::trackChangeOfListStyleName( const OUString& sListStyleName,
+                                        const OUString& sNewListStyleName )
+{
+    SwList* pList = getListForListStyle( sListStyleName );
+    OSL_ENSURE( pList,
+            "<DocumentListsManager::changeOfListStyleName(..)> - misusage of method: no list found for given list style name" );
+
+    if ( pList != 0 )
+    {
+        maListStyleLists.erase( sListStyleName );
+        maListStyleLists[sNewListStyleName] = pList;
+    }
+}
+
+
+
+
+DocumentListsManager::~DocumentListsManager()
+{
+    for ( boost::unordered_map< OUString, SwList*, OUStringHash >::iterator
+                                           aListIter = maLists.begin();
+        aListIter != maLists.end();
+        ++aListIter )
+    {
+         delete (*aListIter).second;
+    }
+    maLists.clear();
+
+    maListStyleLists.clear();
+}
+
+
+const OUString DocumentListsManager::MakeListIdUnique( const OUString& aSuggestedUniqueListId )
+{
+    long nHitCount = 0;
+    OUString aTmpStr = aSuggestedUniqueListId;
+    while ( getListByName( aTmpStr ) )
+    {
+        ++nHitCount;
+        aTmpStr = aSuggestedUniqueListId;
+        aTmpStr += OUString::number( nHitCount );
+    }
+
+    return aTmpStr;
+}
+
+const OUString DocumentListsManager::CreateUniqueListId()
+{
+    static bool bHack = (getenv("LIBO_ONEWAY_STABLE_ODF_EXPORT") != NULL);
+    if (bHack)
+    {
+        static sal_Int64 nIdCounter = SAL_CONST_INT64(7000000000);
+        return MakeListIdUnique( OUString( "list" + OUString::number(nIdCounter++) ) );
+    }
+    else
+    {
+        // #i92478#
+        OUString aNewListId( "list" );
+        // #o12311627#
+        static rtlRandomPool s_RandomPool( rtl_random_createPool() );
+        sal_Int64 n;
+        rtl_random_getBytes( s_RandomPool, &n, sizeof(n) );
+        aNewListId += OUString::number( (n < 0 ? -n : n) );
+
+        return MakeListIdUnique( aNewListId );
+    }
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 5fa2316..00cb59d 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -25,6 +25,7 @@
 #include <DocumentChartDataProviderManager.hxx>
 #include <DocumentLinksAdministrationManager.hxx>
 #include <DocumentListItemsManager.hxx>
+#include <DocumentListsManager.hxx>
 #include <UndoManager.hxx>
 #include <hintids.hxx>
 
@@ -319,6 +320,17 @@ IDocumentListItems & SwDoc::getIDocumentListItems()
     return *m_pDocumentListItemsManager;
 }
 
+//IDocumentListsAccess
+IDocumentListsAccess const & SwDoc::getIDocumentListsAccess() const
+{
+    return *m_pDocumentListsManager;
+}
+
+IDocumentListsAccess & SwDoc::getIDocumentListsAccess()
+{
+    return *m_pDocumentListsManager;
+}
+
 /* Implementations the next Interface here */
 
 /*
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 5ee5174..322c7e1 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -94,6 +94,7 @@
 #include <DocumentTimerManager.hxx>
 #include <DocumentLinksAdministrationManager.hxx>
 #include <DocumentListItemsManager.hxx>
+#include <DocumentListsManager.hxx>
 #include <unochart.hxx>
 #include <fldbas.hxx>
 
@@ -102,7 +103,6 @@
 #include <pausethreadstarting.hxx>
 #include <numrule.hxx>
 #include <list.hxx>
-#include <listfunc.hxx>
 
 #include <sfx2/Metadatable.hxx>
 #include <fmtmeta.hxx>
@@ -201,6 +201,7 @@ SwDoc::SwDoc()
     m_pDocumentTimerManager( new ::sw::DocumentTimerManager( *this ) ),
     m_pDocumentLinksAdministrationManager( new ::sw::DocumentLinksAdministrationManager( *this ) ),
     m_pDocumentListItemsManager( new ::sw::DocumentListItemsManager() ),
+    m_pDocumentListsManager( new ::sw::DocumentListsManager( *this ) ),
     mpDfltFrmFmt( new SwFrmFmt( GetAttrPool(), sFrmFmtStr, 0 ) ),
     mpEmptyPageFmt( new SwFrmFmt( GetAttrPool(), sEmptyPageStr, mpDfltFrmFmt ) ),
     mpColumnContFmt( new SwFrmFmt( GetAttrPool(), sColumnCntStr, mpDfltFrmFmt ) ),
@@ -231,8 +232,6 @@ SwDoc::SwDoc()
     mpURLStateChgd( 0 ),
     mpNumberFormatter( 0 ),
     mpNumRuleTbl( new SwNumRuleTbl ),
-    maLists(),
-    maListStyleLists(),
     mpRedlineTbl( new SwRedlineTbl ),
     mpExtraRedlineTbl ( new SwExtraRedlineTbl ),
     mpAutoFmtRedlnComment( 0 ),
@@ -598,18 +597,6 @@ SwDoc::~SwDoc()
     delete mpDfltGrfFmtColl;
     delete mpNumRuleTbl;
 
-    {
-        for ( boost::unordered_map< OUString, SwList*, OUStringHash >::iterator
-                                                    aListIter = maLists.begin();
-              aListIter != maLists.end();
-              ++aListIter )
-        {
-            delete (*aListIter).second;
-        }
-        maLists.clear();
-    }
-    maListStyleLists.clear();
-
     disposeXForms(); // #i113606#, dispose the XForms objects
 
     delete mpNumberFormatter;
@@ -726,18 +713,6 @@ void SwDoc::ClearDoc()
     BOOST_FOREACH( SwNumRule* pNumRule, *mpNumRuleTbl )
         delete pNumRule;
     mpNumRuleTbl->clear();
-    // #i114725#,#i115828#
-    {
-        for ( boost::unordered_map< OUString, SwList*, OUStringHash >::iterator
-                                                    aListIter = maLists.begin();
-              aListIter != maLists.end();
-              ++aListIter )
-        {
-            delete (*aListIter).second;
-        }
-        maLists.clear();
-    }
-    maListStyleLists.clear();
 
     // creation of new outline numbering rule
     mpOutlineRule = new SwNumRule( SwNumRule::GetOutlineRuleName(),
diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx
index 35944bd..e582dae 100644
--- a/sw/source/core/doc/docnum.cxx
+++ b/sw/source/core/doc/docnum.cxx
@@ -25,6 +25,7 @@
 #include <ftnidx.hxx>
 #include <doc.hxx>
 #include <IDocumentUndoRedo.hxx>
+#include <IDocumentListsAccess.hxx>
 #include <pam.hxx>
 #include <ndtxt.hxx>
 #include <doctxm.hxx>
@@ -48,7 +49,6 @@
 #include <SwStyleNameMapper.hxx>
 #include <SwNodeNum.hxx>
 #include <list.hxx>
-#include <listfunc.hxx>
 #include <switerator.hxx>
 #include <comphelper/string.hxx>
 
@@ -105,7 +105,7 @@ void SwDoc::SetOutlineNumRule( const SwNumRule& rRule )
     }
 
     mpOutlineRule->SetRuleType( OUTLINE_RULE );
-    mpOutlineRule->SetName(SwNumRule::GetOutlineRuleName(), *this);
+    mpOutlineRule->SetName(SwNumRule::GetOutlineRuleName(), getIDocumentListsAccess());
 
     // assure that the outline numbering rule is an automatic rule
     mpOutlineRule->SetAutoRule( true );
@@ -874,7 +874,7 @@ void SwDoc::SetNumRule( const SwPaM& rPam,
             else
             {
                 // create new list and apply its list id
-                const SwList* pNewList = createList( OUString(), pNewOrChangedNumRule->GetName() );
+                const SwList* pNewList = getIDocumentListsAccess().createList( OUString(), pNewOrChangedNumRule->GetName() );
                 OSL_ENSURE( pNewList,
                         "<SwDoc::SetNumRule(..)> - could not create new list. Serious defect -> please inform OD." );
                 sListId = pNewList->GetListId();
@@ -1027,28 +1027,8 @@ bool SwDoc::DelNumRule( const OUString& rName, bool bBroadcast )
             BroadcastStyleOperation(rName, SFX_STYLE_FAMILY_PSEUDO,
                                     SFX_STYLESHEET_ERASED);
 
-        deleteListForListStyle( rName );
-        {
-            // delete further list, which have the deleted list style as default list style
-            std::vector< SwList* > aListsForDeletion;
-            tHashMapForLists::iterator aListIter = maLists.begin();
-            while ( aListIter != maLists.end() )
-            {
-                SwList* pList = (*aListIter).second;
-                if ( pList->GetDefaultListStyleName() == rName )
-                {
-                    aListsForDeletion.push_back( pList );
-                }
-
-                ++aListIter;
-            }
-            while ( !aListsForDeletion.empty() )
-            {
-                SwList* pList = aListsForDeletion.back();
-                aListsForDeletion.pop_back();
-                deleteList( pList->GetListId() );
-            }
-        }
+        getIDocumentListsAccess().deleteListForListStyle( rName );
+        getIDocumentListsAccess().deleteListsByDefaultListStyle( rName );
         // #i34097# DeleteAndDestroy deletes rName if
         // rName is directly taken from the numrule.
         const OUString aTmpName( rName );
@@ -1100,7 +1080,7 @@ bool SwDoc::RenameNumRule(const OUString & rOldName, const OUString & rNewName,
         SwNumRule::tTxtNodeList aTxtNodeList;
         pNumRule->GetTxtNodeList( aTxtNodeList );
 
-        pNumRule->SetName( rNewName, *this );
+        pNumRule->SetName( rNewName, getIDocumentListsAccess() );
 
         SwNumRuleItem aItem(rNewName);
 
@@ -1251,7 +1231,7 @@ void SwDoc::MakeUniqueNumRules(const SwPaM & rPaM)
                     if ( aListStyleData.pReplaceNumRule == 0 )
                     {
                         aListStyleData.pReplaceNumRule = new SwNumRule(*pRule);
-                        aListStyleData.pReplaceNumRule->SetName( GetUniqueNumRuleName(), *this );
+                        aListStyleData.pReplaceNumRule->SetName( GetUniqueNumRuleName(), getIDocumentListsAccess() );
                         aListStyleData.bCreateNewList = true;
                     }
 
@@ -2152,7 +2132,7 @@ void SwDoc::AddNumRule(SwNumRule * pRule)
     maNumRuleMap[pRule->GetName()] = pRule;
     pRule->SetNumRuleMap(&maNumRuleMap);
 
-    createListForListStyle( pRule->GetName() );
+    getIDocumentListsAccess().createListForListStyle( pRule->GetName() );
 }
 
 sal_uInt16 SwDoc::MakeNumRule( const OUString &rName,
@@ -2165,7 +2145,7 @@ sal_uInt16 SwDoc::MakeNumRule( const OUString &rName,
     {
         pNew = new SwNumRule( *pCpy );
 
-        pNew->SetName( GetUniqueNumRuleName( &rName ), *this );
+        pNew->SetName( GetUniqueNumRuleName( &rName ), getIDocumentListsAccess() );
 
         if( pNew->GetName() != rName )
         {
@@ -2296,7 +2276,7 @@ void SwDoc::MarkListLevel( const OUString& sListId,
                            const int nListLevel,
                            const bool bValue )
 {
-    SwList* pList = getListByName( sListId );
+    SwList* pList = getIDocumentListsAccess().getListByName( sListId );
 
     if ( pList )
     {
@@ -2365,177 +2345,5 @@ void SwDoc::getOutlineNodes( IDocumentOutlineNodes::tSortedOutlineNodeList& orOu
     }
 }
 
-// implementation of interface IDocumentListsAccess
-SwList* SwDoc::createList( const OUString& rListId,
-                           const OUString& sDefaultListStyleName )
-{
-    OUString sListId = rListId;
-    if ( sListId.isEmpty() )
-    {
-        sListId = listfunc::CreateUniqueListId( *this );
-    }
-
-    if ( getListByName( sListId ) )
-    {
-        OSL_FAIL( "<SwDoc::createList(..)> - provided list id already used. Serious defect -> please inform OD." );
-        return 0;
-    }
-
-    SwNumRule* pDefaultNumRuleForNewList = FindNumRulePtr( sDefaultListStyleName );
-    if ( !pDefaultNumRuleForNewList )
-    {
-        OSL_FAIL( "<SwDoc::createList(..)> - for provided default list style name no list style is found. Serious defect -> please inform OD." );
-        return 0;
-    }
-
-    SwList* pNewList = new SwList( sListId, *pDefaultNumRuleForNewList, GetNodes() );
-    maLists[sListId] = pNewList;
-
-    return pNewList;
-}
-
-void SwDoc::deleteList( const OUString& sListId )
-{
-    SwList* pList = getListByName( sListId );
-    if ( pList )
-    {
-        maLists.erase( sListId );
-        delete pList;
-    }
-}
-
-SwList* SwDoc::getListByName( const OUString& sListId ) const
-{
-    SwList* pList = 0;
-
-    boost::unordered_map< OUString, SwList*, OUStringHash >::const_iterator
-                                            aListIter = maLists.find( sListId );
-    if ( aListIter != maLists.end() )
-    {
-        pList = (*aListIter).second;
-    }
-
-    return pList;
-}
-
-SwList* SwDoc::createListForListStyle( const OUString& sListStyleName )
-{
-    if ( sListStyleName.isEmpty() )
-    {
-        OSL_FAIL( "<SwDoc::createListForListStyle(..)> - no list style name provided. Serious defect -> please inform OD." );
-        return 0;
-    }
-
-    if ( getListForListStyle( sListStyleName ) )
-    {
-        OSL_FAIL( "<SwDoc::createListForListStyle(..)> - a list for the provided list style name already exists. Serious defect -> please inform OD." );
-        return 0;
-    }
-
-    SwNumRule* pNumRule = FindNumRulePtr( sListStyleName );
-    if ( !pNumRule )
-    {
-        OSL_FAIL( "<SwDoc::createListForListStyle(..)> - for provided list style name no list style is found. Serious defect -> please inform OD." );
-        return 0;
-    }
-
-    OUString sListId( pNumRule->GetDefaultListId() ); // can be empty String
-    if ( getListByName( sListId ) )
-    {
-        sListId = OUString();
-    }
-    SwList* pNewList = createList( sListId, sListStyleName );
-    maListStyleLists[sListStyleName] = pNewList;
-    pNumRule->SetDefaultListId( pNewList->GetListId() );
-
-    return pNewList;
-}
-
-SwList* SwDoc::getListForListStyle( const OUString& sListStyleName ) const
-{
-    SwList* pList = 0;
-
-    boost::unordered_map< OUString, SwList*, OUStringHash >::const_iterator
-                            aListIter = maListStyleLists.find( sListStyleName );
-    if ( aListIter != maListStyleLists.end() )
-    {
-        pList = (*aListIter).second;
-    }
-
-    return pList;
-}
-
-void SwDoc::deleteListForListStyle( const OUString& sListStyleName )
-{
-    OUString sListId;
-    {
-        SwList* pList = getListForListStyle( sListStyleName );
-        OSL_ENSURE( pList,
-                "<SwDoc::deleteListForListStyle(..)> - misusage of method: no list found for given list style name" );
-        if ( pList )
-        {
-            sListId = pList->GetListId();
-        }
-    }
-    if ( !sListId.isEmpty() )
-    {
-        maListStyleLists.erase( sListStyleName );
-        deleteList( sListId );
-    }
-}
-
-void SwDoc::trackChangeOfListStyleName( const OUString& sListStyleName,
-                                        const OUString& sNewListStyleName )
-{
-    SwList* pList = getListForListStyle( sListStyleName );
-    OSL_ENSURE( pList,
-            "<SwDoc::changeOfListStyleName(..)> - misusage of method: no list found for given list style name" );
-
-    if ( pList != 0 )
-    {
-        maListStyleLists.erase( sListStyleName );
-        maListStyleLists[sNewListStyleName] = pList;
-    }
-}
-
-namespace listfunc
-{
-    const OUString MakeListIdUnique( const SwDoc& rDoc,
-                                   const OUString& aSuggestedUniqueListId )
-    {
-        long nHitCount = 0;
-        OUString aTmpStr = aSuggestedUniqueListId;
-        while ( rDoc.getListByName( aTmpStr ) )
-        {
-            ++nHitCount;
-            aTmpStr = aSuggestedUniqueListId;
-            aTmpStr += OUString::number( nHitCount );
-        }
-
-        return aTmpStr;
-    }
-    const OUString CreateUniqueListId( const SwDoc& rDoc )
-    {
-        static bool bHack = (getenv("LIBO_ONEWAY_STABLE_ODF_EXPORT") != NULL);
-
-        if (bHack)
-        {
-            static sal_Int64 nIdCounter = SAL_CONST_INT64(7000000000);
-            return MakeListIdUnique( rDoc, OUString( "list" + OUString::number(nIdCounter++) ) );
-        }
-        else
-        {
-            // #i92478#
-            OUString aNewListId( "list" );
-            // #o12311627#
-            static rtlRandomPool s_RandomPool( rtl_random_createPool() );
-            sal_Int64 n;
-            rtl_random_getBytes( s_RandomPool, &n, sizeof(n) );
-            aNewListId += OUString::number( (n < 0 ? -n : n) );
-
-            return MakeListIdUnique( rDoc, aNewListId );
-        }
-    }
-}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx
index 66c156f..3645ca4 100644
--- a/sw/source/core/doc/number.cxx
+++ b/sw/source/core/doc/number.cxx
@@ -881,7 +881,7 @@ void SwNumRule::SetInvalidRule(bool bFlag)
         {
             const SwTxtNode* pTxtNode = *aIter;
             // #i111681# - applying patch from cmc
-            SwList* pList = pTxtNode->GetDoc()->getListByName( pTxtNode->GetListId() );
+            SwList* pList = pTxtNode->GetDoc()->getIDocumentListsAccess().getListByName( pTxtNode->GetListId() );
             OSL_ENSURE( pList, "<SwNumRule::SetInvalidRule(..)> - list at which the text node is registered at does not exist. This is a serious issue --> please inform OD.");
             if ( pList )
             {
@@ -995,7 +995,7 @@ void SwNumRule::Validate()
     for ( aIter = maTxtNodeList.begin(); aIter != maTxtNodeList.end(); ++aIter )
     {
         const SwTxtNode* pTxtNode = *aIter;
-        aLists.insert( pTxtNode->GetDoc()->getListByName( pTxtNode->GetListId() ) );
+        aLists.insert( pTxtNode->GetDoc()->getIDocumentListsAccess().getListByName( pTxtNode->GetListId() ) );
     }
     std::for_each( aLists.begin(), aLists.end(),
                    std::mem_fun( &SwList::ValidateListTree ) );
diff --git a/sw/source/core/inc/DocumentListsManager.hxx b/sw/source/core/inc/DocumentListsManager.hxx
new file mode 100644
index 0000000..6d01d04
--- /dev/null
+++ b/sw/source/core/inc/DocumentListsManager.hxx
@@ -0,0 +1,73 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_SW_SOURCE_CORE_INC_DOCUMENTLISTSMANAGER_HXX
+#define INCLUDED_SW_SOURCE_CORE_INC_DOCUMENTLISTSMANAGER_HXX
+
+#include <IDocumentListsAccess.hxx>
+#include <boost/utility.hpp>
+#include <boost/unordered_map.hpp>
+
+class SwList;
+class SwDoc;
+
+namespace sw
+{
+
+
+class DocumentListsManager : public IDocumentListsAccess,
+                             public ::boost::noncopyable
+{
+    public:
+
+        DocumentListsManager( SwDoc& i_rSwdoc );
+
+        SwList* createList( const OUString& rListId,
+                                    const OUString& rDefaultListStyleName ) SAL_OVERRIDE;
+        void deleteList( const OUString& rListId ) SAL_OVERRIDE;
+        SwList* getListByName( const OUString& rListId ) const SAL_OVERRIDE;
+
+        SwList* createListForListStyle( const OUString& rListStyleName ) SAL_OVERRIDE;
+        SwList* getListForListStyle( const OUString& rListStyleName ) const SAL_OVERRIDE;
+        void deleteListForListStyle( const OUString& rListStyleName ) SAL_OVERRIDE;
+        void deleteListsByDefaultListStyle( const OUString& rListStyleName ) SAL_OVERRIDE;
+        // #i91400#
+        void trackChangeOfListStyleName( const OUString& rListStyleName,
+                                                 const OUString& rNewListStyleName ) SAL_OVERRIDE;
+        ~DocumentListsManager();
+
+    private:
+
+        SwDoc& m_rSwdoc;
+
+        typedef boost::unordered_map<OUString, SwList*, OUStringHash> tHashMapForLists;
+        // container to hold the lists of the text document
+        tHashMapForLists maLists;
+        // relation between list style and its default list
+        tHashMapForLists maListStyleLists;
+
+        const OUString CreateUniqueListId();
+        const OUString MakeListIdUnique( const OUString& aSuggestedUniqueListId );
+};
+
+}
+
+#endif // INCLUDED_SW_SOURCE_CORE_INC_DOCUMENTLISTSMANAGER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 235e516..bf3d0fc 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -52,6 +52,7 @@
 #include <doc.hxx>
 #include <IDocumentUndoRedo.hxx>
 #include <IDocumentSettingAccess.hxx>
+#include <IDocumentListsAccess.hxx>
 #include <docary.hxx>
 #include <pam.hxx>
 #include <fldbas.hxx>
@@ -2506,7 +2507,7 @@ bool SwTxtNode::HasMarkedLabel() const
     if ( IsInList() )
     {
         bResult =
-            GetDoc()->getListByName( GetListId() )->IsListLevelMarked( GetActualListLevel() );
+            GetDoc()->getIDocumentListsAccess().getListByName( GetListId() )->IsListLevelMarked( GetActualListLevel() );
     }
 
     return bResult;
@@ -3969,14 +3970,14 @@ void SwTxtNode::AddToList()
     const OUString sListId = GetListId();
     if (!sListId.isEmpty())
     {
-        SwList* pList = GetDoc()->getListByName( sListId );
+        SwList* pList = GetDoc()->getIDocumentListsAccess().getListByName( sListId );
         if ( pList == 0 )
         {
             // Create corresponding list.
             SwNumRule* pNumRule = GetNumRule();
             if ( pNumRule )
             {
-                pList = GetDoc()->createList( sListId, GetNumRule()->GetName() );
+                pList = GetDoc()->getIDocumentListsAccess().createList( sListId, GetNumRule()->GetName() );
             }
         }
         OSL_ENSURE( pList != 0,
diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx
index ec4332c..81654e3 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -59,6 +59,7 @@
 #include <IDocumentUndoRedo.hxx>
 #include <IDocumentSettingAccess.hxx>
 #include <IDocumentDeviceAccess.hxx>
+#include <IDocumentListsAccess.hxx>
 #include "swstyle.h"
 #include "frmfmt.hxx"
 #include "charfmt.hxx"
@@ -1063,7 +1064,7 @@ sal_uInt16 SwDocShell::UpdateStyle(const OUString &rName, sal_uInt16 nFamily, Sw
                 SwNumRule aRule( *pCurRule );
                 // #i91400#
                 aRule.SetName( pStyle->GetNumRule()->GetName(),
-                               *(pCurrWrtShell->GetDoc()) );
+                               pCurrWrtShell->GetDoc()->getIDocumentListsAccess() );
                 pCurrWrtShell->ChgNumRuleFmts( aRule );
             }
         }
@@ -1206,7 +1207,7 @@ sal_uInt16 SwDocShell::MakeByExample( const OUString &rName, sal_uInt16 nFamily,
                 OUString sOrigRule( aRule.GetName() );
                 // #i91400#
                 aRule.SetName( pStyle->GetNumRule()->GetName(),
-                               *(pCurrWrtShell->GetDoc()) );
+                               pCurrWrtShell->GetDoc()->getIDocumentListsAccess() );
                 pCurrWrtShell->ChgNumRuleFmts( aRule );
 
                 pCurrWrtShell->ReplaceNumRule( sOrigRule, aRule.GetName() );
diff --git a/sw/source/uibase/app/docstyle.cxx b/sw/source/uibase/app/docstyle.cxx
index 8cb9c2a..3fa19c6 100644
--- a/sw/source/uibase/app/docstyle.cxx
+++ b/sw/source/uibase/app/docstyle.cxx
@@ -967,7 +967,7 @@ bool  SwDocStyleSheet::SetName(const OUString& rStr, bool bReindexNow)
                 else
                 {
                     // #i91400#
-                    ((SwNumRule*)pNumRule)->SetName( rStr, rDoc );
+                    ((SwNumRule*)pNumRule)->SetName( rStr, rDoc.getIDocumentListsAccess() );
                     rDoc.SetModified();
 
                     bChg = true;
@@ -1871,7 +1871,7 @@ void SwDocStyleSheet::Create()
                 if( aName.isEmpty() )
                 {
                     // #i91400#
-                    pRule->SetName( aName, rDoc );
+                    pRule->SetName( aName, rDoc.getIDocumentListsAccess() );
                 }
                 pNumRule = pRule;
             }


More information about the Libreoffice-commits mailing list