summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2011-10-26 15:26:43 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2011-10-26 17:02:00 +0200
commit7fe4fa13c1f82524bd7b1f526adb851c67e1706f (patch)
tree6619d25507c433b8a6a2e03df5883d546bada91e /sc/source
parent5fbdd7bf0994f43ad4783f7ff574e11642321016 (diff)
add uno part for local range names
you can now use e.g. thisComponent.sheets(0).namedRanges
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/ui/docshell/docfunc.cxx13
-rw-r--r--sc/source/ui/inc/docfunc.hxx2
-rw-r--r--sc/source/ui/unoobj/cellsuno.cxx8
-rw-r--r--sc/source/ui/unoobj/docuno.cxx2
-rw-r--r--sc/source/ui/unoobj/nameuno.cxx202
-rw-r--r--sc/source/ui/unoobj/targuno.cxx2
6 files changed, 176 insertions, 53 deletions
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index b2d0536bd50b..f218b8b0ac21 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -4478,7 +4478,7 @@ bool ScDocFunc::UnmergeCells( const ScCellMergeOption& rOption, sal_Bool bRecord
bool ScDocFunc::ModifyRangeNames( const ScRangeName& rNewRanges, SCTAB nTab )
{
- return SetNewRangeNames( new ScRangeName(rNewRanges), nTab );
+ return SetNewRangeNames( new ScRangeName(rNewRanges), true, nTab );
}
void ScDocFunc::ModifyAllRangeNames( const ScRangeName* pGlobal, const ScRangeName::TabNameCopyMap& rTabs )
@@ -4625,7 +4625,7 @@ void ScDocFunc::CreateOneName( ScRangeName& rList,
}
}
-sal_Bool ScDocFunc::CreateNames( const ScRange& rRange, sal_uInt16 nFlags, sal_Bool bApi )
+sal_Bool ScDocFunc::CreateNames( const ScRange& rRange, sal_uInt16 nFlags, sal_Bool bApi, SCTAB aTab )
{
if (!nFlags)
return false; // war nix
@@ -4651,7 +4651,12 @@ sal_Bool ScDocFunc::CreateNames( const ScRange& rRange, sal_uInt16 nFlags, sal_B
if (bValid)
{
ScDocument* pDoc = rDocShell.GetDocument();
- ScRangeName* pNames = pDoc->GetRangeName();
+ ScRangeName* pNames;
+ if (aTab >=0)
+ pNames = pDoc->GetRangeName(nTab);
+ else
+ pNames = pDoc->GetRangeName();
+
if (!pNames)
return false; // soll nicht sein
ScRangeName aNewRanges( *pNames );
@@ -4701,7 +4706,7 @@ sal_Bool ScDocFunc::CreateNames( const ScRange& rRange, sal_uInt16 nFlags, sal_B
if ( bBottom && bRight )
CreateOneName( aNewRanges, nEndCol,nEndRow,nTab, nContX1,nContY1,nContX2,nContY2, bCancel, bApi );
- bDone = ModifyRangeNames( aNewRanges );
+ bDone = ModifyRangeNames( aNewRanges, aTab );
aModificator.SetDocumentModified();
SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx
index 70d83c6e85a7..ec5925afd172 100644
--- a/sc/source/ui/inc/docfunc.hxx
+++ b/sc/source/ui/inc/docfunc.hxx
@@ -196,7 +196,7 @@ public:
*/
void ModifyAllRangeNames( const ScRangeName* pGlobal, const ScRangeName::TabNameCopyMap& rTabs );
- sal_Bool CreateNames( const ScRange& rRange, sal_uInt16 nFlags, sal_Bool bApi );
+ sal_Bool CreateNames( const ScRange& rRange, sal_uInt16 nFlags, sal_Bool bApi, SCTAB nTab = -1 ); // -1 for global range names
sal_Bool InsertNameList( const ScAddress& rStartPos, sal_Bool bApi );
sal_Bool InsertAreaLink( const String& rFile, const String& rFilter,
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 2450ee8a7284..748b3c0b3cc1 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -85,6 +85,7 @@
#include "miscuno.hxx"
#include "convuno.hxx"
#include "srchuno.hxx"
+#include "nameuno.hxx"
#include "targuno.hxx"
#include "tokenuno.hxx"
#include "eventuno.hxx"
@@ -785,6 +786,7 @@ const SfxItemPropertySet* lcl_GetSheetPropertySet()
{MAP_CHAR_LEN(SC_UNONAME_WRITING), ATTR_WRITINGDIR, &getCppuType((sal_Int16*)0), 0, 0 },
{MAP_CHAR_LEN(SC_UNONAME_TABCOLOR), SC_WID_UNO_TABCOLOR, &getCppuType((sal_Int32*)0), 0, 0 },
{MAP_CHAR_LEN(SC_UNO_CODENAME), SC_WID_UNO_CODENAME, &getCppuType(static_cast< const rtl::OUString * >(0)), 0, 0},
+ {MAP_CHAR_LEN(SC_UNO_NAMEDRANGES), SC_WID_UNO_NAMES, &getCppuType((uno::Reference<sheet::XNamedRanges>*)0), 0, 0 },
{0,0,0,0,0,0}
};
static SfxItemPropertySet aSheetPropertySet( aSheetPropertyMap_Impl );
@@ -8526,7 +8528,11 @@ void ScTableSheetObj::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pEn
ScDocument* pDoc = pDocSh->GetDocument();
SCTAB nTab = GetTab_Impl();
- if ( pEntry->nWID == SC_WID_UNO_PAGESTL )
+ if ( pEntry->nWID == SC_WID_UNO_NAMES )
+ {
+ rAny <<= uno::Reference<sheet::XNamedRanges>(new ScLocalNamedRangesObj(pDocSh, this));
+ }
+ else if ( pEntry->nWID == SC_WID_UNO_PAGESTL )
{
rAny <<= rtl::OUString( ScStyleNameConversion::DisplayToProgrammaticName(
pDoc->GetPageStyle( nTab ), SFX_STYLE_FAMILY_PAGE ) );
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index df949d8d7ede..4d4d5880a2a2 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1775,7 +1775,7 @@ uno::Any SAL_CALL ScModelObj::getPropertyValue( const rtl::OUString& aPropertyNa
}
else if ( aString.EqualsAscii( SC_UNO_NAMEDRANGES ) )
{
- aRet <<= uno::Reference<sheet::XNamedRanges>(new ScNamedRangesObj( pDocShell ));
+ aRet <<= uno::Reference<sheet::XNamedRanges>(new ScGlobalNamedRangesObj( pDocShell ));
}
else if ( aString.EqualsAscii( SC_UNO_DATABASERNG ) )
{
diff --git a/sc/source/ui/unoobj/nameuno.cxx b/sc/source/ui/unoobj/nameuno.cxx
index aed65767a839..3726eb788b0f 100644
--- a/sc/source/ui/unoobj/nameuno.cxx
+++ b/sc/source/ui/unoobj/nameuno.cxx
@@ -99,10 +99,11 @@ bool lcl_UserVisibleName(const ScRangeData& rData)
return !rData.HasType(RT_DATABASE) && !rData.HasType(RT_SHARED);
}
-ScNamedRangeObj::ScNamedRangeObj(ScNamedRangesObj* pParent, ScDocShell* pDocSh, const String& rNm) :
+ScNamedRangeObj::ScNamedRangeObj(ScNamedRangesObj* pParent, ScDocShell* pDocSh, const String& rNm, ScTableSheetObj* pSheet) :
mpParent(pParent),
pDocShell( pDocSh ),
- aName( rNm )
+ aName( rNm ),
+ mpSheet( pSheet )
{
pDocShell->GetDocument()->AddUnoObject(*this);
}
@@ -128,7 +129,12 @@ ScRangeData* ScNamedRangeObj::GetRangeData_Impl()
ScRangeData* pRet = NULL;
if (pDocShell)
{
- ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
+ ScRangeName* pNames;
+ SCTAB nTab = GetTab_Impl();
+ if (nTab >= 0)
+ pNames = pDocShell->GetDocument()->GetRangeName(nTab);
+ else
+ pNames = pDocShell->GetDocument()->GetRangeName();
if (pNames)
{
pRet = pNames->findByName(aName);
@@ -139,6 +145,21 @@ ScRangeData* ScNamedRangeObj::GetRangeData_Impl()
return pRet;
}
+SCTAB ScNamedRangeObj::GetTab_Impl()
+{
+ if (mpSheet)
+ {
+ if (!pDocShell)
+ return -2;
+ ScDocument* pDoc = pDocShell->GetDocument();
+ SCTAB nTab;
+ pDoc->GetTable(mpSheet->getName(), nTab);
+ return nTab;
+ }
+ else
+ return -1;//global range name
+}
+
// sheet::XNamedRange
void ScNamedRangeObj::Modify_Impl( const String* pNewName, const ScTokenArray* pNewTokens, const String* pNewContent,
@@ -149,7 +170,12 @@ void ScNamedRangeObj::Modify_Impl( const String* pNewName, const ScTokenArray* p
return;
ScDocument* pDoc = pDocShell->GetDocument();
- ScRangeName* pNames = pDoc->GetRangeName();
+ ScRangeName* pNames;
+ SCTAB nTab = GetTab_Impl();
+ if (nTab >= 0)
+ pNames = pDoc->GetRangeName(nTab);
+ else
+ pNames = pDoc->GetRangeName();
if (!pNames)
return;
@@ -188,7 +214,7 @@ void ScNamedRangeObj::Modify_Impl( const String* pNewName, const ScTokenArray* p
if (pNewRanges->insert(pNew))
{
ScDocFunc aFunc(*pDocShell);
- aFunc.SetNewRangeNames(pNewRanges, mpParent->IsModifyAndBroadcast());
+ aFunc.SetNewRangeNames(pNewRanges, mpParent->IsModifyAndBroadcast(), nTab);
aName = aInsName; //! broadcast?
}
@@ -481,8 +507,8 @@ ScNamedRangeObj* ScNamedRangeObj::getImplementation( const uno::Reference<uno::X
//------------------------------------------------------------------------
ScNamedRangesObj::ScNamedRangesObj(ScDocShell* pDocSh) :
- pDocShell( pDocSh ),
- mbModifyAndBroadcast(true)
+ mbModifyAndBroadcast(true),
+ pDocShell( pDocSh )
{
pDocShell->GetDocument()->AddUnoObject(*this);
}
@@ -511,36 +537,6 @@ bool ScNamedRangesObj::IsModifyAndBroadcast() const
// sheet::XNamedRanges
-ScNamedRangeObj* ScNamedRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
-{
- if (!pDocShell)
- return NULL;
-
- ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
- if (!pNames)
- return NULL;
-
- ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
- sal_uInt16 nPos = 0;
- for (; itr != itrEnd; ++itr)
- {
- if (lcl_UserVisibleName(*itr))
- {
- if (nPos == nIndex)
- return new ScNamedRangeObj(this, pDocShell, itr->GetName());
- }
- ++nPos;
- }
- return NULL;
-}
-
-ScNamedRangeObj* ScNamedRangesObj::GetObjectByName_Impl(const rtl::OUString& aName)
-{
- if ( pDocShell && hasByName(aName) )
- return new ScNamedRangeObj(this, pDocShell, String(aName));
- return NULL;
-}
-
void SAL_CALL ScNamedRangesObj::addNewByName( const rtl::OUString& aName,
const rtl::OUString& aContent, const table::CellAddress& aPosition,
sal_Int32 nUnoType ) throw(uno::RuntimeException)
@@ -558,7 +554,7 @@ void SAL_CALL ScNamedRangesObj::addNewByName( const rtl::OUString& aName,
if (pDocShell)
{
ScDocument* pDoc = pDocShell->GetDocument();
- ScRangeName* pNames = pDoc->GetRangeName();
+ ScRangeName* pNames = GetRangeName_Impl();
if (pNames && !pNames->findByName(aName))
{
ScRangeName* pNewRanges = new ScRangeName( *pNames );
@@ -568,7 +564,7 @@ void SAL_CALL ScNamedRangesObj::addNewByName( const rtl::OUString& aName,
if ( pNewRanges->insert(pNew) )
{
ScDocFunc aFunc(*pDocShell);
- aFunc.SetNewRangeNames(pNewRanges, mbModifyAndBroadcast);
+ aFunc.SetNewRangeNames(pNewRanges, mbModifyAndBroadcast, GetTab_Impl());
bDone = true;
}
else
@@ -606,7 +602,7 @@ void SAL_CALL ScNamedRangesObj::addNewFromTitles( const table::CellRangeAddress&
if (nFlags)
{
ScDocFunc aFunc(*pDocShell);
- aFunc.CreateNames( aRange, nFlags, sal_True );
+ aFunc.CreateNames( aRange, nFlags, sal_True, GetTab_Impl() );
}
}
@@ -617,7 +613,7 @@ void SAL_CALL ScNamedRangesObj::removeByName( const rtl::OUString& aName )
bool bDone = false;
if (pDocShell)
{
- ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
+ ScRangeName* pNames = GetRangeName_Impl();
if (pNames)
{
const ScRangeData* pData = pNames->findByName(aName);
@@ -626,7 +622,7 @@ void SAL_CALL ScNamedRangesObj::removeByName( const rtl::OUString& aName )
ScRangeName* pNewRanges = new ScRangeName(*pNames);
pNewRanges->erase(*pData);
ScDocFunc aFunc(*pDocShell);
- aFunc.SetNewRangeNames( pNewRanges, mbModifyAndBroadcast);
+ aFunc.SetNewRangeNames( pNewRanges, mbModifyAndBroadcast, GetTab_Impl());
bDone = true;
}
}
@@ -665,7 +661,7 @@ sal_Int32 SAL_CALL ScNamedRangesObj::getCount() throw(uno::RuntimeException)
long nRet = 0;
if (pDocShell)
{
- ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
+ ScRangeName* pNames = GetRangeName_Impl();
if (pNames)
{
ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
@@ -754,7 +750,7 @@ uno::Sequence<rtl::OUString> SAL_CALL ScNamedRangesObj::getElementNames()
SolarMutexGuard aGuard;
if (pDocShell)
{
- ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
+ ScRangeName* pNames = GetRangeName_Impl();
if (pNames)
{
long nVisCount = getCount(); // Namen mit lcl_UserVisibleName
@@ -779,7 +775,7 @@ sal_Bool SAL_CALL ScNamedRangesObj::hasByName( const rtl::OUString& aName )
SolarMutexGuard aGuard;
if (pDocShell)
{
- ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
+ ScRangeName* pNames = GetRangeName_Impl();
if (pNames)
{
const ScRangeData* pData = pNames->findByName(aName);
@@ -873,6 +869,122 @@ sal_Int16 ScNamedRangesObj::resetActionLocks() throw(uno::RuntimeException)
//------------------------------------------------------------------------
+ScGlobalNamedRangesObj::ScGlobalNamedRangesObj(ScDocShell* pDocSh)
+ : ScNamedRangesObj(pDocSh)
+{
+
+}
+
+ScGlobalNamedRangesObj::~ScGlobalNamedRangesObj()
+{
+
+}
+
+ScNamedRangeObj* ScGlobalNamedRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
+{
+ if (!pDocShell)
+ return NULL;
+
+ ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
+ if (!pNames)
+ return NULL;
+
+ ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
+ sal_uInt16 nPos = 0;
+ for (; itr != itrEnd; ++itr)
+ {
+ if (lcl_UserVisibleName(*itr))
+ {
+ if (nPos == nIndex)
+ return new ScNamedRangeObj(this, pDocShell, itr->GetName());
+ }
+ ++nPos;
+ }
+ return NULL;
+}
+
+ScNamedRangeObj* ScGlobalNamedRangesObj::GetObjectByName_Impl(const ::rtl::OUString& aName)
+{
+ if ( pDocShell && hasByName(aName) )
+ return new ScNamedRangeObj(this, pDocShell, String(aName));
+ return NULL;
+}
+
+ScRangeName* ScGlobalNamedRangesObj::GetRangeName_Impl()
+{
+ return pDocShell->GetDocument()->GetRangeName();
+}
+
+SCTAB ScGlobalNamedRangesObj::GetTab_Impl()
+{
+ return -1;
+}
+
+//------------------------------------------------------------------------
+
+ScLocalNamedRangesObj::ScLocalNamedRangesObj( ScDocShell* pDocSh, ScTableSheetObj* pSheet )
+ : ScNamedRangesObj(pDocSh),
+ mpSheet(pSheet)
+{
+
+}
+
+ScLocalNamedRangesObj::~ScLocalNamedRangesObj()
+{
+
+}
+
+ScNamedRangeObj* ScLocalNamedRangesObj::GetObjectByName_Impl(const ::rtl::OUString& aName)
+{
+ if ( pDocShell && hasByName( aName ) )
+ return new ScNamedRangeObj( this, pDocShell, String(aName), mpSheet);
+ return NULL;
+
+}
+
+ScNamedRangeObj* ScLocalNamedRangesObj::GetObjectByIndex_Impl( sal_uInt16 nIndex )
+{
+ if (!pDocShell)
+ return NULL;
+
+ rtl::OUString aName = mpSheet->getName();
+ ScDocument* pDoc = pDocShell->GetDocument();
+ SCTAB nTab;
+ pDoc->GetTable( aName, nTab );
+
+ ScRangeName* pNames = pDoc->GetRangeName( nTab );
+ if (!pNames)
+ return NULL;
+
+ ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
+ sal_uInt16 nPos = 0;
+ for (; itr != itrEnd; ++itr)
+ {
+ if (lcl_UserVisibleName(*itr))
+ {
+ if (nPos == nIndex)
+ return new ScNamedRangeObj(this, pDocShell, itr->GetName(), mpSheet);
+ }
+ ++nPos;
+ }
+ return NULL;
+}
+
+ScRangeName* ScLocalNamedRangesObj::GetRangeName_Impl()
+{
+ SCTAB nTab = GetTab_Impl();
+ return pDocShell->GetDocument()->GetRangeName( nTab );
+}
+
+SCTAB ScLocalNamedRangesObj::GetTab_Impl()
+{
+ SCTAB nTab;
+ pDocShell->GetDocument()->GetTable(mpSheet->getName(), nTab);
+ return nTab;
+}
+
+//------------------------------------------------------------------------
+
ScLabelRangeObj::ScLabelRangeObj(ScDocShell* pDocSh, sal_Bool bCol, const ScRange& rR) :
pDocShell( pDocSh ),
bColumn( bCol ),
diff --git a/sc/source/ui/unoobj/targuno.cxx b/sc/source/ui/unoobj/targuno.cxx
index 498f32656046..40de12c025a3 100644
--- a/sc/source/ui/unoobj/targuno.cxx
+++ b/sc/source/ui/unoobj/targuno.cxx
@@ -187,7 +187,7 @@ uno::Reference< container::XNameAccess > SAL_CALL ScLinkTargetTypeObj::getLinks
xCollection.set(new ScTableSheetsObj(pDocShell));
break;
case SC_LINKTARGETTYPE_RANGENAME:
- xCollection.set(new ScNamedRangesObj(pDocShell));
+ xCollection.set(new ScGlobalNamedRangesObj(pDocShell));
break;
case SC_LINKTARGETTYPE_DBAREA:
xCollection.set(new ScDatabaseRangesObj(pDocShell));