diff --git a/main/sc/inc/rangenam.hxx b/main/sc/inc/rangenam.hxx old mode 100644 new mode 100755 index d452729..dd5aff9 --- a/main/sc/inc/rangenam.hxx +++ b/main/sc/inc/rangenam.hxx @@ -31,6 +31,8 @@ #include "scdllapi.h" #include +#include +#include //------------------------------------------------------------------------ @@ -40,7 +42,6 @@ namespace rtl { class OUStringBuffer; } - //------------------------------------------------------------------------ typedef sal_uInt16 RangeType; @@ -161,6 +162,27 @@ public: SCROW GetMaxRow() const; SC_DLLPUBLIC void SetMaxCol(SCCOL nCol); SCCOL GetMaxCol() const; + + /** Return a string that encodes the given range name and sheet + so that it can be used as argument in a SID_CURRENTCELL slot + call. + */ + static String GetScopedInternalName (const String& rsName, const SCTAB nSheet); + + /** Return a string that encodes the given range name and sheet + so that it can be used as display name. + */ + static String GetScopedDisplayName (const String& rsName, const SCTAB nSheet); + + /** Decode a string that is returned by GetScopedInternalName back + into range name and sheet. + */ + static void ParseScopedInternalName (const String& rsInternalName, String& rsOutName, SCTAB& rOutSheet); + + /** Decode a string that is returned by GetScopedDisplayName back + into range name and sheet. + */ + static void ParseScopedDisplayName (const String& rsDisplayName, String& rsOutName, SCTAB& rOutSheet); }; inline sal_Bool ScRangeData::HasType( RangeType nType ) const @@ -223,6 +245,11 @@ public: sal_uInt16 GetSharedMaxIndex() { return nSharedMaxIndex; } void SetSharedMaxIndex(sal_uInt16 nInd) { nSharedMaxIndex = nInd; } sal_uInt16 GetEntryIndex(); + + /** Return a shared poitner to a vector whose content are the sorted + display names of all valid ranges. + */ + ::boost::shared_ptr > GetSortedRangeDisplayNames (void) const; }; #endif diff --git a/main/sc/source/core/data/documen3.cxx b/main/sc/source/core/data/documen3.cxx index 6d36132..047dae6 100644 --- a/main/sc/source/core/data/documen3.cxx +++ b/main/sc/source/core/data/documen3.cxx @@ -116,7 +116,9 @@ ScRangeData* ScDocument::GetRangeAtBlock( const ScRange& rBlock, String* pName ) { pData = pRangeName->GetRangeAtBlock( rBlock ); if (pData && pName) - *pName = pData->GetName(); + { + *pName = ScRangeData::GetScopedDisplayName(pData->GetName(), pData->GetRangeScope()); + } } return pData; } diff --git a/main/sc/source/core/tool/rangenam.cxx b/main/sc/source/core/tool/rangenam.cxx old mode 100644 new mode 100755 index c1577d6..3b7b4b7 --- a/main/sc/source/core/tool/rangenam.cxx +++ b/main/sc/source/core/tool/rangenam.cxx @@ -49,6 +49,13 @@ using namespace formula; // ScRangeData //======================================================================== +namespace +{ + static const String gsScopedDisplayNameHead = String(" (", 2); + static const String gsScopedDisplayNameTail = String(")", 1); +} + + // Interner ctor fuer das Suchen nach einem Index ScRangeData::ScRangeData( sal_uInt16 n ) @@ -732,6 +739,69 @@ ScRangeData_QsortNameCompare( const void* p1, const void* p2 ) (*(const ScRangeData**)p2)->GetName() ); } +String ScRangeData::GetScopedInternalName (const String& rsName, const SCTAB nSheet) +{ + if (nSheet == MAXTABCOUNT) + return rsName; + else + { + String sScopedName (rsName); + sScopedName.Append('_'); + sScopedName.Append(String::CreateFromInt32(static_cast(nSheet))); + return sScopedName; + } +} + + + + +String ScRangeData::GetScopedDisplayName (const String& rsName, const SCTAB nSheet) +{ + if (nSheet == MAXTABCOUNT) + return rsName; + else + { + String sScopedName (rsName); + sScopedName.Append(gsScopedDisplayNameHead); + sScopedName.Append(String::CreateFromInt32(static_cast(nSheet))); + sScopedName.Append(gsScopedDisplayNameTail); + return sScopedName; + } +} + +void ScRangeData::ParseScopedInternalName (const String& rsInternalName, String& rsOutName, SCTAB& rOutSheet) +{ + rsOutName = rsInternalName; + const xub_StrLen nSeparatorIndex (rsOutName.Search('_')); + rOutSheet = MAXTABCOUNT; + if (nSeparatorIndex != STRING_LEN) + { + rOutSheet = static_cast(rsOutName.Copy(nSeparatorIndex+1).ToInt32()); + rsOutName = rsOutName.Copy(0, nSeparatorIndex); + } +} + +void ScRangeData::ParseScopedDisplayName (const String& rsDisplayName, String& rsOutName, SCTAB& rOutSheet) +{ + rsOutName = rsDisplayName; + rOutSheet = MAXTABCOUNT; + + const xub_StrLen nScopeStart (rsOutName.Search(gsScopedDisplayNameHead)); + if (nScopeStart != STRING_LEN) + { + const xub_StrLen nTailStart (rsOutName.Len()-gsScopedDisplayNameTail.Len()); + if (rsOutName.Search(gsScopedDisplayNameTail, nTailStart) == nTailStart) + { + const String sScopeName (rsOutName.Copy( + nScopeStart+gsScopedDisplayNameHead.Len(), + nTailStart-nScopeStart-gsScopedDisplayNameHead.Len())); + rOutSheet = static_cast(sScopeName.ToInt32()); + rsOutName = rsOutName.Copy(0, nScopeStart); + } + } +} + + //======================================================================== // ScRangeName @@ -939,3 +1009,51 @@ void ScRangeName::UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTabl + +namespace +{ + int compareString (const void*a, const void*b) + { + return reinterpret_cast(a)->CompareTo(*reinterpret_cast(b)); + } +} + +::boost::shared_ptr > ScRangeName::GetSortedRangeDisplayNames (void) const +{ + ::boost::shared_ptr > pResult; + + const sal_uInt16 nCount (GetCount()); + if (nCount > 0) + { + sal_uInt16 nValidCount (0); + ScRange aDummy; + for (sal_uInt16 nIndex=0; nIndexIsValidReference(aDummy)) + ++nValidCount; + } + if (nValidCount > 0) + { + pResult.reset(new std::vector()); + pResult->reserve(nValidCount); + for (sal_uInt16 nReadIndex=0,nWriteIndex=0; nReadIndexIsValidReference(aDummy)) + pResult->push_back( + ScRangeData::GetScopedDisplayName(pData->GetName(), pData->GetRangeScope())); + } + + qsort( + (void*)&pResult->front(), + pResult->size(), + sizeof(String), + compareString); + } + } + + return pResult; +} + + diff --git a/main/sc/source/core/tool/rangeutl.cxx b/main/sc/source/core/tool/rangeutl.cxx old mode 100644 new mode 100755 index a75f714..0e16d83 --- a/main/sc/source/core/tool/rangeutl.cxx +++ b/main/sc/source/core/tool/rangeutl.cxx @@ -286,7 +286,11 @@ sal_Bool ScRangeUtil::MakeRangeFromName ( ScRangeName& rRangeNames = *(pDoc->GetRangeName()); sal_uInt16 nAt = 0; - if ( rRangeNames.SearchName( rName, nAt ) ) + String sName; + SCTAB nSheet; + ScRangeData::ParseScopedInternalName(rName, sName, nSheet); + + if ( rRangeNames.SearchName( sName, nAt, nSheet ) ) { ScRangeData* pData = rRangeNames[nAt]; String aStrArea; diff --git a/main/sc/source/ui/app/inputwin.cxx b/main/sc/source/ui/app/inputwin.cxx old mode 100644 new mode 100755 index 361f891..9206494 --- a/main/sc/source/ui/app/inputwin.cxx +++ b/main/sc/source/ui/app/inputwin.cxx @@ -1470,38 +1470,15 @@ void ScPosWnd::FillRangeNames() // per Hand sortieren, weil Funktionen nicht sortiert werden: ScRangeName* pRangeNames = pDoc->GetRangeName(); - sal_uInt16 nCount = pRangeNames->GetCount(); - if ( nCount > 0 ) - { - sal_uInt16 nValidCount = 0; - ScRange aDummy; - sal_uInt16 i; - for ( i=0; iIsValidReference(aDummy)) - nValidCount++; - } - if ( nValidCount ) - { - ScRangeData** ppSortArray = new ScRangeData* [ nValidCount ]; - sal_uInt16 j; - for ( i=0, j=0; iIsValidReference(aDummy)) - ppSortArray[j++] = pData; - } -#ifndef ICC - qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*), - &ScRangeData_QsortNameCompare ); -#else - qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*), - ICCQsortNameCompare ); -#endif - for ( j=0; jGetName() ); - delete [] ppSortArray; + ::boost::shared_ptr > pSortedRanges ( + pDoc->GetRangeName()->GetSortedRangeDisplayNames()); + if (pSortedRanges) + { + for (::std::vector::const_iterator iName(pSortedRanges->begin()),iEnd(pSortedRanges->end()); + iName!=iEnd; + ++iName) + { + InsertEntry(*iName); } } } @@ -1595,11 +1572,16 @@ ScNameInputType lcl_GetInputType( const String& rText ) SCTAB nNameTab; sal_Int32 nNumeric; + String sRangeName; + SCTAB nSheet; + ScRangeData::ParseScopedDisplayName(rText, sRangeName, nSheet); + const String sScopedInternalName (ScRangeData::GetScopedInternalName(sRangeName, nSheet)); + if ( aRange.Parse( rText, pDoc, eConv ) & SCA_VALID ) eRet = SC_NAME_INPUT_NAMEDRANGE; else if ( aAddress.Parse( rText, pDoc, eConv ) & SCA_VALID ) eRet = SC_NAME_INPUT_CELL; - else if ( aRangeUtil.MakeRangeFromName( rText, pDoc, nTab, aRange, RUTL_NAMES, eConv ) ) + else if ( aRangeUtil.MakeRangeFromName( sScopedInternalName, pDoc, nTab, aRange, RUTL_NAMES, eConv ) ) eRet = SC_NAME_INPUT_NAMEDRANGE; else if ( aRangeUtil.MakeRangeFromName( rText, pDoc, nTab, aRange, RUTL_DBASE, eConv ) ) eRet = SC_NAME_INPUT_DATABASE; @@ -1761,7 +1743,17 @@ void ScPosWnd::DoEnter() { // for all selection types, excecute the SID_CURRENTCELL slot - SfxStringItem aPosItem( SID_CURRENTCELL, aText ); + String sName (aText); + if (eType == SC_NAME_INPUT_NAMEDRANGE) + { + // Convert display name of range to internal + // name. + String sRangeName; + SCTAB nSheet; + ScRangeData::ParseScopedDisplayName(sName, sRangeName, nSheet); + sName = ScRangeData::GetScopedInternalName(sRangeName, nSheet); + } + SfxStringItem aPosItem( SID_CURRENTCELL, sName); SfxBoolItem aUnmarkItem( FN_PARAM_1, sal_True ); // remove existing selection pViewSh->GetViewData()->GetDispatcher().Execute( SID_CURRENTCELL, diff --git a/main/sc/source/ui/navipi/content.cxx b/main/sc/source/ui/navipi/content.cxx old mode 100644 new mode 100755 index 46133bc..f326f85 --- a/main/sc/source/ui/navipi/content.cxx +++ b/main/sc/source/ui/navipi/content.cxx @@ -67,6 +67,7 @@ #include "tabvwsh.hxx" #include "drawview.hxx" #include "clipparam.hxx" +#include "rangeutl.hxx" using namespace com::sun::star; @@ -863,7 +864,6 @@ void ScContentTree::GetTableNames() InsertContent( SC_CONTENT_TABLE, aName ); } } - void ScContentTree::GetAreaNames() { if ( nRootType && nRootType != SC_CONTENT_RANGENAME ) // ausgeblendet ? @@ -873,40 +873,16 @@ void ScContentTree::GetAreaNames() if (!pDoc) return; - ScRangeName* pRangeNames = pDoc->GetRangeName(); - sal_uInt16 nCount = pRangeNames->GetCount(); - if ( nCount > 0 ) - { - sal_uInt16 nValidCount = 0; - ScRange aDummy; - sal_uInt16 i; - for ( i=0; iIsValidReference(aDummy)) - nValidCount++; - } - if ( nValidCount ) - { - ScRangeData** ppSortArray = new ScRangeData* [ nValidCount ]; - sal_uInt16 j; - for ( i=0, j=0; iIsValidReference(aDummy)) - ppSortArray[j++] = pData; - } -#ifndef ICC - qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*), - &ScRangeData_QsortNameCompare ); -#else - qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*), - ICCQsortNameCompare ); -#endif - for ( j=0; jGetName() ); - delete [] ppSortArray; - } + ::boost::shared_ptr > pSortedRanges ( + pDoc->GetRangeName()->GetSortedRangeDisplayNames()); + if (pSortedRanges) + { + for (::std::vector::const_iterator iName(pSortedRanges->begin()),iEnd(pSortedRanges->end()); + iName!=iEnd; + ++iName) + { + InsertContent(SC_CONTENT_RANGENAME, *iName); + } } } diff --git a/main/sc/source/ui/navipi/navipi.cxx b/main/sc/source/ui/navipi/navipi.cxx old mode 100644 new mode 100755 index 9a3ca74..50e7391 --- a/main/sc/source/ui/navipi/navipi.cxx +++ b/main/sc/source/ui/navipi/navipi.cxx @@ -651,6 +651,7 @@ void __EXPORT ScNavigatorDialogWrapper::Resizing( Size& rSize ) #define CTRL_ITEMS 4 + #define REGISTER_SLOT(i,id) \ ppBoundItems[i]=new ScNavigatorControllerItem(id,*this,rBindings); @@ -1064,10 +1065,15 @@ void ScNavigatorDlg::SetCurrentCell( SCCOL nColNo, SCROW nRowNo ) } } -void ScNavigatorDlg::SetCurrentCellStr( const String rName ) +void ScNavigatorDlg::SetCurrentCellStr( const String sScopedDisplayName ) { + String sName; + SCTAB nSheet; + ScRangeData::ParseScopedDisplayName(sScopedDisplayName, sName, nSheet); + const String sScopedInternalName (ScRangeData::GetScopedInternalName(sName, nSheet)); + ppBoundItems[0]->ClearCache(); - SfxStringItem aNameItem( SID_CURRENTCELL, rName ); + SfxStringItem aNameItem( SID_CURRENTCELL, sScopedInternalName ); rBindings.GetDispatcher()->Execute( SID_CURRENTCELL, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD,