[Libreoffice-commits] core.git: Branch 'feature/refactor-god-objects' - sw/inc sw/Library_sw.mk sw/source
Valentin Kettner
vakevk+libreoffice at gmail.com
Mon Jun 23 05:59:11 PDT 2014
sw/Library_sw.mk | 1
sw/inc/doc.hxx | 23 ----
sw/source/core/doc/DocumentListItemsManager.cxx | 121 ++++++++++++++++++++++++
sw/source/core/doc/doc.cxx | 12 ++
sw/source/core/doc/docnew.cxx | 7 -
sw/source/core/doc/docnum.cxx | 79 ---------------
sw/source/core/docnode/node.cxx | 2
sw/source/core/inc/DocumentListItemsManager.hxx | 69 +++++++++++++
sw/source/core/view/viewsh.cxx | 2
9 files changed, 212 insertions(+), 104 deletions(-)
New commits:
commit f8cfacc479decff61beb892df6714d77351a2fb0
Author: Valentin Kettner <vakevk+libreoffice at gmail.com>
Date: Mon Jun 23 14:56:59 2014 +0200
Refactored IDocumentListItems out of SwDoc.
Into the new class DocumentListItemsManager.
Change-Id: Ic86200280caa1b6e2c940bb12149235223ed0cd2
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 2980476..c28c6ed 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -190,6 +190,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
sw/source/core/doc/DocumentChartDataProviderManager \
sw/source/core/doc/DocumentTimerManager \
sw/source/core/doc/DocumentLinksAdministrationManager \
+ sw/source/core/doc/DocumentListItemsManager \
sw/source/core/doc/extinput \
sw/source/core/doc/fmtcol \
sw/source/core/doc/ftnidx \
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 69b2fd7..6694ec1 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -31,7 +31,6 @@
#include <IDocumentState.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <IDocumentOutlineNodes.hxx>
-#include <IDocumentListItems.hxx>
#include <IDocumentListsAccess.hxx>
class SwList;
@@ -195,6 +194,7 @@ class IDocumentDrawModelAccess;
class IDocumentChartDataProviderAccess;
class IDocumentTimerAccess;
class IDocumentLinksAdministration;
+class IDocumentListItems;
class _SetGetExpFlds;
namespace sw { namespace mark {
@@ -210,6 +210,7 @@ namespace sw {
class DocumentChartDataProviderManager;
class DocumentTimerManager;
class DocumentLinksAdministrationManager;
+ class DocumentListItemsManager;
}
namespace com { namespace sun { namespace star {
@@ -255,7 +256,6 @@ class SW_DLLPUBLIC SwDoc :
public IDocumentStatistics,
public IDocumentState,
public IDocumentLayoutAccess,
- public IDocumentListItems,
public IDocumentOutlineNodes,
public IDocumentListsAccess,
public IDocumentExternalData
@@ -291,6 +291,7 @@ class SW_DLLPUBLIC SwDoc :
::boost::scoped_ptr< ::sw::DocumentDeviceManager > m_pDeviceAccess;
const ::boost::scoped_ptr< ::sw::DocumentTimerManager > m_pDocumentTimerManager;
const ::boost::scoped_ptr< ::sw::DocumentLinksAdministrationManager > m_pDocumentLinksAdministrationManager;
+ const ::boost::scoped_ptr< ::sw::DocumentListItemsManager > m_pDocumentListItemsManager;
// Pointer
SwFrmFmt *mpDfltFrmFmt; //< Default formats.
@@ -368,17 +369,8 @@ class SW_DLLPUBLIC SwDoc :
rtl::Reference<SvxForbiddenCharactersTable> mxForbiddenCharsTable;
com::sun::star::uno::Reference< com::sun::star::script::vba::XVBAEventProcessor > mxVbaEvents;
com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> m_xTemplateToProjectCache;
-public:
- struct lessThanNodeNum
- {
- bool operator()( const SwNodeNum* pNodeNumOne,
- const SwNodeNum* pNodeNumTwo ) const;
- };
- typedef ::std::set< const SwNodeNum*, lessThanNodeNum > tImplSortedNodeNumList;
private:
- tImplSortedNodeNumList* mpListItemsList;
-
::std::auto_ptr< ::sfx2::IXmlIdRegistry > m_pXmlIdRegistry;
// other
@@ -774,13 +766,8 @@ public:
IDocumentChartDataProviderAccess & getIDocumentChartDataProviderAccess();
// IDocumentListItems
- virtual void addListItem( const SwNodeNum& rNodeNum ) SAL_OVERRIDE;
- virtual void removeListItem( const SwNodeNum& rNodeNum ) SAL_OVERRIDE;
- virtual OUString getListItemText( const SwNodeNum& rNodeNum,
- const bool bWithNumber = true,
- const bool bWithSpacesForLevel = false ) const SAL_OVERRIDE;
- virtual void getListItems( IDocumentListItems::tSortedNodeNumList& orNodeNumList ) const SAL_OVERRIDE;
- virtual void getNumItems( IDocumentListItems::tSortedNodeNumList& orNodeNumList ) const SAL_OVERRIDE;
+ IDocumentListItems const & getIDocumentListItems() const;
+ IDocumentListItems & getIDocumentListItems();
// IDocumentOutlineNodes
virtual sal_Int32 getOutlineNodesCount() const SAL_OVERRIDE;
diff --git a/sw/source/core/doc/DocumentListItemsManager.cxx b/sw/source/core/doc/DocumentListItemsManager.cxx
new file mode 100644
index 0000000..5844fd2
--- /dev/null
+++ b/sw/source/core/doc/DocumentListItemsManager.cxx
@@ -0,0 +1,121 @@
+/* -*- 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 <DocumentListItemsManager.hxx>
+#include <SwNodeNum.hxx>
+#include <ndtxt.hxx>
+
+
+namespace sw
+{
+
+DocumentListItemsManager::DocumentListItemsManager() : mpListItemsList( new tImplSortedNodeNumList() ) // #i83479#
+{
+}
+
+bool DocumentListItemsManager::lessThanNodeNum::operator()( const SwNodeNum* pNodeNumOne,
+ const SwNodeNum* pNodeNumTwo ) const
+{
+ return pNodeNumOne->LessThan( *pNodeNumTwo );
+}
+
+void DocumentListItemsManager::addListItem( const SwNodeNum& rNodeNum )
+{
+ if ( mpListItemsList == 0 )
+ {
+ return;
+ }
+
+ const bool bAlreadyInserted(
+ mpListItemsList->find( &rNodeNum ) != mpListItemsList->end() );
+ OSL_ENSURE( !bAlreadyInserted,
+ "<DocumentListItemsManager::addListItem(..)> - <SwNodeNum> instance already registered as numbered item!" );
+ if ( !bAlreadyInserted )
+ {
+ mpListItemsList->insert( &rNodeNum );
+ }
+}
+
+void DocumentListItemsManager::removeListItem( const SwNodeNum& rNodeNum )
+{
+ if ( mpListItemsList == 0 )
+ {
+ return;
+ }
+
+ const tImplSortedNodeNumList::size_type nDeleted = mpListItemsList->erase( &rNodeNum );
+ if ( nDeleted > 1 )
+ {
+ OSL_FAIL( "<DocumentListItemsManager::removeListItem(..)> - <SwNodeNum> was registered more than once as numbered item!" );
+ }
+}
+
+OUString DocumentListItemsManager::getListItemText( const SwNodeNum& rNodeNum,
+ const bool bWithNumber,
+ const bool bWithSpacesForLevel ) const
+{
+ return rNodeNum.GetTxtNode()
+ ? rNodeNum.GetTxtNode()->GetExpandTxt( 0, -1, bWithNumber,
+ bWithNumber, bWithSpacesForLevel )
+ : OUString();
+}
+
+void DocumentListItemsManager::getListItems( tSortedNodeNumList& orNodeNumList ) const
+{
+ orNodeNumList.clear();
+ orNodeNumList.reserve( mpListItemsList->size() );
+
+ tImplSortedNodeNumList::iterator aIter;
+ tImplSortedNodeNumList::iterator aEndIter = mpListItemsList->end();
+ for ( aIter = mpListItemsList->begin(); aIter != aEndIter; ++aIter )
+ {
+ orNodeNumList.push_back( (*aIter) );
+ }
+}
+
+void DocumentListItemsManager::getNumItems( tSortedNodeNumList& orNodeNumList ) const
+{
+ orNodeNumList.clear();
+ orNodeNumList.reserve( mpListItemsList->size() );
+
+ tImplSortedNodeNumList::iterator aIter;
+ tImplSortedNodeNumList::iterator aEndIter = mpListItemsList->end();
+ for ( aIter = mpListItemsList->begin(); aIter != aEndIter; ++aIter )
+ {
+ const SwNodeNum* pNodeNum = (*aIter);
+ if ( pNodeNum->IsCounted() &&
+ pNodeNum->GetTxtNode() && pNodeNum->GetTxtNode()->HasNumber() )
+ {
+ orNodeNumList.push_back( pNodeNum );
+ }
+ }
+}
+
+DocumentListItemsManager::~DocumentListItemsManager()
+{
+// #i83479#
+delete mpListItemsList;
+mpListItemsList = 0;
+}
+
+
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index c6aea1d..5fa2316 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -24,6 +24,7 @@
#include <DocumentDeviceManager.hxx>
#include <DocumentChartDataProviderManager.hxx>
#include <DocumentLinksAdministrationManager.hxx>
+#include <DocumentListItemsManager.hxx>
#include <UndoManager.hxx>
#include <hintids.hxx>
@@ -306,6 +307,17 @@ IDocumentLinksAdministration & SwDoc::getIDocumentLinksAdministration()
return *m_pDocumentLinksAdministrationManager;
}
+//IDocumentListItems
+IDocumentListItems const & SwDoc::getIDocumentListItems() const
+{
+ return *m_pDocumentListItemsManager;
+}
+
+//IDocumentListItems
+IDocumentListItems & SwDoc::getIDocumentListItems()
+{
+ return *m_pDocumentListItemsManager;
+}
/* Implementations the next Interface here */
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 50c6cf6..5ee5174 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -93,6 +93,7 @@
#include <DocumentChartDataProviderManager.hxx>
#include <DocumentTimerManager.hxx>
#include <DocumentLinksAdministrationManager.hxx>
+#include <DocumentListItemsManager.hxx>
#include <unochart.hxx>
#include <fldbas.hxx>
@@ -199,6 +200,7 @@ SwDoc::SwDoc()
m_pDeviceAccess( new ::sw::DocumentDeviceManager( *this ) ),
m_pDocumentTimerManager( new ::sw::DocumentTimerManager( *this ) ),
m_pDocumentLinksAdministrationManager( new ::sw::DocumentLinksAdministrationManager( *this ) ),
+ m_pDocumentListItemsManager( new ::sw::DocumentListItemsManager() ),
mpDfltFrmFmt( new SwFrmFmt( GetAttrPool(), sFrmFmtStr, 0 ) ),
mpEmptyPageFmt( new SwFrmFmt( GetAttrPool(), sEmptyPageStr, mpDfltFrmFmt ) ),
mpColumnContFmt( new SwFrmFmt( GetAttrPool(), sColumnCntStr, mpDfltFrmFmt ) ),
@@ -242,7 +244,6 @@ SwDoc::SwDoc()
mpLayoutCache( 0 ),
mpUnoCallBack(new SwModify(0)),
mpGrammarContact(createGrammarContact()),
- mpListItemsList( new tImplSortedNodeNumList() ), // #i83479#
m_pXmlIdRegistry(),
mnAutoFmtRedlnCommentNo( 0 ),
meRedlineMode((RedlineMode_t)(nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE)),
@@ -418,10 +419,6 @@ SwDoc::~SwDoc()
mpDocShell->SetUndoManager(0);
}
- // #i83479#
- delete mpListItemsList;
- mpListItemsList = 0;
-
delete mpGrammarContact;
mpGrammarContact = 0;
diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx
index bf7b4f2..35944bd 100644
--- a/sw/source/core/doc/docnum.cxx
+++ b/sw/source/core/doc/docnum.cxx
@@ -2325,85 +2325,6 @@ bool SwDoc::IsFirstOfNumRuleAtPos( const SwPosition & rPos )
return bResult;
}
-// implementation for interface <IDocumentListItems>
-bool SwDoc::lessThanNodeNum::operator()( const SwNodeNum* pNodeNumOne,
- const SwNodeNum* pNodeNumTwo ) const
-{
- return pNodeNumOne->LessThan( *pNodeNumTwo );
-}
-
-void SwDoc::addListItem( const SwNodeNum& rNodeNum )
-{
- if ( mpListItemsList == 0 )
- {
- return;
- }
-
- const bool bAlreadyInserted(
- mpListItemsList->find( &rNodeNum ) != mpListItemsList->end() );
- OSL_ENSURE( !bAlreadyInserted,
- "<SwDoc::InsertListItem(..)> - <SwNodeNum> instance already registered as numbered item!" );
- if ( !bAlreadyInserted )
- {
- mpListItemsList->insert( &rNodeNum );
- }
-}
-
-void SwDoc::removeListItem( const SwNodeNum& rNodeNum )
-{
- if ( mpListItemsList == 0 )
- {
- return;
- }
-
- const tImplSortedNodeNumList::size_type nDeleted = mpListItemsList->erase( &rNodeNum );
- if ( nDeleted > 1 )
- {
- OSL_FAIL( "<SwDoc::RemoveListItem(..)> - <SwNodeNum> was registered more than once as numbered item!" );
- }
-}
-
-OUString SwDoc::getListItemText( const SwNodeNum& rNodeNum,
- const bool bWithNumber,
- const bool bWithSpacesForLevel ) const
-{
- return rNodeNum.GetTxtNode()
- ? rNodeNum.GetTxtNode()->GetExpandTxt( 0, -1, bWithNumber,
- bWithNumber, bWithSpacesForLevel )
- : OUString();
-}
-
-void SwDoc::getListItems( tSortedNodeNumList& orNodeNumList ) const
-{
- orNodeNumList.clear();
- orNodeNumList.reserve( mpListItemsList->size() );
-
- tImplSortedNodeNumList::iterator aIter;
- tImplSortedNodeNumList::iterator aEndIter = mpListItemsList->end();
- for ( aIter = mpListItemsList->begin(); aIter != aEndIter; ++aIter )
- {
- orNodeNumList.push_back( (*aIter) );
- }
-}
-
-void SwDoc::getNumItems( tSortedNodeNumList& orNodeNumList ) const
-{
- orNodeNumList.clear();
- orNodeNumList.reserve( mpListItemsList->size() );
-
- tImplSortedNodeNumList::iterator aIter;
- tImplSortedNodeNumList::iterator aEndIter = mpListItemsList->end();
- for ( aIter = mpListItemsList->begin(); aIter != aEndIter; ++aIter )
- {
- const SwNodeNum* pNodeNum = (*aIter);
- if ( pNodeNum->IsCounted() &&
- pNodeNum->GetTxtNode() && pNodeNum->GetTxtNode()->HasNumber() )
- {
- orNodeNumList.push_back( pNodeNum );
- }
- }
-}
-
// implementation for interface <IDocumentOutlineNodes>
sal_Int32 SwDoc::getOutlineNodesCount() const
{
diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx
index 0af3c7c..0800d5e 100644
--- a/sw/source/core/docnode/node.cxx
+++ b/sw/source/core/docnode/node.cxx
@@ -1927,7 +1927,7 @@ IDocumentLinksAdministration* SwNode::getIDocumentLinksAdministration() { return
const IDocumentFieldsAccess* SwNode::getIDocumentFieldsAccess() const { return GetDoc(); }
IDocumentFieldsAccess* SwNode::getIDocumentFieldsAccess() { return GetDoc(); }
IDocumentContentOperations* SwNode::getIDocumentContentOperations() { return GetDoc(); }
-IDocumentListItems& SwNode::getIDocumentListItems() { return *GetDoc(); } // #i83479#
+IDocumentListItems& SwNode::getIDocumentListItems() { return GetDoc()->getIDocumentListItems(); } // #i83479#
const IDocumentMarkAccess* SwNode::getIDocumentMarkAccess() const { return GetDoc()->getIDocumentMarkAccess(); }
IStyleAccess& SwNode::getIDocumentStyleAccess() { return GetDoc()->GetIStyleAccess(); }
diff --git a/sw/source/core/inc/DocumentListItemsManager.hxx b/sw/source/core/inc/DocumentListItemsManager.hxx
new file mode 100644
index 0000000..c292967
--- /dev/null
+++ b/sw/source/core/inc/DocumentListItemsManager.hxx
@@ -0,0 +1,69 @@
+/* -*- 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_DOCUMENTLISTITEMSMANAGER_HXX
+#define INCLUDED_SW_SOURCE_CORE_INC_DOCUMENTLISTITEMSMANAGER_HXX
+
+#include <IDocumentListItems.hxx>
+#include <boost/utility.hpp>
+#include <set>
+
+namespace sw
+{
+
+class DocumentListItemsManager : public IDocumentListItems,
+ public ::boost::noncopyable
+{
+public:
+
+ DocumentListItemsManager();
+
+ void addListItem( const SwNodeNum& rNodeNum ) SAL_OVERRIDE;
+ void removeListItem( const SwNodeNum& rNodeNum ) SAL_OVERRIDE;
+
+ OUString getListItemText( const SwNodeNum& rNodeNum,
+ const bool bWithNumber = true,
+ const bool bWithSpacesForLevel = false ) const SAL_OVERRIDE;
+
+ void getListItems( IDocumentListItems::tSortedNodeNumList& orNodeNumList ) const SAL_OVERRIDE;
+
+ void getNumItems( IDocumentListItems::tSortedNodeNumList& orNodeNumList ) const SAL_OVERRIDE;
+
+ virtual ~DocumentListItemsManager();
+
+
+ //Non Interface
+ struct lessThanNodeNum
+ {
+ bool operator()( const SwNodeNum* pNodeNumOne,
+ const SwNodeNum* pNodeNumTwo ) const;
+ };
+
+ typedef ::std::set< const SwNodeNum*, lessThanNodeNum > tImplSortedNodeNumList;
+
+private:
+
+ tImplSortedNodeNumList* mpListItemsList;
+};
+
+}
+
+ #endif // INCLUDED_SW_SOURCE_CORE_INC_DOCUMENTLISTITEMSMANAGER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index 766a8ac..ccc2e8d 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -2533,7 +2533,7 @@ IDocumentUndoRedo const& SwViewShell::GetIDocumentUndoRedo() const
// --> OD 2007-11-14 #i83479#
const IDocumentListItems* SwViewShell::getIDocumentListItemsAccess() const
{
- return mpDoc;
+ return &mpDoc->getIDocumentListItems();
}
const IDocumentOutlineNodes* SwViewShell::getIDocumentOutlineNodesAccess() const
More information about the Libreoffice-commits
mailing list