sc/source/ui/dbgui/filtdlg.cxx | 200 ++++++++++++++++++++--------------------- sc/source/ui/inc/filtdlg.hxx | 22 +++- 2 files changed, 117 insertions(+), 105 deletions(-)
New commits: commit 20baf7f8c5f33c4961241b0df2dc93d51fed3a12 Author: Kohei Yoshida <kohei.yosh...@suse.com> Date: Tue Nov 15 12:07:33 2011 -0500 Use size_t and remove static_cast'ing. diff --git a/sc/source/ui/dbgui/filtdlg.cxx b/sc/source/ui/dbgui/filtdlg.cxx index ae0f847..daffd24 100644 --- a/sc/source/ui/dbgui/filtdlg.cxx +++ b/sc/source/ui/dbgui/filtdlg.cxx @@ -340,7 +340,7 @@ void ScFilterDlg::Init( const SfxItemSet& rArgSet ) maValueEdArr[i]->SetText( aValStr ); maValueEdArr[i]->EnableAutocomplete( false ); maValueEdArr[i]->SetModifyHdl( LINK( this, ScFilterDlg, ValModifyHdl ) ); - UpdateValueList( static_cast<sal_uInt16>(i+1) ); + UpdateValueList(i+1); } aScrollBar.SetEndScrollHdl( LINK( this, ScFilterDlg, ScrollHdl ) ); @@ -505,7 +505,7 @@ void ScFilterDlg::FillFieldLists() //---------------------------------------------------------------------------- -void ScFilterDlg::UpdateValueList( sal_uInt16 nList ) +void ScFilterDlg::UpdateValueList( size_t nList ) { if (pDoc && nList > 0 && nList <= QUERY_ENTRY_COUNT) { @@ -527,7 +527,7 @@ void ScFilterDlg::UpdateValueList( sal_uInt16 nList ) EntryList* pList = NULL; if (!maEntryLists.count(nColumn)) { - sal_uInt16 nOffset = GetSliderPos(); + size_t nOffset = GetSliderPos(); SCTAB nTab = nSrcTab; SCROW nFirstRow = theQueryData.nRow1; SCROW nLastRow = theQueryData.nRow2; @@ -590,7 +590,7 @@ void ScFilterDlg::UpdateValueList( sal_uInt16 nList ) UpdateHdrInValueList( nList ); } -void ScFilterDlg::UpdateHdrInValueList( sal_uInt16 nList ) +void ScFilterDlg::UpdateHdrInValueList( size_t nList ) { //! GetText / SetText ?? @@ -643,7 +643,7 @@ void ScFilterDlg::UpdateHdrInValueList( sal_uInt16 nList ) //---------------------------------------------------------------------------- -void ScFilterDlg::ClearValueList( sal_uInt16 nList ) +void ScFilterDlg::ClearValueList( size_t nList ) { if (nList > 0 && nList <= QUERY_ENTRY_COUNT) { @@ -1201,7 +1201,7 @@ void ScFilterDlg::RefreshEditRow( size_t nOffset ) else maConnLbArr[0]->Show(); - for ( sal_uInt16 i=0; i<4; i++ ) + for (size_t i = 0; i < QUERY_ENTRY_COUNT; ++i) { rtl::OUString aValStr; size_t nCondPos = 0; @@ -1296,7 +1296,7 @@ void ScFilterDlg::RefreshEditRow( size_t nOffset ) maFieldLbArr[i]->SelectEntryPos( nFieldSelPos ); maCondLbArr [i]->SelectEntryPos( nCondPos ); maValueEdArr[i]->SetText( aValStr ); - UpdateValueList( static_cast<sal_uInt16>(i+1) ); + UpdateValueList(i+1); } } diff --git a/sc/source/ui/inc/filtdlg.hxx b/sc/source/ui/inc/filtdlg.hxx index 500d01b..693c2d7 100644 --- a/sc/source/ui/inc/filtdlg.hxx +++ b/sc/source/ui/inc/filtdlg.hxx @@ -161,9 +161,9 @@ private: void Init ( const SfxItemSet& rArgSet ); void FillFieldLists (); void FillAreaList (); - void UpdateValueList ( sal_uInt16 nList ); - void UpdateHdrInValueList( sal_uInt16 nList ); - void ClearValueList ( sal_uInt16 nList ); + void UpdateValueList ( size_t nList ); + void UpdateHdrInValueList( size_t nList ); + void ClearValueList ( size_t nList ); size_t GetFieldSelPos ( SCCOL nField ); ScQueryItem* GetOutputItem (); commit 6a4fc2cb91f933f4bc79a546547c00ee17ce5d8b Author: Kohei Yoshida <kohei.yosh...@suse.com> Date: Tue Nov 15 12:02:51 2011 -0500 More cleanups. diff --git a/sc/source/ui/dbgui/filtdlg.cxx b/sc/source/ui/dbgui/filtdlg.cxx index f57a3f0..ae0f847 100644 --- a/sc/source/ui/dbgui/filtdlg.cxx +++ b/sc/source/ui/dbgui/filtdlg.cxx @@ -436,7 +436,7 @@ void ScFilterDlg::SetReference( const ScRange& rRef, ScDocument* pDocP ) { if ( rRef.aStart != rRef.aEnd ) RefInputStart( &aEdCopyArea ); - String aRefStr; + rtl::OUString aRefStr; rRef.aStart.Format( aRefStr, SCA_ABS_3D, pDocP, pDocP->GetAddressConvention() ); aEdCopyArea.SetRefString( aRefStr ); } @@ -474,7 +474,7 @@ void ScFilterDlg::FillFieldLists() if ( pDoc ) { - String aFieldName; + rtl::OUString aFieldName; SCTAB nTab = nSrcTab; SCCOL nFirstCol = theQueryData.nCol1; SCROW nFirstRow = theQueryData.nRow1; @@ -485,11 +485,13 @@ void ScFilterDlg::FillFieldLists() for ( col=nFirstCol; col<=nMaxCol; col++ ) { pDoc->GetString( col, nFirstRow, nTab, aFieldName ); - if ( !aBtnHeader.IsChecked() || (aFieldName.Len() == 0) ) + if (!aBtnHeader.IsChecked() || aFieldName.isEmpty()) { - aFieldName = aStrColumn; - aFieldName += ' '; - aFieldName += ScColToAlpha( col ); + rtl::OUStringBuffer aBuf; + aBuf.append(aStrColumn); + aBuf.append(sal_Unicode(' ')); + aBuf.append(ScColToAlpha(col)); + aFieldName = aBuf.makeStringAndClear(); } aLbField1.InsertEntry( aFieldName, i ); aLbField2.InsertEntry( aFieldName, i ); @@ -510,7 +512,7 @@ void ScFilterDlg::UpdateValueList( sal_uInt16 nList ) ComboBox* pValList = maValueEdArr[nList-1]; sal_uInt16 nFieldSelPos = maFieldLbArr[nList-1]->GetSelectEntryPos(); sal_uInt16 nListPos = 0; - String aCurValue = pValList->GetText(); + rtl::OUString aCurValue = pValList->GetText(); pValList->Clear(); pValList->InsertEntry( aStrNotEmpty, 0 ); @@ -727,7 +729,7 @@ IMPL_LINK( ScFilterDlg, EndDlgHdl, Button*, pBtn ) { if ( pBtn == &aBtnOk ) { - sal_Bool bAreaInputOk = true; + bool bAreaInputOk = true; if ( aBtnCopyResult.IsChecked() ) { @@ -1101,7 +1103,7 @@ IMPL_LINK( ScFilterDlg, ValModifyHdl, ComboBox*, pEd ) size_t nQE = i + nOffset; if ( pEd ) { - String aStrVal = pEd->GetText(); + rtl::OUString aStrVal = pEd->GetText(); ListBox* pLbCond = &aLbCond1; ListBox* pLbField = &aLbField1; if ( pEd == &aEdVal2 ) @@ -1201,9 +1203,9 @@ void ScFilterDlg::RefreshEditRow( size_t nOffset ) for ( sal_uInt16 i=0; i<4; i++ ) { - String aValStr; - sal_uInt16 nCondPos = 0; - sal_uInt16 nFieldSelPos = 0; + rtl::OUString aValStr; + size_t nCondPos = 0; + size_t nFieldSelPos = 0; size_t nQE = i + nOffset; if (maRefreshExceptQuery.size() < nQE + 1) @@ -1212,7 +1214,7 @@ void ScFilterDlg::RefreshEditRow( size_t nOffset ) ScQueryEntry& rEntry = theQueryData.GetEntry( nQE); if ( rEntry.bDoQuery || maRefreshExceptQuery[nQE] ) { - nCondPos = (sal_uInt16)rEntry.eOp; + nCondPos = static_cast<size_t>(rEntry.eOp); if(rEntry.bDoQuery) nFieldSelPos = GetFieldSelPos( static_cast<SCCOL>(rEntry.nField) ); commit 92b3d2a9038e4f79b22b9ec89424290ca2588e79 Author: Kohei Yoshida <kohei.yosh...@suse.com> Date: Tue Nov 15 11:51:50 2011 -0500 Use the range parser instead of local string parsing. diff --git a/sc/source/ui/dbgui/filtdlg.cxx b/sc/source/ui/dbgui/filtdlg.cxx index 44cf29e..f57a3f0 100644 --- a/sc/source/ui/dbgui/filtdlg.cxx +++ b/sc/source/ui/dbgui/filtdlg.cxx @@ -674,14 +674,10 @@ ScQueryItem* ScFilterDlg::GetOutputItem() if ( aBtnCopyResult.IsChecked() ) { - String theCopyStr( aEdCopyArea.GetText() ); - xub_StrLen nColonPos = theCopyStr.Search( ':' ); - - if ( STRING_NOTFOUND != nColonPos ) - theCopyStr.Erase( nColonPos ); - - sal_uInt16 nResult = theCopyPos.Parse( theCopyStr, pDoc, pDoc->GetAddressConvention() ); + ScRange aTempRange; + sal_uInt16 nResult = aTempRange.Parse(aEdCopyArea.GetText(), pDoc, pDoc->GetAddressConvention()); bCopyPosOk = ( SCA_VALID == (nResult & SCA_VALID) ); + theCopyPos = aTempRange.aStart; } if ( aBtnCopyResult.IsChecked() && bCopyPosOk ) commit 129ff6855e5f5a591b9b2e00e829164bc676843c Author: Kohei Yoshida <kohei.yosh...@suse.com> Date: Tue Nov 15 11:47:04 2011 -0500 More cleanups. diff --git a/sc/source/ui/dbgui/filtdlg.cxx b/sc/source/ui/dbgui/filtdlg.cxx index cdbfa80..44cf29e 100644 --- a/sc/source/ui/dbgui/filtdlg.cxx +++ b/sc/source/ui/dbgui/filtdlg.cxx @@ -132,7 +132,6 @@ ScFilterDlg::ScFilterDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, pViewData ( NULL ), pDoc ( NULL ), nSrcTab ( 0 ), - nFieldCount ( 0 ), bRefInputMode ( false ), pTimer ( NULL ) { @@ -302,15 +301,15 @@ void ScFilterDlg::Init( const SfxItemSet& rArgSet ) for (size_t i = 0; i < QUERY_ENTRY_COUNT; ++i) { - String aValStr; - sal_uInt16 nCondPos = 0; - sal_uInt16 nFieldSelPos = 0; + rtl::OUString aValStr; + size_t nCondPos = 0; + size_t nFieldSelPos = 0; ScQueryEntry& rEntry = theQueryData.GetEntry(i); if ( rEntry.bDoQuery ) { const ScQueryEntry::Item& rItem = rEntry.GetQueryItem(); - nCondPos = (sal_uInt16)rEntry.eOp; + nCondPos = static_cast<size_t>(rEntry.eOp); nFieldSelPos = GetFieldSelPos( static_cast<SCCOL>(rEntry.nField) ); if (rEntry.IsQueryByEmpty()) { @@ -498,7 +497,6 @@ void ScFilterDlg::FillFieldLists() aLbField4.InsertEntry( aFieldName, i ); i++; } - nFieldCount = i; } } @@ -600,7 +598,7 @@ void ScFilterDlg::UpdateHdrInValueList( sal_uInt16 nList ) if (nList == 0 || nList > QUERY_ENTRY_COUNT) return; - sal_uInt16 nFieldSelPos = maFieldLbArr[nList-1]->GetSelectEntryPos(); + size_t nFieldSelPos = maFieldLbArr[nList-1]->GetSelectEntryPos(); if (!nFieldSelPos) return; @@ -625,9 +623,9 @@ void ScFilterDlg::UpdateHdrInValueList( sal_uInt16 nList ) return; } - String aHdrStr = pHdrEntry->GetString(); - sal_Bool bWasThere = ( pValList->GetEntry(nListPos) == aHdrStr ); - sal_Bool bInclude = !aBtnHeader.IsChecked(); + rtl::OUString aHdrStr = pHdrEntry->GetString(); + bool bWasThere = aHdrStr.equals(pValList->GetEntry(nListPos)); + bool bInclude = !aBtnHeader.IsChecked(); if (bInclude) // Include entry { @@ -658,10 +656,10 @@ void ScFilterDlg::ClearValueList( sal_uInt16 nList ) //---------------------------------------------------------------------------- -sal_uInt16 ScFilterDlg::GetFieldSelPos( SCCOL nField ) +size_t ScFilterDlg::GetFieldSelPos( SCCOL nField ) { if ( nField >= theQueryData.nCol1 && nField <= theQueryData.nCol2 ) - return static_cast<sal_uInt16>(nField - theQueryData.nCol1 + 1); + return static_cast<size_t>(nField - theQueryData.nCol1 + 1); else return 0; } @@ -672,7 +670,7 @@ ScQueryItem* ScFilterDlg::GetOutputItem() { ScAddress theCopyPos; ScQueryParam theParam( theQueryData ); - sal_Bool bCopyPosOk = false; + bool bCopyPosOk = false; if ( aBtnCopyResult.IsChecked() ) { diff --git a/sc/source/ui/inc/filtdlg.hxx b/sc/source/ui/inc/filtdlg.hxx index 79516e0..500d01b 100644 --- a/sc/source/ui/inc/filtdlg.hxx +++ b/sc/source/ui/inc/filtdlg.hxx @@ -149,7 +149,6 @@ private: std::deque<bool> maHasDates; std::deque<bool> maRefreshExceptQuery; - sal_uInt16 nFieldCount; bool bRefInputMode; EntryListsMap maEntryLists; @@ -165,7 +164,7 @@ private: void UpdateValueList ( sal_uInt16 nList ); void UpdateHdrInValueList( sal_uInt16 nList ); void ClearValueList ( sal_uInt16 nList ); - sal_uInt16 GetFieldSelPos ( SCCOL nField ); + size_t GetFieldSelPos ( SCCOL nField ); ScQueryItem* GetOutputItem (); // Handler: commit be8d1d48ed3adbd07e911e2b9b232be95850126a Author: Kohei Yoshida <kohei.yosh...@suse.com> Date: Tue Nov 15 11:37:59 2011 -0500 Reduce scoping level by early bailout. diff --git a/sc/source/ui/dbgui/filtdlg.cxx b/sc/source/ui/dbgui/filtdlg.cxx index 094cd3a..cdbfa80 100644 --- a/sc/source/ui/dbgui/filtdlg.cxx +++ b/sc/source/ui/dbgui/filtdlg.cxx @@ -594,49 +594,50 @@ void ScFilterDlg::UpdateHdrInValueList( sal_uInt16 nList ) { //! GetText / SetText ?? - if (pDoc && nList > 0 && nList <= QUERY_ENTRY_COUNT) + if (!pDoc) + return; + + if (nList == 0 || nList > QUERY_ENTRY_COUNT) + return; + + sal_uInt16 nFieldSelPos = maFieldLbArr[nList-1]->GetSelectEntryPos(); + if (!nFieldSelPos) + return; + + SCCOL nColumn = theQueryData.nCol1 + static_cast<SCCOL>(nFieldSelPos) - 1; + if (!maEntryLists.count(nColumn)) { - sal_uInt16 nFieldSelPos = maFieldLbArr[nList-1]->GetSelectEntryPos(); - if ( nFieldSelPos ) - { - SCCOL nColumn = theQueryData.nCol1 + static_cast<SCCOL>(nFieldSelPos) - 1; - if (maEntryLists.count(nColumn)) - { - size_t nPos = maEntryLists[nColumn].mnHeaderPos; - if (nPos != INVALID_HEADER_POS) - { - ComboBox* pValList = maValueEdArr[nList-1]; - size_t nListPos = nPos + 2; // for "empty" and "non-empty" + OSL_FAIL("Spalte noch nicht initialisiert"); + return; + } - TypedStrData* pHdrEntry = maEntryLists[nColumn].maList[nPos]; - if ( pHdrEntry ) - { - String aHdrStr = pHdrEntry->GetString(); - sal_Bool bWasThere = ( pValList->GetEntry(nListPos) == aHdrStr ); - sal_Bool bInclude = !aBtnHeader.IsChecked(); - - if (bInclude) // Include entry - { - if (!bWasThere) - pValList->InsertEntry(aHdrStr, nListPos); - } - else // Omit entry - { - if (bWasThere) - pValList->RemoveEntry(nListPos); - } - } - else - { - OSL_FAIL("Eintag in Liste nicht gefunden"); - } - } - } - else - { - OSL_FAIL("Spalte noch nicht initialisiert"); - } - } + size_t nPos = maEntryLists[nColumn].mnHeaderPos; + if (nPos == INVALID_HEADER_POS) + return; + + ComboBox* pValList = maValueEdArr[nList-1]; + size_t nListPos = nPos + 2; // for "empty" and "non-empty" + + TypedStrData* pHdrEntry = maEntryLists[nColumn].maList[nPos]; + if (!pHdrEntry) + { + OSL_FAIL("Eintag in Liste nicht gefunden"); + return; + } + + String aHdrStr = pHdrEntry->GetString(); + sal_Bool bWasThere = ( pValList->GetEntry(nListPos) == aHdrStr ); + sal_Bool bInclude = !aBtnHeader.IsChecked(); + + if (bInclude) // Include entry + { + if (!bWasThere) + pValList->InsertEntry(aHdrStr, nListPos); + } + else // Omit entry + { + if (bWasThere) + pValList->RemoveEntry(nListPos); } } commit 90f9521ba46786e64a36c17ceb2f4424cf53d16f Author: Kohei Yoshida <kohei.yosh...@suse.com> Date: Tue Nov 15 11:33:23 2011 -0500 Store header position this way. diff --git a/sc/source/ui/dbgui/filtdlg.cxx b/sc/source/ui/dbgui/filtdlg.cxx index af87b9f..094cd3a 100644 --- a/sc/source/ui/dbgui/filtdlg.cxx +++ b/sc/source/ui/dbgui/filtdlg.cxx @@ -57,6 +57,8 @@ #undef _FILTDLG_CXX #include <vcl/msgbox.hxx> +#include <limits> + using ::rtl::OUString; using ::rtl::OUStringBuffer; @@ -64,6 +66,11 @@ using ::rtl::OUStringBuffer; ScGlobal::GetRscString(rid) ).Execute() #define QUERY_ENTRY_COUNT 4 +#define INVALID_HEADER_POS std::numeric_limits<size_t>::max() + +ScFilterDlg::EntryList::EntryList() : + maList(128, 128), + mnHeaderPos(INVALID_HEADER_POS) {} ScFilterDlg::ScFilterDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, const SfxItemSet& rArgSet ) @@ -517,7 +524,7 @@ void ScFilterDlg::UpdateValueList( sal_uInt16 nList ) WaitObject aWaiter( this ); // even if only the list box has content SCCOL nColumn = theQueryData.nCol1 + static_cast<SCCOL>(nFieldSelPos) - 1; - TypedScStrCollection* pColl = NULL; + EntryList* pList = NULL; if (!maEntryLists.count(nColumn)) { sal_uInt16 nOffset = GetSliderPos(); @@ -530,20 +537,20 @@ void ScFilterDlg::UpdateValueList( sal_uInt16 nList ) // first without the first line std::pair<EntryListsMap::iterator, bool> r = - maEntryLists.insert(nColumn, new TypedScStrCollection(128, 128)); + maEntryLists.insert(nColumn, new EntryList); if (!r.second) // insertion failed. return; - pColl = r.first->second; - pColl->SetCaseSensitive(aBtnCase.IsChecked()); + pList = r.first->second; + pList->maList.SetCaseSensitive(aBtnCase.IsChecked()); pDoc->GetFilterEntriesArea( nColumn, nFirstRow+1, nLastRow, - nTab, *pColl, maHasDates[nOffset+nList-1] ); + nTab, pList->maList, maHasDates[nOffset+nList-1] ); // Entry for the first line //! Entry (pHdrEntry) doesn't generate collection? - nHeaderPos[nColumn] = USHRT_MAX; + pList->mnHeaderPos = INVALID_HEADER_POS; TypedScStrCollection aHdrColl( 1, 1 ); bool bDummy = false; pDoc->GetFilterEntriesArea( nColumn, nFirstRow, nFirstRow, @@ -552,10 +559,10 @@ void ScFilterDlg::UpdateValueList( sal_uInt16 nList ) if ( pHdrEntry ) { TypedStrData* pNewEntry = new TypedStrData(*pHdrEntry); - if ( pColl->Insert(pNewEntry) ) + if ( pList->maList.Insert(pNewEntry) ) { - nHeaderPos[nColumn] = pColl->IndexOf(pNewEntry); - OSL_ENSURE( nHeaderPos[nColumn] != USHRT_MAX, + pList->mnHeaderPos = pList->maList.IndexOf(pNewEntry); + OSL_ENSURE( pList->mnHeaderPos != INVALID_HEADER_POS, "Header-Eintrag nicht wiedergefunden" ); } else @@ -563,15 +570,15 @@ void ScFilterDlg::UpdateValueList( sal_uInt16 nList ) } } else - pColl = &maEntryLists[nColumn]; + pList = &maEntryLists[nColumn]; - OSL_ASSERT(pColl); - sal_uInt16 nValueCount = pColl->GetCount(); + OSL_ASSERT(pList); + sal_uInt16 nValueCount = pList->maList.GetCount(); if ( nValueCount > 0 ) { for ( sal_uInt16 i=0; i<nValueCount; i++ ) { - pValList->InsertEntry( (*pColl)[i]->GetString(), nListPos ); + pValList->InsertEntry(pList->maList[i]->GetString(), nListPos); nListPos++; } } @@ -595,13 +602,13 @@ void ScFilterDlg::UpdateHdrInValueList( sal_uInt16 nList ) SCCOL nColumn = theQueryData.nCol1 + static_cast<SCCOL>(nFieldSelPos) - 1; if (maEntryLists.count(nColumn)) { - sal_uInt16 nPos = nHeaderPos[nColumn]; - if ( nPos != USHRT_MAX ) + size_t nPos = maEntryLists[nColumn].mnHeaderPos; + if (nPos != INVALID_HEADER_POS) { ComboBox* pValList = maValueEdArr[nList-1]; - sal_uInt16 nListPos = nPos + 2; // for "empty" and "non-empty" + size_t nListPos = nPos + 2; // for "empty" and "non-empty" - TypedStrData* pHdrEntry = maEntryLists[nColumn][nPos]; + TypedStrData* pHdrEntry = maEntryLists[nColumn].maList[nPos]; if ( pHdrEntry ) { String aHdrStr = pHdrEntry->GetString(); diff --git a/sc/source/ui/inc/filtdlg.hxx b/sc/source/ui/inc/filtdlg.hxx index b28797f..79516e0 100644 --- a/sc/source/ui/inc/filtdlg.hxx +++ b/sc/source/ui/inc/filtdlg.hxx @@ -39,7 +39,9 @@ #include <deque> #include <vector> +#include <map> #include <boost/ptr_container/ptr_map.hpp> +#include <boost/noncopyable.hpp> //---------------------------------------------------------------------------- @@ -52,6 +54,13 @@ class TypedScStrCollection; class ScFilterDlg : public ScAnyRefDlg { + struct EntryList : boost::noncopyable + { + TypedScStrCollection maList; + size_t mnHeaderPos; + EntryList(); + }; + typedef boost::ptr_map<SCCOL,EntryList> EntryListsMap; public: ScFilterDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, const SfxItemSet& rArgSet ); @@ -143,9 +152,7 @@ private: sal_uInt16 nFieldCount; bool bRefInputMode; - typedef boost::ptr_map<SCCOL,TypedScStrCollection> EntryListsMap; EntryListsMap maEntryLists; - sal_uInt16 nHeaderPos[MAXCOLCOUNT]; // Hack: RefInput control Timer* pTimer; commit ec3e71d0784a087e0e4fc71e20f7d91819743227 Author: Kohei Yoshida <kohei.yosh...@suse.com> Date: Tue Nov 15 11:17:24 2011 -0500 Use map and avoid MAXCOLCOUNT-sized array. diff --git a/sc/source/ui/dbgui/filtdlg.cxx b/sc/source/ui/dbgui/filtdlg.cxx index aff212b..af87b9f 100644 --- a/sc/source/ui/dbgui/filtdlg.cxx +++ b/sc/source/ui/dbgui/filtdlg.cxx @@ -129,9 +129,6 @@ ScFilterDlg::ScFilterDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, bRefInputMode ( false ), pTimer ( NULL ) { - for (sal_uInt16 i=0; i<=MAXCOL; i++) - pEntryLists[i] = NULL; - aBtnMore.SetMoreText( String(ScResId( SCSTR_MOREBTN_MOREOPTIONS )) ); aBtnMore.SetLessText( String(ScResId( SCSTR_MOREBTN_FEWEROPTIONS )) ); Init( rArgSet ); @@ -208,9 +205,6 @@ ScFilterDlg::ScFilterDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, ScFilterDlg::~ScFilterDlg() { - for (sal_uInt16 i=0; i<=MAXCOL; i++) - delete pEntryLists[i]; - delete pOptionsMgr; delete pOutItem; @@ -523,7 +517,8 @@ void ScFilterDlg::UpdateValueList( sal_uInt16 nList ) WaitObject aWaiter( this ); // even if only the list box has content SCCOL nColumn = theQueryData.nCol1 + static_cast<SCCOL>(nFieldSelPos) - 1; - if (!pEntryLists[nColumn]) + TypedScStrCollection* pColl = NULL; + if (!maEntryLists.count(nColumn)) { sal_uInt16 nOffset = GetSliderPos(); SCTAB nTab = nSrcTab; @@ -534,11 +529,16 @@ void ScFilterDlg::UpdateValueList( sal_uInt16 nList ) maHasDates[nOffset+nList-1] = false; // first without the first line - - pEntryLists[nColumn] = new TypedScStrCollection( 128, 128 ); - pEntryLists[nColumn]->SetCaseSensitive( aBtnCase.IsChecked() ); + std::pair<EntryListsMap::iterator, bool> r = + maEntryLists.insert(nColumn, new TypedScStrCollection(128, 128)); + if (!r.second) + // insertion failed. + return; + + pColl = r.first->second; + pColl->SetCaseSensitive(aBtnCase.IsChecked()); pDoc->GetFilterEntriesArea( nColumn, nFirstRow+1, nLastRow, - nTab, *pEntryLists[nColumn], maHasDates[nOffset+nList-1] ); + nTab, *pColl, maHasDates[nOffset+nList-1] ); // Entry for the first line //! Entry (pHdrEntry) doesn't generate collection? @@ -552,9 +552,9 @@ void ScFilterDlg::UpdateValueList( sal_uInt16 nList ) if ( pHdrEntry ) { TypedStrData* pNewEntry = new TypedStrData(*pHdrEntry); - if ( pEntryLists[nColumn]->Insert( pNewEntry ) ) + if ( pColl->Insert(pNewEntry) ) { - nHeaderPos[nColumn] = pEntryLists[nColumn]->IndexOf( pNewEntry ); + nHeaderPos[nColumn] = pColl->IndexOf(pNewEntry); OSL_ENSURE( nHeaderPos[nColumn] != USHRT_MAX, "Header-Eintrag nicht wiedergefunden" ); } @@ -562,8 +562,10 @@ void ScFilterDlg::UpdateValueList( sal_uInt16 nList ) delete pNewEntry; // was already there } } + else + pColl = &maEntryLists[nColumn]; - TypedScStrCollection* pColl = pEntryLists[nColumn]; + OSL_ASSERT(pColl); sal_uInt16 nValueCount = pColl->GetCount(); if ( nValueCount > 0 ) { @@ -591,7 +593,7 @@ void ScFilterDlg::UpdateHdrInValueList( sal_uInt16 nList ) if ( nFieldSelPos ) { SCCOL nColumn = theQueryData.nCol1 + static_cast<SCCOL>(nFieldSelPos) - 1; - if ( pEntryLists[nColumn] ) + if (maEntryLists.count(nColumn)) { sal_uInt16 nPos = nHeaderPos[nColumn]; if ( nPos != USHRT_MAX ) @@ -599,7 +601,7 @@ void ScFilterDlg::UpdateHdrInValueList( sal_uInt16 nList ) ComboBox* pValList = maValueEdArr[nList-1]; sal_uInt16 nListPos = nPos + 2; // for "empty" and "non-empty" - TypedStrData* pHdrEntry = (*pEntryLists[nColumn])[nPos]; + TypedStrData* pHdrEntry = maEntryLists[nColumn][nPos]; if ( pHdrEntry ) { String aHdrStr = pHdrEntry->GetString(); @@ -1077,9 +1079,7 @@ IMPL_LINK( ScFilterDlg, CheckBoxHdl, CheckBox*, pBox ) if ( pBox == &aBtnCase ) // Complete value list { - for (sal_uInt16 i=0; i<=MAXCOL; i++) - DELETEZ( pEntryLists[i] ); - + maEntryLists.clear(); UpdateValueList( 1 ); // current text is recorded UpdateValueList( 2 ); UpdateValueList( 3 ); diff --git a/sc/source/ui/inc/filtdlg.hxx b/sc/source/ui/inc/filtdlg.hxx index 654f289..b28797f 100644 --- a/sc/source/ui/inc/filtdlg.hxx +++ b/sc/source/ui/inc/filtdlg.hxx @@ -39,6 +39,7 @@ #include <deque> #include <vector> +#include <boost/ptr_container/ptr_map.hpp> //---------------------------------------------------------------------------- @@ -142,7 +143,8 @@ private: sal_uInt16 nFieldCount; bool bRefInputMode; - TypedScStrCollection* pEntryLists[MAXCOLCOUNT]; + typedef boost::ptr_map<SCCOL,TypedScStrCollection> EntryListsMap; + EntryListsMap maEntryLists; sal_uInt16 nHeaderPos[MAXCOLCOUNT]; // Hack: RefInput control _______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits