diff options
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/data/documen3.cxx | 26 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh.cxx | 13 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh1.cxx | 1 |
3 files changed, 40 insertions, 0 deletions
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index a018a065b1d2..f7f8687ca4b2 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -208,6 +208,32 @@ void ScDocument::SetRangeName( ScRangeName* pNewRangeName ) pRangeName = pNewRangeName; } +bool ScDocument::IsAddressInRangeName( RangeNameScope eScope, ScAddress& rAddress ) +{ + ScRangeName* pRangeNames; + ScRange aNameRange; + bool bRet = false; + + if (eScope == RangeNameScope::GLOBAL) + pRangeNames= GetRangeName(); + else + pRangeNames= GetRangeName(rAddress.Tab()); + + ScRangeName::iterator itrBegin = pRangeNames->begin(), itrEnd = pRangeNames->end(); + + for (ScRangeName::iterator itr = itrBegin; itr != itrEnd; ++itr) + { + itr->second->IsValidReference(aNameRange); + bRet = aNameRange.In(rAddress); + if (!bRet) + continue; + else + break; + } + + return bRet; +} + bool ScDocument::InsertNewRangeName( const OUString& rName, const ScAddress& rPos, const OUString& rExpr ) { ScRangeName* pGlobalNames = GetRangeName(); diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx index 7157d112f766..cae223dd5cde 100644 --- a/sc/source/ui/view/cellsh.cxx +++ b/sc/source/ui/view/cellsh.cxx @@ -1185,6 +1185,19 @@ void ScCellShell::GetState(SfxItemSet &rSet) } break; + case FID_DEFINE_CURRENT_NAME: + { + ScAddress aCurrentAddress = ScAddress( nPosX, nPosY, nTab ); + + if ( pDoc && + !pDoc->IsAddressInRangeName( RangeNameScope::GLOBAL, aCurrentAddress ) && + !pDoc->IsAddressInRangeName( RangeNameScope::SHEET, aCurrentAddress )) + { + rSet.DisableItem( nWhich ); + } + } + break; + case SID_SPELL_DIALOG: { if ( pDoc && pData && pDoc->IsTabProtected( pData->GetTabNo() ) ) diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index 4f075c981999..9a1e7dc8a3cf 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -1883,6 +1883,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) break; case FID_DEFINE_NAME: + case FID_DEFINE_CURRENT_NAME: if ( pReqArgs ) { const SfxPoolItem* pItem; |