diff options
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/ui/inc/namemgrtable.hxx | 13 | ||||
-rw-r--r-- | sc/source/ui/namedlg/namemgrtable.cxx | 54 |
2 files changed, 60 insertions, 7 deletions
diff --git a/sc/source/ui/inc/namemgrtable.hxx b/sc/source/ui/inc/namemgrtable.hxx index b95002ee7d53..bbbcab60bd41 100644 --- a/sc/source/ui/inc/namemgrtable.hxx +++ b/sc/source/ui/inc/namemgrtable.hxx @@ -36,6 +36,7 @@ #include <boost/ptr_container/ptr_map.hpp> class ScRangeName; +class ScRangeData; struct ScRangeNameLine { @@ -64,8 +65,17 @@ private: HeaderBar maHeaderBar; rtl::OUString maGlobalString; + // should be const because we should not modify it here + const boost::ptr_map<rtl::OUString, ScRangeName>& mrRangeMap; + // for performance, save which entries already have the formula entry + // otherwise opening the dialog with a lot of range names is extremelly slow because + // we would calculate all formula strings during opening + std::map<SvLBoxEntry*, bool> maCalculatedFormulaEntries; + void GetLine(ScRangeNameLine& aLine, SvLBoxEntry* pEntry); - void Init( const boost::ptr_map<rtl::OUString, ScRangeName>& rRangeMap ); + void Init(); + void CheckForFormulaString(); + const ScRangeData* findRangeData(const ScRangeNameLine& rLine); public: ScRangeManagerTable( Window* pParent, boost::ptr_map<rtl::OUString, ScRangeName>& aTabRangeNames ); @@ -78,6 +88,7 @@ public: bool IsMultiSelection(); std::vector<ScRangeNameLine> GetSelectedEntries(); + DECL_LINK( ScrollHdl, void*); DECL_LINK( HeaderEndDragHdl, void*); }; diff --git a/sc/source/ui/namedlg/namemgrtable.cxx b/sc/source/ui/namedlg/namemgrtable.cxx index d471c7467cc7..de9e3862b65e 100644 --- a/sc/source/ui/namedlg/namemgrtable.cxx +++ b/sc/source/ui/namedlg/namemgrtable.cxx @@ -60,7 +60,8 @@ String createEntryString(const ScRangeNameLine& rLine) ScRangeManagerTable::ScRangeManagerTable( Window* pWindow, boost::ptr_map<rtl::OUString, ScRangeName>& rRangeMap ): SvTabListBox( pWindow, WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP ), maHeaderBar( pWindow, WB_BUTTONSTYLE | WB_BOTTOMBORDER ), - maGlobalString( ScGlobal::GetRscString(STR_GLOBAL_SCOPE)) + maGlobalString( ScGlobal::GetRscString(STR_GLOBAL_SCOPE)), + mrRangeMap( rRangeMap ) { Size aBoxSize( pWindow->GetOutputSizePixel() ); @@ -84,12 +85,16 @@ ScRangeManagerTable::ScRangeManagerTable( Window* pWindow, boost::ptr_map<rtl::O maHeaderBar.SetEndDragHdl( LINK( this, ScRangeManagerTable, HeaderEndDragHdl ) ); + Init(); Show(); maHeaderBar.Show(); SetSelectionMode(MULTIPLE_SELECTION); - Init(rRangeMap); if (GetEntryCount()) + { SetCurEntry(GetEntryOnPos(0)); + CheckForFormulaString(); + } + SetScrolledHdl( LINK( this, ScRangeManagerTable, ScrollHdl ) ); } ScRangeManagerTable::~ScRangeManagerTable() @@ -116,11 +121,11 @@ void ScRangeManagerTable::GetLine(ScRangeNameLine& rLine, SvLBoxEntry* pEntry) rLine.aScope = GetEntryText(pEntry, 2); } -void ScRangeManagerTable::Init(const boost::ptr_map<rtl::OUString, ScRangeName>& rRangeMap) +void ScRangeManagerTable::Init() { Clear(); - for (boost::ptr_map<rtl::OUString, ScRangeName>::const_iterator itr = rRangeMap.begin(); - itr != rRangeMap.end(); ++itr) + for (boost::ptr_map<rtl::OUString, ScRangeName>::const_iterator itr = mrRangeMap.begin(); + itr != mrRangeMap.end(); ++itr) { const ScRangeName* pLocalRangeName = itr->second; ScRangeNameLine aLine; @@ -134,13 +139,44 @@ void ScRangeManagerTable::Init(const boost::ptr_map<rtl::OUString, ScRangeName>& if (!it->second->HasType(RT_DATABASE) && !it->second->HasType(RT_SHARED)) { aLine.aName = it->second->GetName(); - it->second->GetSymbol(aLine.aExpression); addEntry(aLine); } } } } +const ScRangeData* ScRangeManagerTable::findRangeData(const ScRangeNameLine& rLine) +{ + const ScRangeName* pRangeName; + if (rLine.aScope == maGlobalString) + pRangeName = mrRangeMap.find(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_GLOBAL_RANGE_NAME)))->second; + else + pRangeName = mrRangeMap.find(rLine.aScope)->second; + + return pRangeName->findByUpperName(ScGlobal::pCharClass->upper(rLine.aName)); +} + + + +void ScRangeManagerTable::CheckForFormulaString() +{ + for (SvLBoxEntry* pEntry = GetFirstEntryInView(); pEntry ; pEntry = GetNextEntryInView(pEntry)) + { + std::map<SvLBoxEntry*, bool>::const_iterator itr = maCalculatedFormulaEntries.find(pEntry); + if (itr == maCalculatedFormulaEntries.end() || itr->second == false) + { + ScRangeNameLine aLine; + GetLine( aLine, pEntry); + const ScRangeData* pData = findRangeData( aLine ); + rtl::OUString aFormulaString; + pData->GetSymbol(aFormulaString); + SetEntryText(aFormulaString, pEntry, 1); + maCalculatedFormulaEntries.insert( std::pair<SvLBoxEntry*, bool>(pEntry, true) ); + } + + } +} + void ScRangeManagerTable::DeleteSelectedEntries() { if (GetSelectionCount()) @@ -237,5 +273,11 @@ IMPL_LINK( ScRangeManagerTable, HeaderEndDragHdl, void*, EMPTYARG) return 0; } +IMPL_LINK( ScRangeManagerTable, ScrollHdl, void*, EMPTYARG) +{ + CheckForFormulaString(); + return 0; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |