[Libreoffice-commits] .: sc/inc sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Wed Jun 1 16:15:29 PDT 2011
sc/inc/userlist.hxx | 32 ++++++----
sc/source/core/data/table3.cxx | 5 -
sc/source/core/tool/appoptio.cxx | 9 +-
sc/source/core/tool/userlist.cxx | 118 +++++++++++++++++++++++++--------------
sc/source/ui/dbgui/tpsort.cxx | 4 -
sc/source/ui/dbgui/tpsubt.cxx | 7 --
sc/source/ui/inc/tpusrlst.hxx | 4 -
sc/source/ui/optdlg/tpusrlst.cxx | 33 +++++-----
sc/source/ui/unoobj/appluno.cxx | 9 +-
sc/source/ui/view/dbfunc3.cxx | 6 -
sc/source/ui/view/gridwin2.cxx | 6 -
11 files changed, 137 insertions(+), 96 deletions(-)
New commits:
commit 2eaf28d7bf7e4099c4ae6f92e521af6001884f8d
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Wed Jun 1 19:14:40 2011 -0400
ScUserList and ScUserListData no longer dependent of ScCollection.
diff --git a/sc/inc/userlist.hxx b/sc/inc/userlist.hxx
index add91ed..84a1297 100644
--- a/sc/inc/userlist.hxx
+++ b/sc/inc/userlist.hxx
@@ -31,14 +31,13 @@
#include <tools/stream.hxx>
#include "scdllapi.h"
-#include "collect.hxx"
#include <boost/ptr_container/ptr_vector.hpp>
/**
* Stores individual user-defined sort list.
*/
-class SC_DLLPUBLIC ScUserListData : public ScDataObject
+class SC_DLLPUBLIC ScUserListData
{
public:
struct SubStr
@@ -57,9 +56,7 @@ private:
public:
ScUserListData(const ::rtl::OUString& rStr);
ScUserListData(const ScUserListData& rData);
- virtual ~ScUserListData();
-
- virtual ScDataObject* Clone() const { return new ScUserListData(*this); }
+ ~ScUserListData();
const ::rtl::OUString& GetString() const { return aStr; }
void SetString(const ::rtl::OUString& rStr);
@@ -73,22 +70,35 @@ public:
/**
* Collection of user-defined sort lists.
*/
-class SC_DLLPUBLIC ScUserList : public ScCollection
+class SC_DLLPUBLIC ScUserList
{
+ typedef ::boost::ptr_vector<ScUserListData> DataType;
+ DataType maData;
public:
- ScUserList( sal_uInt16 nLim = 4, sal_uInt16 nDel = 4);
- ScUserList( const ScUserList& rUserList ) : ScCollection ( rUserList ) {}
+ typedef DataType::iterator iterator;
+ typedef DataType::const_iterator const_iterator;
- virtual ScDataObject* Clone() const;
+ ScUserList();
+ ScUserList(const ScUserList& r);
- ScUserListData* GetData( const ::rtl::OUString& rSubStr ) const;
+ const ScUserListData* GetData( const ::rtl::OUString& rSubStr ) const;
/// If the list in rStr is already inserted
bool HasEntry( const ::rtl::OUString& rStr ) const;
- ScUserListData* operator[]( const sal_uInt16 nIndex) const;
+ const ScUserListData* operator[](size_t nIndex) const;
+ ScUserListData* operator[](size_t nIndex);
ScUserList& operator= ( const ScUserList& r );
bool operator==( const ScUserList& r ) const;
bool operator!=( const ScUserList& r ) const;
+
+ iterator begin();
+ iterator end();
+ const_iterator begin() const;
+ const_iterator end() const;
+ void clear();
+ size_t size() const;
+ void push_back(ScUserListData* p);
+ void erase(iterator itr);
};
#endif
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 1b16b39..6982da8 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -427,9 +427,8 @@ short ScTable::CompareCell( sal_uInt16 nSort,
if (bUserDef)
{
- ScUserListData* pData =
- static_cast<ScUserListData*>( (ScGlobal::GetUserList()->At(
- aSortParam.nUserIndex)) );
+ ScUserList* pList = ScGlobal::GetUserList();
+ const ScUserListData* pData = (*pList)[aSortParam.nUserIndex];
if (pData)
{
diff --git a/sc/source/core/tool/appoptio.cxx b/sc/source/core/tool/appoptio.cxx
index ba7ea8a..4680d86 100644
--- a/sc/source/core/tool/appoptio.cxx
+++ b/sc/source/core/tool/appoptio.cxx
@@ -219,13 +219,12 @@ void lcl_SetSortList( const Any& rValue )
if (!bDefault)
{
- aList.FreeAll();
+ aList.clear();
for (long i=0; i<nCount; i++)
{
ScUserListData* pNew = new ScUserListData( pArray[i] );
- if ( !aList.Insert(pNew) )
- delete pNew;
+ aList.push_back(pNew);
}
}
@@ -238,10 +237,10 @@ void lcl_GetSortList( Any& rDest )
const ScUserList* pUserList = ScGlobal::GetUserList();
if (pUserList)
{
- long nCount = pUserList->GetCount();
+ size_t nCount = pUserList->size();
Sequence<OUString> aSeq( nCount );
OUString* pArray = aSeq.getArray();
- for (long i=0; i<nCount; i++)
+ for (size_t i=0; i<nCount; ++i)
pArray[i] = (*pUserList)[sal::static_int_cast<sal_uInt16>(i)]->GetString();
rDest <<= aSeq;
}
diff --git a/sc/source/core/tool/userlist.cxx b/sc/source/core/tool/userlist.cxx
index 7b7b1de..68ed9fa 100644
--- a/sc/source/core/tool/userlist.cxx
+++ b/sc/source/core/tool/userlist.cxx
@@ -41,6 +41,8 @@
#include <unotools/calendarwrapper.hxx>
#include <unotools/transliterationwrapper.hxx>
+#include <boost/bind.hpp>
+
using ::rtl::OUString;
namespace {
@@ -108,7 +110,6 @@ ScUserListData::ScUserListData(const OUString& rStr) :
}
ScUserListData::ScUserListData(const ScUserListData& rData) :
- ScDataObject(),
aStr(rData.aStr)
{
InitTokens();
@@ -212,8 +213,7 @@ StringCompare ScUserListData::ICompare(const OUString& rSubStr1, const OUString&
return (StringCompare) ScGlobal::GetpTransliteration()->compareString( rSubStr1, rSubStr2 );
}
-ScUserList::ScUserList(sal_uInt16 nLim, sal_uInt16 nDel) :
- ScCollection ( nLim, nDel )
+ScUserList::ScUserList()
{
using namespace ::com::sun::star;
@@ -250,9 +250,9 @@ ScUserList::ScUserList(sal_uInt16 nLim, sal_uInt16 nDel) :
sDayLong += String( xCal[i].FullName );
if ( !HasEntry( sDayShort ) )
- Insert( new ScUserListData( sDayShort ));
+ maData.push_back( new ScUserListData( sDayShort ));
if ( !HasEntry( sDayLong ) )
- Insert( new ScUserListData( sDayLong ));
+ maData.push_back( new ScUserListData( sDayLong ));
}
xCal = xCalendars[j].Months;
@@ -272,58 +272,58 @@ ScUserList::ScUserList(sal_uInt16 nLim, sal_uInt16 nDel) :
sMonthLong += String( xCal[i].FullName );
if ( !HasEntry( sMonthShort ) )
- Insert( new ScUserListData( sMonthShort ));
+ maData.push_back( new ScUserListData( sMonthShort ));
if ( !HasEntry( sMonthLong ) )
- Insert( new ScUserListData( sMonthLong ));
+ maData.push_back( new ScUserListData( sMonthLong ));
}
}
}
-ScDataObject* ScUserList::Clone() const
+ScUserList::ScUserList(const ScUserList& r) :
+ maData(r.maData) {}
+
+const ScUserListData* ScUserList::GetData(const OUString& rSubStr) const
{
- return ( new ScUserList( *this ) );
+ DataType::const_iterator itr = maData.begin(), itrEnd = maData.end();
+ for (; itr != itrEnd; ++itr)
+ {
+ sal_uInt16 nIndex;
+ if (itr->GetSubIndex(rSubStr, nIndex))
+ return &(*itr);
+ }
+ return NULL;
}
-ScUserListData* ScUserList::GetData(const OUString& rSubStr) const
+const ScUserListData* ScUserList::operator[](size_t nIndex) const
{
- sal_uInt16 nIndex;
- sal_uInt16 i = 0;
- for (i=0; i < nCount; i++)
- if (((ScUserListData*)pItems[i])->GetSubIndex(rSubStr, nIndex))
- return (ScUserListData*)pItems[i];
- return NULL;
+ return &maData[nIndex];
}
-ScUserListData* ScUserList::operator[]( const sal_uInt16 nIndex) const
+ScUserListData* ScUserList::operator[](size_t nIndex)
{
- return (ScUserListData*)At(nIndex);
+ return &maData[nIndex];
}
ScUserList& ScUserList::operator=( const ScUserList& r )
{
- return (ScUserList&)ScCollection::operator=( r );
+ maData = r.maData;
+ return *this;
}
bool ScUserList::operator==( const ScUserList& r ) const
{
- bool bEqual = (nCount == r.nCount);
+ if (size() != r.size())
+ return false;
- if ( bEqual )
+ DataType::const_iterator itr1 = maData.begin(), itr2 = r.maData.begin(), itrEnd = maData.end();
+ for (; itr1 != itrEnd; ++itr1, ++itr2)
{
- ScUserListData* pMyData = NULL;
- ScUserListData* pOtherData = NULL;
-
- for ( sal_uInt16 i=0; i<nCount && bEqual; i++)
- {
- pMyData = (ScUserListData*)At(i);
- pOtherData = (ScUserListData*)r.At(i);
-
- bEqual = ((pMyData->GetSubCount() == pOtherData->GetSubCount())
- && (pMyData->GetString() == pOtherData->GetString()) );
- }
+ const ScUserListData& v1 = *itr1;
+ const ScUserListData& v2 = *itr2;
+ if (v1.GetString() != v2.GetString() || v1.GetSubCount() != v2.GetSubCount())
+ return false;
}
-
- return bEqual;
+ return true;
}
bool ScUserList::operator!=( const ScUserList& r ) const
@@ -334,13 +334,49 @@ bool ScUserList::operator!=( const ScUserList& r ) const
bool ScUserList::HasEntry( const OUString& rStr ) const
{
- for ( sal_uInt16 i=0; i<nCount; i++)
- {
- const ScUserListData* pMyData = (ScUserListData*) At(i);
- if ( pMyData->GetString() == rStr )
- return true;
- }
- return false;
+ DataType::const_iterator itr = ::std::find_if(
+ maData.begin(), maData.end(), ::boost::bind(&ScUserListData::GetString, _1) == rStr);
+ return itr != maData.end();
+}
+
+ScUserList::iterator ScUserList::begin()
+{
+ return maData.begin();
+}
+
+ScUserList::iterator ScUserList::end()
+{
+ return maData.end();
+}
+
+ScUserList::const_iterator ScUserList::begin() const
+{
+ return maData.begin();
+}
+
+ScUserList::const_iterator ScUserList::end() const
+{
+ return maData.end();
+}
+
+void ScUserList::clear()
+{
+ maData.clear();
+}
+
+size_t ScUserList::size() const
+{
+ return maData.size();
+}
+
+void ScUserList::push_back(ScUserListData* p)
+{
+ maData.push_back(p);
+}
+
+void ScUserList::erase(iterator itr)
+{
+ maData.erase(itr);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/dbgui/tpsort.cxx b/sc/source/ui/dbgui/tpsort.cxx
index eac9df4..6c41c89 100644
--- a/sc/source/ui/dbgui/tpsort.cxx
+++ b/sc/source/ui/dbgui/tpsort.cxx
@@ -935,9 +935,9 @@ void ScTabPageSortOptions::FillUserSortListBox()
aLbSortUser.Clear();
if ( pUserLists )
{
- sal_uInt16 nCount = pUserLists->GetCount();
+ size_t nCount = pUserLists->size();
if ( nCount > 0 )
- for ( sal_uInt16 i=0; i<nCount; i++ )
+ for ( size_t i=0; i<nCount; ++i )
aLbSortUser.InsertEntry( (*pUserLists)[i]->GetString() );
}
}
diff --git a/sc/source/ui/dbgui/tpsubt.cxx b/sc/source/ui/dbgui/tpsubt.cxx
index b37a362..acf7c38 100644
--- a/sc/source/ui/dbgui/tpsubt.cxx
+++ b/sc/source/ui/dbgui/tpsubt.cxx
@@ -617,10 +617,9 @@ void ScTpSubTotalOptions::FillUserSortListBox()
aLbUserDef.Clear();
if ( pUserLists )
{
- sal_uInt16 nCount = pUserLists->GetCount();
- if ( nCount > 0 )
- for ( sal_uInt16 i=0; i<nCount; i++ )
- aLbUserDef.InsertEntry( (*pUserLists)[i]->GetString() );
+ size_t nCount = pUserLists->size();
+ for ( size_t i=0; i<nCount; ++i )
+ aLbUserDef.InsertEntry( (*pUserLists)[i]->GetString() );
}
}
diff --git a/sc/source/ui/inc/tpusrlst.hxx b/sc/source/ui/inc/tpusrlst.hxx
index 5e32c49..9f234e8 100644
--- a/sc/source/ui/inc/tpusrlst.hxx
+++ b/sc/source/ui/inc/tpusrlst.hxx
@@ -96,10 +96,10 @@ private:
private:
void Init ();
sal_uInt16 UpdateUserListBox ();
- void UpdateEntries ( sal_uInt16 nList );
+ void UpdateEntries ( size_t nList );
void MakeListStr ( String& rListStr );
void AddNewList ( const String& rEntriesStr );
- void RemoveList ( sal_uInt16 nList );
+ void RemoveList ( size_t nList );
void ModifyList ( sal_uInt16 nSelList,
const String& rEntriesStr );
void CopyListFromArea ( const ScRefAddress& rStartPos,
diff --git a/sc/source/ui/optdlg/tpusrlst.cxx b/sc/source/ui/optdlg/tpusrlst.cxx
index 52f31ee..d568546 100644
--- a/sc/source/ui/optdlg/tpusrlst.cxx
+++ b/sc/source/ui/optdlg/tpusrlst.cxx
@@ -289,17 +289,14 @@ sal_uInt16 ScTpUserLists::UpdateUserListBox()
//----------------------------------------------------------
- sal_uInt16 nCount = pUserLists->GetCount();
+ size_t nCount = pUserLists->size();
String aEntry;
- if ( nCount > 0 )
+ for ( size_t i=0; i<nCount; ++i )
{
- for ( sal_uInt16 i=0; i<nCount; i++ )
- {
- aEntry = (*pUserLists)[i]->GetString();
- OSL_ENSURE( aEntry.Len() > 0, "Empty UserList-entry :-/" );
- aLbLists.InsertEntry( aEntry );
- }
+ aEntry = (*pUserLists)[i]->GetString();
+ OSL_ENSURE( aEntry.Len() > 0, "Empty UserList-entry :-/" );
+ aLbLists.InsertEntry( aEntry );
}
return nCount;
@@ -307,15 +304,15 @@ sal_uInt16 ScTpUserLists::UpdateUserListBox()
// -----------------------------------------------------------------------
-void ScTpUserLists::UpdateEntries( sal_uInt16 nList )
+void ScTpUserLists::UpdateEntries( size_t nList )
{
if ( !pUserLists ) return;
//----------------------------------------------------------
- if ( nList < pUserLists->GetCount() )
+ if ( nList < pUserLists->size() )
{
- ScUserListData* pList = (*pUserLists)[nList];
+ const ScUserListData* pList = (*pUserLists)[nList];
sal_uInt16 nSubCount = pList->GetSubCount();
String aEntryListStr;
@@ -393,10 +390,7 @@ void ScTpUserLists::AddNewList( const String& rEntriesStr )
MakeListStr( theEntriesStr );
- if ( !pUserLists->Insert( new ScUserListData( theEntriesStr ) ) )
- {
- OSL_FAIL( "Entry could not be inserted :-/" );
- }
+ pUserLists->push_back(new ScUserListData(theEntriesStr));
}
// -----------------------------------------------------------------------
@@ -509,9 +503,14 @@ void ScTpUserLists::ModifyList( sal_uInt16 nSelList,
// -----------------------------------------------------------------------
-void ScTpUserLists::RemoveList( sal_uInt16 nList )
+void ScTpUserLists::RemoveList( size_t nList )
{
- if ( pUserLists ) pUserLists->AtFree( nList );
+ if (pUserLists && nList < pUserLists->size())
+ {
+ ScUserList::iterator itr = pUserLists->begin();
+ ::std::advance(itr, nList);
+ pUserLists->erase(itr);
+ }
}
//-----------------------------------------------------------------------
diff --git a/sc/source/ui/unoobj/appluno.cxx b/sc/source/ui/unoobj/appluno.cxx
index 4ea234b..d32d547 100644
--- a/sc/source/ui/unoobj/appluno.cxx
+++ b/sc/source/ui/unoobj/appluno.cxx
@@ -522,15 +522,14 @@ void SAL_CALL ScSpreadsheetSettings::setPropertyValue(
// es wird direkt die "lebende" Liste veraendert,
// mehr tut ScGlobal::SetUserList auch nicht
- pUserList->FreeAll(); // alle Eintraege raus
+ pUserList->clear(); // alle Eintraege raus
sal_uInt16 nCount = (sal_uInt16)aSeq.getLength();
const rtl::OUString* pAry = aSeq.getConstArray();
for (sal_uInt16 i=0; i<nCount; i++)
{
String aEntry = pAry[i];
ScUserListData* pData = new ScUserListData(aEntry);
- if (!pUserList->Insert(pData)) // hinten anhaengen
- delete pData; // sollte nicht vorkommen
+ pUserList->push_back(pData);
}
bSaveApp = sal_True; // Liste wird mit den App-Optionen gespeichert
}
@@ -603,10 +602,10 @@ uno::Any SAL_CALL ScSpreadsheetSettings::getPropertyValue( const rtl::OUString&
ScUserList* pUserList = ScGlobal::GetUserList();
if (pUserList)
{
- sal_uInt16 nCount = pUserList->GetCount();
+ size_t nCount = pUserList->size();
uno::Sequence<rtl::OUString> aSeq(nCount);
rtl::OUString* pAry = aSeq.getArray();
- for (sal_uInt16 i=0; i<nCount; i++)
+ for (size_t i=0; i<nCount; ++i)
{
String aEntry((*pUserList)[i]->GetString());
pAry[i] = aEntry;
diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx
index 5adadaf..daa03ea 100644
--- a/sc/source/ui/view/dbfunc3.cxx
+++ b/sc/source/ui/view/dbfunc3.cxx
@@ -1803,12 +1803,12 @@ bool ScDBFunc::DataPilotSort( const ScAddress& rPos, bool bAscending, sal_uInt16
return false;
{
- sal_uInt16 n = pUserList->GetCount();
- if (!n || *pUserListId >= n)
+ size_t n = pUserList->size();
+ if (!n || *pUserListId >= static_cast<sal_uInt16>(n))
return false;
}
- ScUserListData* pData = static_cast<ScUserListData*>((*pUserList)[*pUserListId]);
+ const ScUserListData* pData = (*pUserList)[*pUserListId];
if (pData)
{
sal_uInt16 n = pData->GetSubCount();
diff --git a/sc/source/ui/view/gridwin2.cxx b/sc/source/ui/view/gridwin2.cxx
index 1c9eff2..b67d0aa 100644
--- a/sc/source/ui/view/gridwin2.cxx
+++ b/sc/source/ui/view/gridwin2.cxx
@@ -490,11 +490,11 @@ void ScGridWindow::DPLaunchFieldPopupMenu(
ScUserList* pUserList = ScGlobal::GetUserList();
if (pUserList)
{
- sal_uInt16 n = pUserList->GetCount();
+ size_t n = pUserList->size();
aUserSortNames.reserve(n);
- for (sal_uInt16 i = 0; i < n; ++i)
+ for (size_t i = 0; i < n; ++i)
{
- ScUserListData* pData = static_cast<ScUserListData*>((*pUserList)[i]);
+ const ScUserListData* pData = (*pUserList)[i];
aUserSortNames.push_back(pData->GetString());
}
}
More information about the Libreoffice-commits
mailing list