[Libreoffice-commits] .: sc/inc sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Mon Feb 6 21:50:49 PST 2012
sc/inc/autoform.hxx | 56 ++++++++-----
sc/source/core/data/table4.cxx | 6 -
sc/source/core/tool/autoform.cxx | 145 +++++++++++++++++++++++-----------
sc/source/ui/docshell/docfunc.cxx | 8 -
sc/source/ui/inc/docfunc.hxx | 4
sc/source/ui/inc/scuiautofmt.hxx | 4
sc/source/ui/miscdlgs/scuiautofmt.cxx | 87 ++++++++++----------
sc/source/ui/unoobj/afmtuno.cxx | 69 ++++++++--------
sc/source/ui/unoobj/cellsuno.cxx | 14 +--
sc/source/ui/view/cellsh3.cxx | 4
10 files changed, 237 insertions(+), 160 deletions(-)
New commits:
commit 72c1b6141d590fb4479925ed8bc88b79357c2bfc
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date: Tue Feb 7 00:50:36 2012 -0500
ScAutoFormat no longer a child of ScSortedCollection.
diff --git a/sc/inc/autoform.hxx b/sc/inc/autoform.hxx
index 5ab5ac1..724d63f 100644
--- a/sc/inc/autoform.hxx
+++ b/sc/inc/autoform.hxx
@@ -69,6 +69,7 @@
#include "global.hxx"
#include "zforauto.hxx"
+#include <boost/ptr_container/ptr_map.hpp>
struct ScAfVersions;
@@ -197,7 +198,7 @@ public:
};
-class SC_DLLPUBLIC ScAutoFormatData : public ScDataObject
+class SC_DLLPUBLIC ScAutoFormatData
{
private:
rtl::OUString aName;
@@ -218,11 +219,9 @@ private:
SC_DLLPRIVATE const ScAutoFormatDataField& GetField( sal_uInt16 nIndex ) const;
public:
- ScAutoFormatData();
- ScAutoFormatData( const ScAutoFormatData& rData );
- virtual ~ScAutoFormatData();
-
- virtual ScDataObject* Clone() const { return new ScAutoFormatData( *this ); }
+ ScAutoFormatData();
+ ScAutoFormatData( const ScAutoFormatData& rData );
+ ~ScAutoFormatData();
void SetName( const rtl::OUString& rName ) { aName = rName; nStrResId = USHRT_MAX; }
const rtl::OUString& GetName() const { return aName; }
@@ -260,23 +259,40 @@ public:
#endif
};
-class SC_DLLPUBLIC ScAutoFormat : public ScSortedCollection
+class SC_DLLPUBLIC ScAutoFormat
{
-private:
- bool bSaveLater;
+ typedef boost::ptr_map<rtl::OUString, ScAutoFormatData> MapType;
+ MapType maData;
+ bool mbSaveLater;
public:
- ScAutoFormat( sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = false );
- ScAutoFormat( const ScAutoFormat& AutoFormat );
- virtual ~ScAutoFormat();
- virtual ScDataObject* Clone() const { return new ScAutoFormat( *this ); }
- ScAutoFormatData* operator[]( const sal_uInt16 nIndex ) const {return (ScAutoFormatData*)At( nIndex );}
- virtual short Compare( ScDataObject* pKey1, ScDataObject* pKey2 ) const;
- bool Load();
- bool Save();
- sal_uInt16 FindIndexPerName( const rtl::OUString& rName ) const;
- void SetSaveLater( bool bSet );
- bool IsSaveLater() const { return bSaveLater; }
+ typedef MapType::const_iterator const_iterator;
+ typedef MapType::iterator iterator;
+
+ ScAutoFormat();
+ ScAutoFormat(const ScAutoFormat& r);
+ ~ScAutoFormat();
+ bool Load();
+ bool Save();
+
+ void SetSaveLater( bool bSet );
+ bool IsSaveLater() const { return mbSaveLater; }
+
+ const ScAutoFormatData* findByIndex(size_t nIndex) const;
+ ScAutoFormatData* findByIndex(size_t nIndex);
+ const_iterator find(const ScAutoFormatData* pData) const;
+ iterator find(const ScAutoFormatData* pData);
+ const_iterator find(const rtl::OUString& rName) const;
+ iterator find(const rtl::OUString& rName);
+
+ bool insert(ScAutoFormatData* pNew);
+ void erase(const iterator& it);
+
+ size_t size() const;
+ const_iterator begin() const;
+ const_iterator end() const;
+ iterator begin();
+ iterator end();
};
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index dac4111..7990d28 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -1591,7 +1591,8 @@ void ScTable::Fill( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
void ScTable::AutoFormatArea(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
const ScPatternAttr& rAttr, sal_uInt16 nFormatNo)
{
- ScAutoFormatData* pData = (*ScGlobal::GetOrCreateAutoFormat())[nFormatNo];
+ ScAutoFormat& rFormat = *ScGlobal::GetOrCreateAutoFormat();
+ ScAutoFormatData* pData = rFormat.findByIndex(nFormatNo);
if (pData)
{
ApplyPatternArea(nStartCol, nStartRow, nEndCol, nEndRow, rAttr);
@@ -1603,7 +1604,8 @@ void ScTable::AutoFormat( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW
{
if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
{
- ScAutoFormatData* pData = (*ScGlobal::GetOrCreateAutoFormat())[nFormatNo];
+ ScAutoFormat& rFormat = *ScGlobal::GetOrCreateAutoFormat();
+ ScAutoFormatData* pData = rFormat.findByIndex(nFormatNo);
if (pData)
{
ScPatternAttr* pPatternAttrs[16];
diff --git a/sc/source/core/tool/autoform.cxx b/sc/source/core/tool/autoform.cxx
index 76dc8b5..5151105 100644
--- a/sc/source/core/tool/autoform.cxx
+++ b/sc/source/core/tool/autoform.cxx
@@ -495,7 +495,6 @@ ScAutoFormatData::ScAutoFormatData()
}
ScAutoFormatData::ScAutoFormatData( const ScAutoFormatData& rData ) :
- ScDataObject(),
aName( rData.aName ),
nStrResId( rData.nStrResId ),
bIncludeFont( rData.bIncludeFont ),
@@ -889,9 +888,8 @@ bool ScAutoFormatData::Save(SvStream& rStream)
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
-ScAutoFormat::ScAutoFormat(sal_uInt16 nLim, sal_uInt16 nDel, sal_Bool bDup):
- ScSortedCollection (nLim, nDel, bDup),
- bSaveLater (false)
+ScAutoFormat::ScAutoFormat() :
+ mbSaveLater(false)
{
// create default autoformat
ScAutoFormatData* pData = new ScAutoFormatData;
@@ -971,38 +969,113 @@ ScAutoFormat::ScAutoFormat(sal_uInt16 nLim, sal_uInt16 nDel, sal_Bool bDup):
}
}
- Insert(pData);
+ insert(pData);
}
-ScAutoFormat::ScAutoFormat(const ScAutoFormat& rAutoFormat) :
- ScSortedCollection (rAutoFormat),
- bSaveLater (false)
-{}
+ScAutoFormat::ScAutoFormat(const ScAutoFormat& r) :
+ maData(r.maData),
+ mbSaveLater(false) {}
ScAutoFormat::~ScAutoFormat()
{
// Bei Aenderungen per StarOne wird nicht sofort gespeichert, sondern zuerst nur
// das SaveLater Flag gesetzt. Wenn das Flag noch gesetzt ist, jetzt speichern.
- if (bSaveLater)
+ if (mbSaveLater)
Save();
}
void ScAutoFormat::SetSaveLater( bool bSet )
{
- bSaveLater = bSet;
+ mbSaveLater = bSet;
}
-short ScAutoFormat::Compare(ScDataObject* pKey1, ScDataObject* pKey2) const
+const ScAutoFormatData* ScAutoFormat::findByIndex(size_t nIndex) const
{
- rtl::OUString aStr1 = ((ScAutoFormatData*)pKey1)->GetName();
- rtl::OUString aStr2 = ((ScAutoFormatData*)pKey2)->GetName();
- String aStrStandard = ScGlobal::GetRscString(STR_STYLENAME_STANDARD);
- if ( ScGlobal::GetpTransliteration()->isEqual( aStr1, aStrStandard ) )
- return -1;
- if ( ScGlobal::GetpTransliteration()->isEqual( aStr2, aStrStandard ) )
- return 1;
- return (short) ScGlobal::GetpTransliteration()->compareString( aStr1, aStr2 );
+ if (nIndex >= maData.size())
+ return NULL;
+
+ MapType::const_iterator it = maData.begin();
+ std::advance(it, nIndex);
+ return it->second;
+}
+
+ScAutoFormatData* ScAutoFormat::findByIndex(size_t nIndex)
+{
+ if (nIndex >= maData.size())
+ return NULL;
+
+ MapType::iterator it = maData.begin();
+ std::advance(it, nIndex);
+ return it->second;
+}
+
+ScAutoFormat::const_iterator ScAutoFormat::find(const ScAutoFormatData* pData) const
+{
+ MapType::const_iterator it = maData.begin(), itEnd = maData.end();
+ for (; it != itEnd; ++it)
+ {
+ if (it->second == pData)
+ return it;
+ }
+ return itEnd;
+}
+
+ScAutoFormat::iterator ScAutoFormat::find(const ScAutoFormatData* pData)
+{
+ MapType::iterator it = maData.begin(), itEnd = maData.end();
+ for (; it != itEnd; ++it)
+ {
+ if (it->second == pData)
+ return it;
+ }
+ return itEnd;
+}
+
+ScAutoFormat::const_iterator ScAutoFormat::find(const rtl::OUString& rName) const
+{
+ return maData.find(rName);
+}
+
+ScAutoFormat::iterator ScAutoFormat::find(const rtl::OUString& rName)
+{
+ return maData.find(rName);
+}
+
+bool ScAutoFormat::insert(ScAutoFormatData* pNew)
+{
+ rtl::OUString aName = pNew->GetName();
+ return maData.insert(aName, pNew).second;
+}
+
+void ScAutoFormat::erase(const iterator& it)
+{
+ maData.erase(it);
+}
+
+size_t ScAutoFormat::size() const
+{
+ return maData.size();
+}
+
+ScAutoFormat::const_iterator ScAutoFormat::begin() const
+{
+ return maData.begin();
+}
+
+ScAutoFormat::const_iterator ScAutoFormat::end() const
+{
+ return maData.end();
+}
+
+ScAutoFormat::iterator ScAutoFormat::begin()
+{
+ return maData.begin();
+}
+
+ScAutoFormat::iterator ScAutoFormat::end()
+{
+ return maData.end();
}
bool ScAutoFormat::Load()
@@ -1059,7 +1132,7 @@ bool ScAutoFormat::Load()
{
pData = new ScAutoFormatData();
bRet = pData->Load(rStream, aVersions);
- Insert(pData);
+ insert(pData);
}
}
#ifdef READ_OLDVERS
@@ -1096,7 +1169,7 @@ bool ScAutoFormat::Load()
{
pData = new ScAutoFormatData();
bRet = pData->LoadOld( rStream, aVersions );
- Insert( pData );
+ insert(pData);
}
}
else
@@ -1105,7 +1178,7 @@ bool ScAutoFormat::Load()
#endif
}
}
- bSaveLater = false;
+ mbSaveLater = false;
return bRet;
}
@@ -1137,32 +1210,18 @@ bool ScAutoFormat::Save()
bRet = (rStream.GetError() == 0);
//-----------------------------------------------------------
- rStream << (sal_uInt16)(nCount - 1);
+ rStream << (sal_uInt16)(maData.size() - 1);
bRet = (rStream.GetError() == 0);
- for (sal_uInt16 i=1; bRet && (i < nCount); i++)
- bRet = ((ScAutoFormatData*)pItems[i])->Save(rStream);
+ MapType::iterator it = maData.begin(), itEnd = maData.end();
+ for (++it; bRet && it != itEnd; ++it) // Skip the first item.
+ bRet = it->second->Save(rStream);
+
rStream.Flush();
aMedium.Commit();
}
- bSaveLater = false;
+ mbSaveLater = false;
return bRet;
}
-sal_uInt16 ScAutoFormat::FindIndexPerName( const rtl::OUString& rName ) const
-{
- for( sal_uInt16 i=0; i<nCount ; i++ )
- {
- ScAutoFormatData* pItem = (ScAutoFormatData*)pItems[i];
-
- if (pItem->GetName().equals(rName))
- return i;
- }
-
- return 0;
-}
-
-
-
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 94dd497..a211534 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -3667,8 +3667,8 @@ sal_Bool ScDocFunc::ChangeIndent( const ScMarkData& rMark, sal_Bool bIncrement,
return sal_True;
}
-sal_Bool ScDocFunc::AutoFormat( const ScRange& rRange, const ScMarkData* pTabMark,
- sal_uInt16 nFormatNo, sal_Bool bRecord, sal_Bool bApi )
+bool ScDocFunc::AutoFormat( const ScRange& rRange, const ScMarkData* pTabMark,
+ sal_uInt16 nFormatNo, bool bRecord, bool bApi )
{
ScDocShellModificator aModificator( rDocShell );
@@ -3694,11 +3694,11 @@ sal_Bool ScDocFunc::AutoFormat( const ScRange& rRange, const ScMarkData* pTabMar
ScAutoFormat* pAutoFormat = ScGlobal::GetOrCreateAutoFormat();
ScEditableTester aTester( pDoc, nStartCol,nStartRow, nEndCol,nEndRow, aMark );
- if ( nFormatNo < pAutoFormat->GetCount() && aTester.IsEditable() )
+ if ( nFormatNo < pAutoFormat->size() && aTester.IsEditable() )
{
WaitObject aWait( rDocShell.GetActiveDialogParent() );
- sal_Bool bSize = (*pAutoFormat)[nFormatNo]->GetIncludeWidthHeight();
+ bool bSize = pAutoFormat->findByIndex(nFormatNo)->GetIncludeWidthHeight();
SCTAB nTabCount = pDoc->GetTableCount();
ScDocument* pUndoDoc = NULL;
diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx
index a339b94..63cbc39 100644
--- a/sc/source/ui/inc/docfunc.hxx
+++ b/sc/source/ui/inc/docfunc.hxx
@@ -151,8 +151,8 @@ public:
sal_Bool ClearItems( const ScMarkData& rMark, const sal_uInt16* pWhich, sal_Bool bApi );
sal_Bool ChangeIndent( const ScMarkData& rMark, sal_Bool bIncrement, sal_Bool bApi );
- sal_Bool AutoFormat( const ScRange& rRange, const ScMarkData* pTabMark,
- sal_uInt16 nFormatNo, sal_Bool bRecord, sal_Bool bApi );
+ bool AutoFormat( const ScRange& rRange, const ScMarkData* pTabMark,
+ sal_uInt16 nFormatNo, bool bRecord, bool bApi );
sal_Bool EnterMatrix( const ScRange& rRange, const ScMarkData* pTabMark,
const ScTokenArray* pTokenArray,
diff --git a/sc/source/ui/inc/scuiautofmt.hxx b/sc/source/ui/inc/scuiautofmt.hxx
index 6547796..4a3a441 100644
--- a/sc/source/ui/inc/scuiautofmt.hxx
+++ b/sc/source/ui/inc/scuiautofmt.hxx
@@ -70,8 +70,8 @@ private:
ScAutoFormat* pFormat;
const ScAutoFormatData* pSelFmtData;
sal_uInt16 nIndex;
- sal_Bool bCoreDataChanged;
- sal_Bool bFmtInserted;
+ bool bCoreDataChanged;
+ bool bFmtInserted;
void Init ();
void UpdateChecks ();
diff --git a/sc/source/ui/miscdlgs/scuiautofmt.cxx b/sc/source/ui/miscdlgs/scuiautofmt.cxx
index 8f8ef23..074cbe3 100644
--- a/sc/source/ui/miscdlgs/scuiautofmt.cxx
+++ b/sc/source/ui/miscdlgs/scuiautofmt.cxx
@@ -104,7 +104,8 @@ ScAutoFormatDlg::ScAutoFormatDlg( Window* pParent,
bFmtInserted ( false )
{
Init();
- pWndPreview->NotifyChange( (*pFormat)[0] );
+ ScAutoFormat::iterator it = pFormat->begin();
+ pWndPreview->NotifyChange(it->second);
FreeResource();
}
@@ -119,9 +120,6 @@ ScAutoFormatDlg::~ScAutoFormatDlg()
void ScAutoFormatDlg::Init()
{
- sal_uInt16 nCount;
- String aEntry;
-
aLbFormat .SetSelectHdl( LINK( this, ScAutoFormatDlg, SelFmtHdl ) );
aBtnNumFormat.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
aBtnBorder .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
@@ -145,15 +143,11 @@ void ScAutoFormatDlg::Init()
aBtnMore.AddWindow( &aBtnAdjust );
aBtnMore.AddWindow( &aFlFormatting );
- nCount = pFormat->GetCount();
-
- for ( sal_uInt16 i = 0; i < nCount; i++ )
- {
- aEntry = ((*pFormat)[i])->GetName();
- aLbFormat.InsertEntry( aEntry );
- }
+ ScAutoFormat::const_iterator it = pFormat->begin(), itEnd = pFormat->end();
+ for (; it != itEnd; ++it)
+ aLbFormat.InsertEntry(it->second->GetName());
- if ( nCount == 1 )
+ if (pFormat->size() == 1)
aBtnRemove.Disable();
aLbFormat.SelectEntryPos( 0 );
@@ -167,7 +161,7 @@ void ScAutoFormatDlg::Init()
{
aBtnAdd.Disable();
aBtnRemove.Disable();
- bFmtInserted = sal_True;
+ bFmtInserted = true;
}
}
@@ -175,7 +169,7 @@ void ScAutoFormatDlg::Init()
void ScAutoFormatDlg::UpdateChecks()
{
- ScAutoFormatData* pData = (*pFormat)[nIndex];
+ const ScAutoFormatData* pData = pFormat->findByIndex(nIndex);
aBtnNumFormat.Check( pData->GetIncludeValueFormat() );
aBtnBorder .Check( pData->GetIncludeFrame() );
@@ -217,8 +211,8 @@ IMPL_LINK_INLINE_END( ScAutoFormatDlg, DblClkHdl, void *, EMPTYARG )
IMPL_LINK( ScAutoFormatDlg, CheckHdl, Button *, pBtn )
{
- ScAutoFormatData* pData = (*pFormat)[nIndex];
- sal_Bool bCheck = ((CheckBox*)pBtn)->IsChecked();
+ ScAutoFormatData* pData = pFormat->findByIndex(nIndex);
+ bool bCheck = ((CheckBox*)pBtn)->IsChecked();
if ( pBtn == &aBtnNumFormat )
pData->SetIncludeValueFormat( bCheck );
@@ -236,7 +230,7 @@ IMPL_LINK( ScAutoFormatDlg, CheckHdl, Button *, pBtn )
if ( !bCoreDataChanged )
{
aBtnCancel.SetText( aStrClose );
- bCoreDataChanged = sal_True;
+ bCoreDataChanged = true;
}
pWndPreview->NotifyChange( pData );
@@ -253,7 +247,7 @@ IMPL_LINK( ScAutoFormatDlg, AddHdl, void *, EMPTYARG )
String aStrStandard( SfxResId(STR_STANDARD) );
rtl::OUString aFormatName;
ScStringInputDlg* pDlg;
- sal_Bool bOk = false;
+ bool bOk = false;
while ( !bOk )
{
@@ -273,20 +267,21 @@ IMPL_LINK( ScAutoFormatDlg, AddHdl, void *, EMPTYARG )
= new ScAutoFormatData( *pSelFmtData );
pNewData->SetName( aFormatName );
- bFmtInserted = pFormat->Insert( pNewData );
+ bFmtInserted = pFormat->insert(pNewData);
if ( bFmtInserted )
{
- sal_uInt16 nAt = pFormat->IndexOf( pNewData );
-
- aLbFormat.InsertEntry( aFormatName, nAt );
+ ScAutoFormat::const_iterator it = pFormat->find(pNewData);
+ ScAutoFormat::const_iterator itBeg = pFormat->begin();
+ size_t nPos = std::distance(itBeg, it);
+ aLbFormat.InsertEntry(aFormatName, nPos);
aLbFormat.SelectEntry( aFormatName );
aBtnAdd.Disable();
if ( !bCoreDataChanged )
{
aBtnCancel.SetText( aStrClose );
- bCoreDataChanged = sal_True;
+ bCoreDataChanged = true;
}
SelFmtHdl( 0 );
@@ -340,10 +335,12 @@ IMPL_LINK( ScAutoFormatDlg, RemoveHdl, void *, EMPTYARG )
if ( !bCoreDataChanged )
{
aBtnCancel.SetText( aStrClose );
- bCoreDataChanged = sal_True;
+ bCoreDataChanged = true;
}
- pFormat->AtFree( nIndex ); // in der Core loeschen
+ ScAutoFormat::iterator it = pFormat->begin();
+ std::advance(it, nIndex);
+ pFormat->erase(it);
nIndex--;
SelFmtHdl( 0 );
@@ -371,57 +368,57 @@ IMPL_LINK( ScAutoFormatDlg, RenameHdl, void *, EMPTYARG )
HID_SC_REN_AFMT_DLG, HID_SC_REN_AFMT_NAME );
if( pDlg->Execute() == RET_OK )
{
- sal_Bool bFmtRenamed = false;
+ bool bFmtRenamed = false;
pDlg->GetInputString( aFormatName );
- sal_uInt16 n;
if (!aFormatName.isEmpty())
{
- for( n = 0; n < pFormat->GetCount(); ++n )
+ ScAutoFormat::iterator it = pFormat->begin(), itEnd = pFormat->end();
+ for (; it != itEnd; ++it)
{
- aEntry = (*pFormat)[n]->GetName();
+ aEntry = it->second->GetName();
if (aFormatName.equals(aEntry))
break;
}
- if( n >= pFormat->GetCount() )
+ if (it == itEnd)
{
// Format mit dem Namen noch nicht vorhanden, also
// umbenennen
aLbFormat.RemoveEntry(nIndex );
- ScAutoFormatData* p=(*pFormat)[ nIndex ];
+ const ScAutoFormatData* p = pFormat->findByIndex(nIndex);
ScAutoFormatData* pNewData
= new ScAutoFormatData(*p);
- pFormat->AtFree( nIndex );
+ it = pFormat->begin();
+ std::advance(it, nIndex);
+ pFormat->erase(it);
pNewData->SetName( aFormatName );
- pFormat->Insert( pNewData);
-
- sal_uInt16 nCount = pFormat->GetCount();
+ pFormat->insert(pNewData);
aLbFormat.SetUpdateMode(false);
aLbFormat.Clear();
- for ( sal_uInt16 i = 0; i < nCount; i++ )
+ for (it = pFormat->begin(); it != itEnd; ++it)
{
- aEntry = ((*pFormat)[i])->GetName();
+ aEntry = it->second->GetName();
aLbFormat.InsertEntry( aEntry );
}
- aLbFormat.SetUpdateMode( sal_True);
+ aLbFormat.SetUpdateMode(true);
aLbFormat.SelectEntry( aFormatName);
if ( !bCoreDataChanged )
{
aBtnCancel.SetText( aStrClose );
- bCoreDataChanged = sal_True;
+ bCoreDataChanged = true;
}
SelFmtHdl( 0 );
- bOk = sal_True;
- bFmtRenamed = sal_True;
+ bOk = true;
+ bFmtRenamed = true;
}
}
if( !bFmtRenamed )
@@ -433,7 +430,7 @@ IMPL_LINK( ScAutoFormatDlg, RenameHdl, void *, EMPTYARG )
}
}
else
- bOk = sal_True;
+ bOk = true;
delete pDlg;
}
@@ -458,7 +455,8 @@ IMPL_LINK( ScAutoFormatDlg, SelFmtHdl, void *, EMPTYARG )
aBtnRemove.Enable();
}
- pWndPreview->NotifyChange( (*pFormat)[nIndex] );
+ ScAutoFormatData* p = pFormat->findByIndex(nIndex);
+ pWndPreview->NotifyChange(p);
return 0;
}
@@ -467,7 +465,8 @@ IMPL_LINK( ScAutoFormatDlg, SelFmtHdl, void *, EMPTYARG )
rtl::OUString ScAutoFormatDlg::GetCurrFormatName()
{
- return ((*pFormat)[nIndex])->GetName();
+ const ScAutoFormatData* p = pFormat->findByIndex(nIndex);
+ return p ? p->GetName() : rtl::OUString();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/unoobj/afmtuno.cxx b/sc/source/ui/unoobj/afmtuno.cxx
index e29fa2d..125a788 100644
--- a/sc/source/ui/unoobj/afmtuno.cxx
+++ b/sc/source/ui/unoobj/afmtuno.cxx
@@ -164,15 +164,16 @@ SC_SIMPLE_SERVICE_INFO( ScAutoFormatsObj, "ScAutoFormatsObj", SCAUTOFORMATSOBJ_S
//------------------------------------------------------------------------
-bool lcl_FindAutoFormatIndex( const ScAutoFormat& rFormats, const String& rName, sal_uInt16& rOutIndex )
+bool lcl_FindAutoFormatIndex( const ScAutoFormat& rFormats, const rtl::OUString& rName, sal_uInt16& rOutIndex )
{
- sal_uInt16 nCount = rFormats.GetCount();
- for( sal_uInt16 nPos=0; nPos<nCount; nPos++ )
+ ScAutoFormat::const_iterator itBeg = rFormats.begin(), itEnd = rFormats.end();
+ for (ScAutoFormat::const_iterator it = itBeg; it != itEnd; ++it)
{
- ScAutoFormatData* pEntry = rFormats[nPos];
+ const ScAutoFormatData* pEntry = it->second;
const rtl::OUString& aEntryName = pEntry->GetName();
if ( aEntryName.equals(rName) )
{
+ size_t nPos = std::distance(itBeg, it);
rOutIndex = nPos;
return true;
}
@@ -220,7 +221,7 @@ uno::Sequence<rtl::OUString> ScAutoFormatsObj::getSupportedServiceNames_Static()
ScAutoFormatObj* ScAutoFormatsObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
{
- if (nIndex < ScGlobal::GetOrCreateAutoFormat()->GetCount())
+ if (nIndex < ScGlobal::GetOrCreateAutoFormat()->size())
return new ScAutoFormatObj(nIndex);
return NULL; // falscher Index
@@ -260,7 +261,7 @@ void SAL_CALL ScAutoFormatsObj::insertByName( const rtl::OUString& aName, const
ScAutoFormatData* pNew = new ScAutoFormatData();
pNew->SetName( aNameStr );
- if (pFormats->Insert( pNew ))
+ if (pFormats->insert(pNew))
{
//! Notify fuer andere Objekte
pFormats->Save(); // sofort speichern
@@ -274,7 +275,6 @@ void SAL_CALL ScAutoFormatsObj::insertByName( const rtl::OUString& aName, const
}
else
{
- delete pNew;
OSL_FAIL("AutoFormat konnte nicht eingefuegt werden");
throw uno::RuntimeException();
}
@@ -311,10 +311,10 @@ void SAL_CALL ScAutoFormatsObj::removeByName( const rtl::OUString& aName )
String aNameStr(aName);
ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
- sal_uInt16 nIndex;
- if (lcl_FindAutoFormatIndex( *pFormats, aNameStr, nIndex ))
+ ScAutoFormat::iterator it = pFormats->find(aName);
+ if (it != pFormats->end())
{
- pFormats->AtFree( nIndex );
+ pFormats->erase(it);
//! Notify fuer andere Objekte
pFormats->Save(); // sofort speichern
@@ -339,7 +339,7 @@ uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatsObj::createEnumera
sal_Int32 SAL_CALL ScAutoFormatsObj::getCount() throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
- return ScGlobal::GetOrCreateAutoFormat()->GetCount();
+ return ScGlobal::GetOrCreateAutoFormat()->size();
}
uno::Any SAL_CALL ScAutoFormatsObj::getByIndex( sal_Int32 nIndex )
@@ -384,12 +384,12 @@ uno::Sequence<rtl::OUString> SAL_CALL ScAutoFormatsObj::getElementNames()
SolarMutexGuard aGuard;
ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
String aName;
- sal_uInt16 nCount = pFormats->GetCount();
- uno::Sequence<rtl::OUString> aSeq(nCount);
+ uno::Sequence<rtl::OUString> aSeq(pFormats->size());
rtl::OUString* pAry = aSeq.getArray();
- for (sal_uInt16 i=0; i<nCount; i++)
+ ScAutoFormat::const_iterator it = pFormats->begin(), itEnd = pFormats->end();
+ for (size_t i = 0; it != itEnd; ++it, ++i)
{
- pAry[i] = (*pFormats)[i]->GetName();
+ pAry[i] = it->second->GetName();
}
return aSeq;
}
@@ -536,8 +536,8 @@ rtl::OUString SAL_CALL ScAutoFormatObj::getName() throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
- if (IsInserted() && nFormatIndex < pFormats->GetCount())
- return (*pFormats)[nFormatIndex]->GetName();
+ if (IsInserted() && nFormatIndex < pFormats->size())
+ return pFormats->findByIndex(nFormatIndex)->GetName();
return rtl::OUString();
}
@@ -550,26 +550,29 @@ void SAL_CALL ScAutoFormatObj::setName( const rtl::OUString& aNewName )
ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
sal_uInt16 nDummy;
- if (IsInserted() && nFormatIndex < pFormats->GetCount() &&
- !lcl_FindAutoFormatIndex( *pFormats, aNewString, nDummy ))
+ if (IsInserted() && nFormatIndex < pFormats->size() &&
+ !lcl_FindAutoFormatIndex( *pFormats, aNewName, nDummy ))
{
- ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
+ ScAutoFormat::iterator it = pFormats->begin();
+ std::advance(it, nFormatIndex);
+ ScAutoFormatData* pData = it->second;
OSL_ENSURE(pData,"AutoFormat Daten nicht da");
ScAutoFormatData* pNew = new ScAutoFormatData(*pData);
pNew->SetName( aNewString );
- pFormats->AtFree( nFormatIndex );
- if (pFormats->Insert( pNew ))
+ pFormats->erase(it);
+ if (pFormats->insert(pNew))
{
- nFormatIndex = pFormats->IndexOf( pNew ); // ist evtl. anders einsortiert...
+ it = pFormats->find(pNew);
+ ScAutoFormat::iterator itBeg = pFormats->begin();
+ nFormatIndex = std::distance(itBeg, it);
//! Notify fuer andere Objekte
- pFormats->SetSaveLater(sal_True);
+ pFormats->SetSaveLater(true);
}
else
{
- delete pNew;
OSL_FAIL("AutoFormat konnte nicht eingefuegt werden");
nFormatIndex = 0; //! alter Index ist ungueltig
}
@@ -599,9 +602,9 @@ void SAL_CALL ScAutoFormatObj::setPropertyValue(
{
SolarMutexGuard aGuard;
ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
- if (IsInserted() && nFormatIndex < pFormats->GetCount())
+ if (IsInserted() && nFormatIndex < pFormats->size())
{
- ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
+ ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex);
OSL_ENSURE(pData,"AutoFormat Daten nicht da");
String aPropString(aPropertyName);
@@ -634,9 +637,9 @@ uno::Any SAL_CALL ScAutoFormatObj::getPropertyValue( const rtl::OUString& aPrope
uno::Any aAny;
ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
- if (IsInserted() && nFormatIndex < pFormats->GetCount())
+ if (IsInserted() && nFormatIndex < pFormats->size())
{
- ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
+ ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex);
OSL_ENSURE(pData,"AutoFormat Daten nicht da");
sal_Bool bValue;
@@ -707,9 +710,9 @@ void SAL_CALL ScAutoFormatFieldObj::setPropertyValue(
const SfxItemPropertySimpleEntry* pEntry =
aPropSet.getPropertyMap().getByName( aPropertyName );
- if ( pEntry && pEntry->nWID && nFormatIndex < pFormats->GetCount() )
+ if ( pEntry && pEntry->nWID && nFormatIndex < pFormats->size() )
{
- ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
+ ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex);
if ( IsScItemWid( pEntry->nWID ) )
{
@@ -797,9 +800,9 @@ uno::Any SAL_CALL ScAutoFormatFieldObj::getPropertyValue( const rtl::OUString& a
const SfxItemPropertySimpleEntry* pEntry =
aPropSet.getPropertyMap().getByName( aPropertyName );
- if ( pEntry && pEntry->nWID && nFormatIndex < pFormats->GetCount() )
+ if ( pEntry && pEntry->nWID && nFormatIndex < pFormats->size() )
{
- const ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
+ const ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex);
if ( IsScItemWid( pEntry->nWID ) )
{
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 65f2dc4..de344e1 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -5484,17 +5484,13 @@ void SAL_CALL ScCellRangeObj::autoFormat( const rtl::OUString& aName )
if ( pDocSh )
{
ScAutoFormat* pAutoFormat = ScGlobal::GetOrCreateAutoFormat();
- sal_uInt16 nCount = pAutoFormat->GetCount();
- sal_uInt16 nIndex;
- for (nIndex=0; nIndex<nCount; nIndex++)
- {
- if ((*pAutoFormat)[nIndex]->GetName().equals(aName)) //! Case-insensitiv ???
- break;
- }
- if (nIndex<nCount)
+ ScAutoFormat::const_iterator it = pAutoFormat->find(aName);
+ if (it != pAutoFormat->end())
{
+ ScAutoFormat::const_iterator itBeg = pAutoFormat->begin();
+ size_t nIndex = std::distance(itBeg, it);
ScDocFunc aFunc(*pDocSh);
- aFunc.AutoFormat( aRange, NULL, nIndex, sal_True, sal_True );
+ aFunc.AutoFormat(aRange, NULL, nIndex, true, true);
}
else
throw lang::IllegalArgumentException();
diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index a9950c8..f90c7c6 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -817,7 +817,9 @@ void ScCellShell::Execute( SfxRequest& rReq )
{
const SfxStringItem& rNameItem = (const SfxStringItem&)pReqArgs->Get( SID_AUTOFORMAT );
ScAutoFormat* pFormat = ScGlobal::GetOrCreateAutoFormat();
- sal_uInt16 nIndex = pFormat->FindIndexPerName( rNameItem.GetValue() );
+ ScAutoFormat::const_iterator it = pFormat->find(rNameItem.GetValue());
+ ScAutoFormat::const_iterator itBeg = pFormat->begin();
+ size_t nIndex = std::distance(itBeg, it);
pTabViewShell->AutoFormat( nIndex );
More information about the Libreoffice-commits
mailing list