incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject svn commit: r1379349 - in /incubator/ooo/trunk/main: offapi/com/sun/star/sheet/ offapi/type_reference/ oox/inc/oox/xls/ oox/source/xls/ sc/inc/ sc/source/core/data/ sc/source/core/tool/ sc/source/filter/excel/ sc/source/filter/xml/ sc/source/ui/inc/ sc...
Date Fri, 31 Aug 2012 08:11:10 GMT
Author: leiw
Date: Fri Aug 31 08:11:09 2012
New Revision: 1379349

URL: http://svn.apache.org/viewvc?rev=1379349&view=rev
Log:
#i120478 Enhancement request: support sheet scoped named ranges in Calc

          Patch by: zhaoshzh (Zhao Shao Zhi)
          Review by: Wang Lei

Modified:
    incubator/ooo/trunk/main/offapi/com/sun/star/sheet/XNamedRange.idl
    incubator/ooo/trunk/main/offapi/com/sun/star/sheet/XNamedRanges.idl
    incubator/ooo/trunk/main/offapi/type_reference/types.rdb
    incubator/ooo/trunk/main/oox/inc/oox/xls/workbookhelper.hxx
    incubator/ooo/trunk/main/oox/source/xls/defnamesbuffer.cxx
    incubator/ooo/trunk/main/oox/source/xls/workbookhelper.cxx
    incubator/ooo/trunk/main/sc/inc/compiler.hxx
    incubator/ooo/trunk/main/sc/inc/nameuno.hxx
    incubator/ooo/trunk/main/sc/inc/rangenam.hxx
    incubator/ooo/trunk/main/sc/source/core/data/documen2.cxx
    incubator/ooo/trunk/main/sc/source/core/tool/compiler.cxx
    incubator/ooo/trunk/main/sc/source/core/tool/rangenam.cxx
    incubator/ooo/trunk/main/sc/source/filter/excel/xename.cxx
    incubator/ooo/trunk/main/sc/source/filter/excel/xiname.cxx
    incubator/ooo/trunk/main/sc/source/filter/xml/xmlbodyi.cxx
    incubator/ooo/trunk/main/sc/source/filter/xml/xmlexprt.cxx
    incubator/ooo/trunk/main/sc/source/filter/xml/xmlexprt.hxx
    incubator/ooo/trunk/main/sc/source/filter/xml/xmlimprt.cxx
    incubator/ooo/trunk/main/sc/source/filter/xml/xmlimprt.hxx
    incubator/ooo/trunk/main/sc/source/filter/xml/xmlnexpi.cxx
    incubator/ooo/trunk/main/sc/source/filter/xml/xmlnexpi.hxx
    incubator/ooo/trunk/main/sc/source/filter/xml/xmltabi.cxx
    incubator/ooo/trunk/main/sc/source/ui/inc/namedlg.hrc
    incubator/ooo/trunk/main/sc/source/ui/inc/namedlg.hxx
    incubator/ooo/trunk/main/sc/source/ui/namedlg/namedlg.cxx
    incubator/ooo/trunk/main/sc/source/ui/src/namedlg.src
    incubator/ooo/trunk/main/sc/source/ui/unoobj/nameuno.cxx

Modified: incubator/ooo/trunk/main/offapi/com/sun/star/sheet/XNamedRange.idl
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/offapi/com/sun/star/sheet/XNamedRange.idl?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/offapi/com/sun/star/sheet/XNamedRange.idl (original)
+++ incubator/ooo/trunk/main/offapi/com/sun/star/sheet/XNamedRange.idl Fri Aug 31 08:11:09 2012
@@ -96,6 +96,10 @@ published interface XNamedRange: com::su
 			as defined in <type>NamedRangeFlag</type>.
 	 */
 	void setType( [in] long nType );
+	
+	string getScopeName();
+	
+	void setScopeAndRangeName( [in] string aScopeName, [in] string aRangeName );
 
 };
 

Modified: incubator/ooo/trunk/main/offapi/com/sun/star/sheet/XNamedRanges.idl
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/offapi/com/sun/star/sheet/XNamedRanges.idl?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/offapi/com/sun/star/sheet/XNamedRanges.idl (original)
+++ incubator/ooo/trunk/main/offapi/com/sun/star/sheet/XNamedRanges.idl Fri Aug 31 08:11:09 2012
@@ -44,6 +44,26 @@
 
 module com {  module sun {  module star {  module sheet {
 
+
+published struct RangeScopeName
+{
+    //-------------------------------------------------------------------------
+
+    /** is the OpCode of the token.
+
+        @see com::sun::star::sheet::XFormulaOpCodeMapper
+     */
+    string ScopeName;
+
+	//-------------------------------------------------------------------------
+
+    /** is additional data in the token, depending on the OpCode.
+
+        @see com::sun::star::sheet::NamedRange::TokenIndex
+        @see com::sun::star::sheet::DatabaseRange::TokenIndex
+     */
+    string RangeName;
+};
 //=============================================================================
 
 /** provides access to the members in a collection of named ranges and to
@@ -127,6 +147,23 @@ published interface XNamedRanges: com::s
 			specifies the top left cell of the output range.
 	 */
 	void outputList( [in] com::sun::star::table::CellAddress aOutputPosition );
+	
+	void addNewByScopeName(
+			[in] string aScopeName,
+			[in] string aRangeName,
+			[in] string aContent,
+			[in] com::sun::star::table::CellAddress aPosition,
+			[in] long nType );
+	
+	void removeByScopeName( [in] string aScopeName, [in] string aRangeName );
+	
+	boolean hasByScopeName( [in] string aScopeName, [in] string aRangeName );
+	
+	any getByScopeName( [in] string aScopeName, [in] string aRangeName )
+			raises( com::sun::star::container::NoSuchElementException, 
+					com::sun::star::lang::WrappedTargetException ); 
+					
+        sequence<RangeScopeName> getElementScopeNames(); 
 
 };
 

Modified: incubator/ooo/trunk/main/offapi/type_reference/types.rdb
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/offapi/type_reference/types.rdb?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/ooo/trunk/main/oox/inc/oox/xls/workbookhelper.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/oox/inc/oox/xls/workbookhelper.hxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/oox/inc/oox/xls/workbookhelper.hxx (original)
+++ incubator/ooo/trunk/main/oox/inc/oox/xls/workbookhelper.hxx Fri Aug 31 08:11:09 2012
@@ -185,6 +185,7 @@ public:
     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XNamedRange >
                         createNamedRangeObject(
                             ::rtl::OUString& orName,
+							sal_Int32 nSheetId = -1, //Add scope for name range
                             sal_Int32 nNameFlags = 0 ) const;
 
     /** Creates and returns a database range on-the-fly in the Calc document.

Modified: incubator/ooo/trunk/main/oox/source/xls/defnamesbuffer.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/oox/source/xls/defnamesbuffer.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/oox/source/xls/defnamesbuffer.cxx (original)
+++ incubator/ooo/trunk/main/oox/source/xls/defnamesbuffer.cxx Fri Aug 31 08:11:09 2012
@@ -502,7 +502,7 @@ void DefinedName::createNameObject()
     }
 
     // create the name and insert it into the document, maCalcName will be changed to the resulting name
-    mxNamedRange = createNamedRangeObject( maCalcName, nNameFlags );
+    mxNamedRange = createNamedRangeObject( maCalcName, maModel.mnSheet, nNameFlags );
     // index of this defined name used in formula token arrays
     PropertySet aPropSet( mxNamedRange );
     aPropSet.getProperty( mnTokenIndex, PROP_TokenIndex );

Modified: incubator/ooo/trunk/main/oox/source/xls/workbookhelper.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/oox/source/xls/workbookhelper.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/oox/source/xls/workbookhelper.cxx (original)
+++ incubator/ooo/trunk/main/oox/source/xls/workbookhelper.cxx Fri Aug 31 08:11:09 2012
@@ -133,7 +133,7 @@ public:
     /** Returns the specified cell or page style from the Calc document. */
     Reference< XStyle > getStyleObject( const OUString& rStyleName, bool bPageStyle ) const;
     /** Creates and returns a defined name on-the-fly in the Calc document. */
-    Reference< XNamedRange > createNamedRangeObject( OUString& orName, sal_Int32 nNameFlags ) const;
+    Reference< XNamedRange > createNamedRangeObject( OUString& orScope, OUString& orName, sal_Int32 nNameFlags ) const;
     /** Creates and returns a database range on-the-fly in the Calc document. */
     Reference< XDatabaseRange > createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const;
     /** Creates and returns a com.sun.star.style.Style object for cells or pages. */
@@ -348,7 +348,7 @@ Reference< XStyle > WorkbookGlobals::get
     return xStyle;
 }
 
-Reference< XNamedRange > WorkbookGlobals::createNamedRangeObject( OUString& orName, sal_Int32 nNameFlags ) const
+Reference< XNamedRange > WorkbookGlobals::createNamedRangeObject( OUString& orScope, OUString& orName, sal_Int32 nNameFlags ) const
 {
     // create the name and insert it into the Calc document
     Reference< XNamedRange > xNamedRange;
@@ -360,8 +360,8 @@ Reference< XNamedRange > WorkbookGlobals
         Reference< XNameAccess > xNameAccess( xNamedRanges, UNO_QUERY_THROW );
         orName = ContainerHelper::getUnusedName( xNameAccess, orName, '_' );
         // create the named range
-        xNamedRanges->addNewByName( orName, OUString(), CellAddress( 0, 0, 0 ), nNameFlags );
-        xNamedRange.set( xNamedRanges->getByName( orName ), UNO_QUERY );
+        xNamedRanges->addNewByScopeName( orScope, orName, OUString(), CellAddress( 0, 0, 0 ), nNameFlags );
+        xNamedRange.set( xNamedRanges->getByScopeName( orScope, orName ), UNO_QUERY );
     }
     catch( Exception& )
     {
@@ -738,9 +738,10 @@ Reference< XStyle > WorkbookHelper::getS
     return mrBookGlob.getStyleObject( rStyleName, bPageStyle );
 }
 
-Reference< XNamedRange > WorkbookHelper::createNamedRangeObject( OUString& orName, sal_Int32 nNameFlags ) const
+Reference< XNamedRange > WorkbookHelper::createNamedRangeObject( OUString& orName, sal_Int32 nSheetId, sal_Int32 nNameFlags ) const
 {
-    return mrBookGlob.createNamedRangeObject( orName, nNameFlags );
+	OUString orScope = nSheetId >= 0? getWorksheets().getCalcSheetName(nSheetId) : OUString();
+    return mrBookGlob.createNamedRangeObject( orScope, orName, nNameFlags );
 }
 
 Reference< XDatabaseRange > WorkbookHelper::createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const

Modified: incubator/ooo/trunk/main/sc/inc/compiler.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/inc/compiler.hxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/inc/compiler.hxx (original)
+++ incubator/ooo/trunk/main/sc/inc/compiler.hxx Fri Aug 31 08:11:09 2012
@@ -443,7 +443,8 @@ public:
 
     ScRangeData* UpdateInsertTab(SCTAB nTable, sal_Bool bIsName );
     ScRangeData* UpdateDeleteTab(SCTAB nTable, sal_Bool bIsMove, sal_Bool bIsName, sal_Bool& bCompile);
-    ScRangeData* UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, sal_Bool bIsName );
+    // the last parameter is true only when copying a sheet, to update the range name's address
+    ScRangeData* UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, bool bIsName, bool bOnlyUpdateOwnTab = false );
 
     sal_Bool HasModifiedRange();
 

Modified: incubator/ooo/trunk/main/sc/inc/nameuno.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/inc/nameuno.hxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/inc/nameuno.hxx (original)
+++ incubator/ooo/trunk/main/sc/inc/nameuno.hxx Fri Aug 31 08:11:09 2012
@@ -44,6 +44,8 @@
 #include <cppuhelper/implbase5.hxx>
 #include <cppuhelper/implbase6.hxx>
 
+#include <global.hxx> //for EMPTY_STRING
+
 class ScDocShell;
 class ScRangeData;
 class ScTokenArray;
@@ -61,16 +63,17 @@ class ScNamedRangeObj : public ::cppu::W
 private:
 	ScDocShell*				pDocShell;
 	String					aName;
+	String					aScopeName;
 
 private:
 	ScRangeData*			GetRangeData_Impl();
 	void					Modify_Impl( const String* pNewName,
                                         const ScTokenArray* pNewTokens, const String* pNewContent,
 										const ScAddress* pNewPos, const sal_uInt16* pNewType,
-                                        const formula::FormulaGrammar::Grammar eGrammar );
+                                        const formula::FormulaGrammar::Grammar eGrammar, const String* pNewScopeName = NULL );
 
 public:
-							ScNamedRangeObj(ScDocShell* pDocSh, const String& rNm);
+							ScNamedRangeObj(ScDocShell* pDocSh, const String& rNm, const String& rScopeName = EMPTY_STRING);
 	virtual					~ScNamedRangeObj();
 
 	virtual void			Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
@@ -86,6 +89,8 @@ public:
 									throw(::com::sun::star::uno::RuntimeException);
 	virtual sal_Int32		SAL_CALL getType() throw(::com::sun::star::uno::RuntimeException);
 	virtual void SAL_CALL	setType( sal_Int32 nType ) throw(::com::sun::star::uno::RuntimeException);
+	virtual ::rtl::OUString SAL_CALL getScopeName() throw(::com::sun::star::uno::RuntimeException);
+	virtual void SAL_CALL	setScopeAndRangeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName ) throw(::com::sun::star::uno::RuntimeException);
 
                             // XFormulaTokens
     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken > SAL_CALL getTokens()
@@ -181,6 +186,14 @@ private:
 
 	ScNamedRangeObj*		GetObjectByIndex_Impl(sal_uInt16 nIndex);
 	ScNamedRangeObj*		GetObjectByName_Impl(const ::rtl::OUString& aName);
+	ScNamedRangeObj*		GetObjectByScopeName_Impl(const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName);
+
+	void ImplAddNewByScopeAndName(SCTAB aScope,const ::rtl::OUString& aRangeName, const ::rtl::OUString& aContent,
+								const ::com::sun::star::table::CellAddress& aPosition, sal_Int32 nType)
+								throw(::com::sun::star::uno::RuntimeException);
+
+	void ImplRemoveByScopeAndName(SCTAB aScope,const ::rtl::OUString& aRangeName)
+								throw(::com::sun::star::uno::RuntimeException);
 
 protected:
     /** called from the XActionLockable interface methods on initial locking */
@@ -199,13 +212,27 @@ public:
 	virtual void SAL_CALL	addNewByName( const ::rtl::OUString& aName, const ::rtl::OUString& aContent,
 								const ::com::sun::star::table::CellAddress& aPosition, sal_Int32 nType )
 									throw(::com::sun::star::uno::RuntimeException);
+
+	virtual void SAL_CALL	addNewByScopeName( const ::rtl::OUString& aScopeName,const ::rtl::OUString& aRangeName, const ::rtl::OUString& aContent,
+								const ::com::sun::star::table::CellAddress& aPosition, sal_Int32 nType )
+									throw(::com::sun::star::uno::RuntimeException);
 	virtual void SAL_CALL	addNewFromTitles( const ::com::sun::star::table::CellRangeAddress& aSource,
 								::com::sun::star::sheet::Border aBorder )
 									throw(::com::sun::star::uno::RuntimeException);
 	virtual void SAL_CALL	removeByName( const ::rtl::OUString& aName )
 								throw(::com::sun::star::uno::RuntimeException);
+	virtual void SAL_CALL	removeByScopeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName )
+								throw(::com::sun::star::uno::RuntimeException);
 	virtual void SAL_CALL	outputList( const ::com::sun::star::table::CellAddress& aOutputPosition )
 								throw(::com::sun::star::uno::RuntimeException);
+	virtual sal_Bool SAL_CALL hasByScopeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName )
+								throw(::com::sun::star::uno::RuntimeException);
+	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::RangeScopeName > SAL_CALL getElementScopeNames()
+								throw(::com::sun::star::uno::RuntimeException);
+	virtual ::com::sun::star::uno::Any SAL_CALL getByScopeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName )
+								throw(::com::sun::star::container::NoSuchElementException,
+									::com::sun::star::lang::WrappedTargetException,
+									::com::sun::star::uno::RuntimeException);
 
 							// XNameAccess
 	virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )

Modified: incubator/ooo/trunk/main/sc/inc/rangenam.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/inc/rangenam.hxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/inc/rangenam.hxx (original)
+++ incubator/ooo/trunk/main/sc/inc/rangenam.hxx Fri Aug 31 08:11:09 2012
@@ -77,6 +77,7 @@ private:
     // application's default.
     SCROW           mnMaxRow;
     SCCOL           mnMaxCol;
+	SCTAB		aRangeNameScope;		// table index reference as range name scope. 0 -  sheet1, 1- sheet2.  MAXTABCOUNT - Global
 
 	friend class ScRangeName;
 	ScRangeData( sal_uInt16 nIndex );
@@ -110,6 +111,9 @@ public:
 	void			GetName( String& rName ) const	{ rName = aName; }
 	const String&	GetName( void ) const			{ return aName; }
 	const String&   GetUpperName( void ) const      { return aUpperName; }
+	SC_DLLPUBLIC  bool			SetRangeScope( SCTAB Scope );	// 0 - sheet1, 1 - sheet2, MAXTABCOUNT - global
+	SCTAB			GetRangeScope() const { return aRangeNameScope; }
+        String	GetScopeSheetName( void ) const;
 	ScAddress 		GetPos() const					{ return aPos; }
 	// Der Index muss eindeutig sein. Ist er 0, wird ein neuer Index vergeben
 	void            SetIndex( sal_uInt16 nInd )         { nIndex = nInd; }
@@ -200,9 +204,14 @@ public:
 //UNUSED2009-05 ScRangeData*			GetRangeAtCursor( const ScAddress&, sal_Bool bStartOnly ) const;
 	SC_DLLPUBLIC ScRangeData*			GetRangeAtBlock( const ScRange& ) const;
 
-	SC_DLLPUBLIC sal_Bool					SearchName( const String& rName, sal_uInt16& rPos ) const;
+	SC_DLLPUBLIC bool					SearchName( const String& rName, sal_uInt16& rPos, SCTAB Scope=MAXTABCOUNT) const;
                             // SearchNameUpper must be called with an upper-case search string
-	sal_Bool					SearchNameUpper( const String& rUpperName, sal_uInt16& rPos ) const;
+	bool					SearchNameUpper( const String& rUpperName, sal_uInt16& rPos, SCTAB Scope=MAXTABCOUNT ) const;
+	/* added by  for scope support */
+	bool				HasRangeinSheetScope( SCTAB Scope );
+	bool				RemoveRangeinScope(SCTAB Scope);
+	bool				CopyRangeinScope(SCTAB oldScope, SCTAB newScope);
+	/* end add */
 	void					UpdateReference(UpdateRefMode eUpdateRefMode,
 								const ScRange& rRange,
 								SCsCOL nDx, SCsROW nDy, SCsTAB nDz );

Modified: incubator/ooo/trunk/main/sc/source/core/data/documen2.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/core/data/documen2.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/core/data/documen2.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/core/data/documen2.cxx Fri Aug 31 08:11:09 2012
@@ -834,6 +834,7 @@ sal_Bool ScDocument::CopyTab( SCTAB nOld
 		if (nNewPos == nMaxTableNumber)
 		{
 			pTab[nMaxTableNumber] = new ScTable(this, nMaxTableNumber, aName);
+			pRangeName->UpdateTabRef(nNewPos, 4, nOldPos);//. 4 - copy table 
 			++nMaxTableNumber;
 		}
 		else
@@ -845,7 +846,7 @@ sal_Bool ScDocument::CopyTab( SCTAB nOld
 				ScRange aRange( 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB );
 				xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 );
 				xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 );
-				pRangeName->UpdateTabRef(nNewPos, 1);
+				pRangeName->UpdateTabRef(nNewPos, 4, nOldPos);//  4 - copy table
 				pDBCollection->UpdateReference(
 									URM_INSDEL, 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB, 0,0,1 );
 				if (pDPCollection)

Modified: incubator/ooo/trunk/main/sc/source/core/tool/compiler.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/core/tool/compiler.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/core/tool/compiler.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/core/tool/compiler.cxx Fri Aug 31 08:11:09 2012
@@ -2964,6 +2964,14 @@ sal_Bool ScCompiler::IsNamedRange( const
 
     sal_uInt16 n;
     ScRangeName* pRangeName = pDoc->GetRangeName();
+    if (pRangeName->SearchNameUpper( rUpperName, n, aPos.Tab() ) )
+    {
+        ScRangeData* pData = (*pRangeName)[n];
+        ScRawToken aToken;
+        aToken.SetName( pData->GetIndex() );
+        pRawToken = aToken.Clone();
+        return sal_True;
+    }
     if (pRangeName->SearchNameUpper( rUpperName, n ) )
     {
         ScRangeData* pData = (*pRangeName)[n];
@@ -4847,7 +4855,7 @@ ScRangeData* ScCompiler::UpdateDeleteTab
 
 // aPos.Tab() must be already adjusted!
 ScRangeData* ScCompiler::UpdateMoveTab( SCTAB nOldTab, SCTAB nNewTab,
-        sal_Bool bIsName )
+       bool bIsName, bool bOnlyUpdateOwnTab /*= FALSE*/)
 {
     ScRangeData* pRangeData = NULL;
     SCsTAB nTab;
@@ -4904,7 +4912,7 @@ ScRangeData* ScCompiler::UpdateMoveTab( 
                     nTab = rRef1.nTab;
                 if ( nTab == nOldTab )
                     rRef1.nTab = nNewTab;
-                else if ( nStart <= nTab && nTab <= nEnd )
+                else if ( nStart <= nTab && nTab <= nEnd && !bOnlyUpdateOwnTab)
                     rRef1.nTab = nTab + nDir;
                 rRef1.nRelTab = rRef1.nTab - nPosTab;
             }
@@ -4921,7 +4929,7 @@ ScRangeData* ScCompiler::UpdateMoveTab( 
                         nTab = rRef2.nTab;
                     if ( nTab == nOldTab )
                         rRef2.nTab = nNewTab;
-                    else if ( nStart <= nTab && nTab <= nEnd )
+                    else if ( nStart <= nTab && nTab <= nEnd && !bOnlyUpdateOwnTab)
                         rRef2.nTab = nTab + nDir;
                     rRef2.nRelTab = rRef2.nTab - nPosTab;
                 }

Modified: incubator/ooo/trunk/main/sc/source/core/tool/rangenam.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/core/tool/rangenam.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/core/tool/rangenam.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/core/tool/rangenam.cxx Fri Aug 31 08:11:09 2012
@@ -52,7 +52,7 @@ using namespace formula;
 // Interner ctor fuer das Suchen nach einem Index
 
 ScRangeData::ScRangeData( sal_uInt16 n )
-           : pCode( NULL ), nIndex( n ), bModified( sal_False ), mnMaxRow(-1), mnMaxCol(-1)
+           : pCode( NULL ), nIndex( n ), bModified( sal_False ), mnMaxRow(-1), mnMaxCol(-1), aRangeNameScope( MAXTABCOUNT )
 {}
 
 ScRangeData::ScRangeData( ScDocument* pDok,
@@ -70,7 +70,8 @@ ScRangeData::ScRangeData( ScDocument* pD
 				nIndex		( 0 ),
                 bModified	( sal_False ),
                 mnMaxRow    (-1),
-                mnMaxCol    (-1)
+                mnMaxCol    (-1),
+				aRangeNameScope( MAXTABCOUNT )
 {
 	if (rSymbol.Len() > 0)
 	{
@@ -118,7 +119,8 @@ ScRangeData::ScRangeData( ScDocument* pD
 				nIndex		( 0 ),
                 bModified	( sal_False ),
                 mnMaxRow    (-1),
-                mnMaxCol    (-1)
+                mnMaxCol    (-1),
+				aRangeNameScope( MAXTABCOUNT )
 {
 	if( !pCode->GetCodeError() )
 	{
@@ -155,7 +157,8 @@ ScRangeData::ScRangeData( ScDocument* pD
 				nIndex		( 0 ),
                 bModified	( sal_False ),
                 mnMaxRow    (-1),
-                mnMaxCol    (-1)
+                mnMaxCol    (-1),
+				aRangeNameScope( MAXTABCOUNT )
 {
 	ScSingleRefData aRefData;
 	aRefData.InitAddress( rTarget );
@@ -179,7 +182,8 @@ ScRangeData::ScRangeData(const ScRangeDa
 	nIndex   	(rScRangeData.nIndex),
     bModified	(rScRangeData.bModified),
     mnMaxRow    (rScRangeData.mnMaxRow),
-    mnMaxCol    (rScRangeData.mnMaxCol)
+    mnMaxCol    (rScRangeData.mnMaxCol),
+	aRangeNameScope (rScRangeData.aRangeNameScope)
 {}
 
 ScRangeData::~ScRangeData()
@@ -340,7 +344,7 @@ sal_Bool ScRangeData::operator== (const 
 	if ( nIndex	!= rData.nIndex	||
 		 aName	!= rData.aName	||
 		 aPos	!= rData.aPos	||
-		 eType	!= rData.eType     ) return sal_False;
+		 eType	!= rData.eType   || aRangeNameScope  != rData.aRangeNameScope  ) return sal_False;
 
 	sal_uInt16 nLen = pCode->GetLen();
 	if ( nLen != rData.pCode->GetLen() ) return sal_False;
@@ -408,6 +412,7 @@ sal_Bool ScRangeData::IsValidReference( 
     return sal_False;
 }
 
+/* modification to update named range scope */
 void ScRangeData::UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable)
 {
 	pCode->Reset();
@@ -420,16 +425,40 @@ void ScRangeData::UpdateTabRef(SCTAB nOl
 		switch (nFlag)
 		{
 			case 1:										// einfache InsertTab (doc.cxx)
-				pRangeData = aComp.UpdateInsertTab(nOldTable, sal_True );	// und CopyTab (doc2.cxx)
+			case 4:	
+			       pRangeData = aComp.UpdateInsertTab(nOldTable, true );	// und CopyTab (doc2.cxx)
+				if ( (aRangeNameScope != MAXTABCOUNT) && ( aRangeNameScope >= nOldTable) && ( aRangeNameScope != MAXTAB ) )
+					aRangeNameScope ++;
 				break;
 			case 2:										// einfaches delete (doc.cxx)
-				pRangeData = aComp.UpdateDeleteTab(nOldTable, sal_False, sal_True, bChanged);
+				pRangeData = aComp.UpdateDeleteTab(nOldTable, false, true, bChanged);
+				if  ( aRangeNameScope != MAXTABCOUNT && aRangeNameScope > nOldTable )
+                                    aRangeNameScope --;
 				break;
 			case 3:										// move (doc2.cxx)
 			{
-				pRangeData = aComp.UpdateMoveTab(nOldTable, nNewTable, sal_True );
+				pRangeData = aComp.UpdateMoveTab(nOldTable, nNewTable, true );
+				if ( aRangeNameScope != MAXTABCOUNT )
+				{
+					if ( aRangeNameScope == nOldTable )
+						aRangeNameScope = nNewTable;
+					else if ( (aRangeNameScope > nOldTable) && (aRangeNameScope <= nNewTable) )
+						aRangeNameScope--;
+					else if ( (aRangeNameScope >= nNewTable) && (aRangeNameScope < nOldTable) )
+						aRangeNameScope++;
+				}
 			}
-				break;
+			break;
+			case 5:										
+			{
+                                //when copying a sheet, this will be invoked to update the new name range's address in the new sheet 
+                                //only need to update the address if the address's tab same as the range scope. because if they are different, the address's tab have been updated in ScRangeName::UpdateTabRef()  
+                                //for example, in sheet5(scope is sheet5), there are two name range, one address is sheet5, the other is sheet4, if copy sheet5 to sheet1
+                                //only need to change the first one's address to sheet1
+				pRangeData = aComp.UpdateMoveTab(nOldTable, nNewTable, true , true);
+				aRangeNameScope = nNewTable;
+			}
+			break;
 			default:
 			{
 				DBG_ERROR("ScRangeName::UpdateTabRef: Unknown Flag");
@@ -536,6 +565,33 @@ SCCOL ScRangeData::GetMaxCol() const
     return mnMaxCol >= 0 ? mnMaxCol : MAXCOL;
 }
 
+/* MAXTABCOUNT - Global, 0 - sheet1, 1 - sheet2, ...		*/
+/*	MAXTABCOUNT -- Global				*/
+/*	return value: FALSE -- set fail		 	*/
+/*			      TRUE  -- set successfully	*/
+bool ScRangeData::SetRangeScope( SCTAB Scope )
+{
+	 if ( Scope <= MAXTABCOUNT && Scope >=0 )
+	 {
+		aRangeNameScope = Scope;
+	        return true;
+	 }
+         return false;
+	
+}
+
+ String ScRangeData::GetScopeSheetName() const
+{
+	if ( aRangeNameScope != MAXTABCOUNT )
+	{
+            String aTableName;
+            pDoc->GetName( aRangeNameScope, aTableName );
+            return aTableName;
+	}
+        return EMPTY_STRING;
+}
+/* end add */
+
 
 sal_uInt16 ScRangeData::GetErrCode()
 {
@@ -700,29 +756,86 @@ short ScRangeName::Compare(ScDataObject*
 	return (short) i1 - (short) i2;
 }
 
-sal_Bool ScRangeName::SearchNameUpper( const String& rUpperName, sal_uInt16& rIndex ) const
+/* added  for scope support */
+bool ScRangeName::HasRangeinSheetScope(SCTAB Scope)
+{
+    for (sal_uInt16 i = 0; i < nCount; i++)
+        if  (((*this)[i])->GetRangeScope() == Scope) 
+            return true;
+
+    return false;
+}
+/* if Scope is global, no range will be removed */
+/* if no range is removed, return value is false */
+bool ScRangeName::RemoveRangeinScope(SCTAB Scope)
+{
+     bool bRemoved = false;
+	
+     if ( Scope == MAXTABCOUNT )
+         return bRemoved;
+
+     sal_uInt16 i = 0;
+     while (i < nCount)
+     {
+          if  (((*this)[i])->GetRangeScope() == Scope) 
+          {
+               Free( (*this)[i] );
+               bRemoved = true;		
+          }
+          else
+               i++;
+     }
+
+     return bRemoved;
+}
+/* it's designed for "Copy Sheet" action. So no name conflict check when copy range to new scope */
+/* if the old scope or the new scope is global, no range will be copied */
+/* if no range is copied, the return value is false */
+bool ScRangeName::CopyRangeinScope(SCTAB oldScope, SCTAB newScope)
+{
+       bool bCopied = false;
+
+       if ( (oldScope == MAXTABCOUNT)||(newScope ==MAXTABCOUNT) )
+           return bCopied;
+
+       sal_uInt16 originalCount = nCount;
+       for ( sal_uInt16 i = 0; i < originalCount; i++)
+           if ( ((*this)[i])->GetRangeScope() == oldScope) 
+           {
+                 ScRangeData * aCopiedRange = (ScRangeData *)(*this)[i]->Clone();
+                 aCopiedRange->UpdateTabRef(oldScope, 5 , newScope);
+                 aCopiedRange->SetIndex(GetEntryIndex());
+                 Insert( aCopiedRange );
+                 bCopied = true;		
+           }
+
+       return bCopied;
+}
+/* end add */
+bool ScRangeName::SearchNameUpper( const String& rUpperName, sal_uInt16& rIndex, SCTAB Scope ) const
 {
     // SearchNameUpper must be called with an upper-case search string
 
     sal_uInt16 i = 0;
     while (i < nCount)
     {
-        if ( ((*this)[i])->GetUpperName() == rUpperName )
+        if ( (((*this)[i])->GetUpperName() == rUpperName) 
+			&& (((*this)[i])->GetRangeScope() == Scope ))
         {
             rIndex = i;
-            return sal_True;
+            return true;
         }
         i++;
     }
-    return sal_False;
+    return false;
 }
 
-sal_Bool ScRangeName::SearchName( const String& rName, sal_uInt16& rIndex ) const
+bool ScRangeName::SearchName( const String& rName, sal_uInt16& rIndex, SCTAB Scope ) const
 {
     if ( nCount > 0 )
-        return SearchNameUpper( ScGlobal::pCharClass->upper( rName ), rIndex );
+        return SearchNameUpper( ScGlobal::pCharClass->upper( rName ), rIndex, Scope );
     else
-        return sal_False;
+        return false;
 }
 
 void ScRangeName::UpdateReference(	UpdateRefMode eUpdateRefMode,
@@ -811,10 +924,18 @@ ScRangeData* ScRangeName::GetRangeAtBloc
 
 void ScRangeName::UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable)
 {
-	for (sal_uInt16 i=0; i<nCount; i++)
-		((ScRangeData*)pItems[i])->UpdateTabRef(nOldTable, nFlag, nNewTable);
-}
+       if (nFlag == 2)
+           RemoveRangeinScope( nOldTable );
 
+       for (sal_uInt16 i=0; i<nCount; i++)
+            ((ScRangeData*)pItems[i])->UpdateTabRef(nOldTable, nFlag, nNewTable);
+
+       if (nFlag ==4)
+       {
+            SCTAB copyScope = nOldTable > nNewTable ? nNewTable : nNewTable+1;
+            CopyRangeinScope( copyScope, nOldTable);
+       }
+}
 
 
 

Modified: incubator/ooo/trunk/main/sc/source/filter/excel/xename.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/excel/xename.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/excel/xename.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/excel/xename.cxx Fri Aug 31 08:11:09 2012
@@ -87,6 +87,9 @@ public:
     inline bool         IsGlobal() const { return mnXclTab == EXC_NAME_GLOBAL; }
     /** Returns the Calc sheet of a local defined name. */
     inline SCTAB        GetScTab() const { return mnScTab; }
+	// 
+	/** Set name range flag value */
+	void				SetScTab( sal_uInt16 nXclTab ) { mnXclTab = nXclTab; }
 
     /** Returns true, if this defined name is volatile. */
     bool                IsVolatile() const;
@@ -548,6 +551,8 @@ sal_uInt16 XclExpNameManagerImpl::Create
     size_t nOldListSize = maNameList.GetSize();
     XclExpNameRef xName( new XclExpName( GetRoot(), rName ) );
     sal_uInt16 nNameIdx = Append( xName );
+	// 
+    xName->SetScTab( rRangeData.GetRangeScope() == MAXTABCOUNT ? EXC_NAME_GLOBAL : rRangeData.GetRangeScope()+1 );
     // store the index of the NAME record in the lookup map
     maNameMap[ rRangeData.GetIndex() ] = nNameIdx;
 

Modified: incubator/ooo/trunk/main/sc/source/filter/excel/xiname.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/excel/xiname.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/excel/xiname.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/excel/xiname.cxx Fri Aug 31 08:11:09 2012
@@ -140,8 +140,8 @@ XclImpName::XclImpName( XclImpStream& rS
     String aOrigName( maScName );
     sal_Int32 nCounter = 0;
     sal_uInt16 nDummy;
-    while( rRangeNames.SearchName( maScName, nDummy ) )
-        maScName.Assign( aOrigName ).Append( ' ' ).Append( String::CreateFromInt32( ++nCounter ) );
+    //while( rRangeNames.SearchName( maScName, nDummy ) )
+        //maScName.Assign( aOrigName ).Append( ' ' ).Append( String::CreateFromInt32( ++nCounter ) );
 
     // 3) *** convert the name definition formula *** -------------------------
 
@@ -212,6 +212,7 @@ XclImpName::XclImpName( XclImpStream& rS
     {
         // create the Calc name data
         ScRangeData* pData = new ScRangeData( GetDocPtr(), maScName, *pTokArr, ScAddress(), nNameType );
+	 pData->SetRangeScope(nXclTab == EXC_NAME_GLOBAL ?  MAXTABCOUNT : mnScTab);
         pData->GuessPosition();             // calculate base position for relative refs
         pData->SetIndex( nXclNameIdx );     // used as unique identifier in formulas
         rRangeNames.Insert( pData );        // takes ownership of pData

Modified: incubator/ooo/trunk/main/sc/source/filter/xml/xmlbodyi.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/xml/xmlbodyi.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/xml/xmlbodyi.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/xml/xmlbodyi.cxx Fri Aug 31 08:11:09 2012
@@ -192,6 +192,7 @@ SvXMLImportContext *ScXMLBodyContext::Cr
 	case XML_TOK_BODY_NAMED_EXPRESSIONS:
 		pContext = new ScXMLNamedExpressionsContext ( GetScImport(), nPrefix, rLocalName,
 														xAttrList );
+		static_cast<ScXMLNamedExpressionsContext*>(pContext)->SetScope( MAXTABCOUNT );//workbookname
 		break;
 	case XML_TOK_BODY_DATABASE_RANGES:
 		pContext = new ScXMLDatabaseRangesContext ( GetScImport(), nPrefix, rLocalName,

Modified: incubator/ooo/trunk/main/sc/source/filter/xml/xmlexprt.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/xml/xmlexprt.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/xml/xmlexprt.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/xml/xmlexprt.cxx Fri Aug 31 08:11:09 2012
@@ -1833,16 +1833,19 @@ void ScXMLExport::_ExportContent()
                         }
                         else
                             ExportFormatRanges(0, 0, pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
-                        CloseRow(pSharedData->GetLastRow(nTable));
-                        nEqualCells = 0;
-                    }
-                }
-            }
-            IncrementProgressBar(sal_False);
+
+						CloseRow(pSharedData->GetLastRow(nTable));
+						WriteNamedExpressions(xSpreadDoc, nTable);
+						nEqualCells = 0;
+					}
+				}
+			}
+			
+			IncrementProgressBar(sal_False);
         }
     }
     WriteExternalRefCaches();
-    WriteNamedExpressions(xSpreadDoc);
+    WriteNamedExpressions(xSpreadDoc, MAXTABCOUNT);
     aExportDatabaseRanges.WriteDatabaseRanges(xSpreadDoc);
     ScXMLExportDataPilot aExportDataPilot(*this);
     aExportDataPilot.WriteDataPilots(xSpreadDoc);
@@ -2955,7 +2958,7 @@ void ScXMLExport::WriteCell(ScMyCell& aC
 				{
                     const formula::FormulaGrammar::Grammar eGrammar = pDoc->GetStorageGrammar();
                     sal_uInt16 nNamespacePrefix = (eGrammar == formula::FormulaGrammar::GRAM_ODFF ? XML_NAMESPACE_OF : XML_NAMESPACE_OOOC);
-					pFormulaCell->GetFormula(sFormula, eGrammar);
+					pFormulaCell->GetFormula(sFormula, eGrammar);//ange scope name support
 					rtl::OUString sOUFormula(sFormula.makeStringAndClear());
 					if (!bIsMatrix)
                     {
@@ -3886,7 +3889,7 @@ void ScXMLExport::WriteLabelRanges( cons
 	}
 }
 
-void ScXMLExport::WriteNamedExpressions(const com::sun::star::uno::Reference <com::sun::star::sheet::XSpreadsheetDocument>& xSpreadDoc)
+void ScXMLExport::WriteNamedExpressions(const com::sun::star::uno::Reference <com::sun::star::sheet::XSpreadsheetDocument>& xSpreadDoc, sal_Int16 nWhichTable)
 {
 	uno::Reference <beans::XPropertySet> xPropertySet (xSpreadDoc, uno::UNO_QUERY);
 	if (xPropertySet.is())
@@ -3895,7 +3898,7 @@ void ScXMLExport::WriteNamedExpressions(
 		CheckAttrList();
 		if (xNamedRanges.is())
 		{
-			uno::Sequence <rtl::OUString> aRangesNames(xNamedRanges->getElementNames());
+			uno::Sequence <sheet::RangeScopeName> aRangesNames(xNamedRanges->getElementScopeNames());//modified 20091211, range scope name support
 			sal_Int32 nNamedRangesCount(aRangesNames.getLength());
 			if (nNamedRangesCount > 0)
 			{
@@ -3906,8 +3909,21 @@ void ScXMLExport::WriteNamedExpressions(
 					for (sal_Int32 i = 0; i < nNamedRangesCount; ++i)
 					{
 						CheckAttrList();
-						rtl::OUString sNamedRange(aRangesNames[i]);
-                        uno::Reference <sheet::XNamedRange> xNamedRange(xNamedRanges->getByName(sNamedRange), uno::UNO_QUERY);
+						//range scope name support -start
+						rtl::OUString sNamedRange(aRangesNames[i].RangeName);
+						rtl::OUString sRangeScope(aRangesNames[i].ScopeName);
+						SCTAB nScopeNumber = MAXTABCOUNT;
+						String sScopeStr(sRangeScope);
+						if(sScopeStr !=EMPTY_STRING)
+						{
+							pDoc->GetTable(sScopeStr,nScopeNumber);
+							if( nWhichTable != nScopeNumber || nScopeNumber ==MAXTABCOUNT)
+								continue;
+						}
+						else if( nWhichTable !=MAXTABCOUNT)
+							continue;
+                        uno::Reference <sheet::XNamedRange> xNamedRange(xNamedRanges->getByScopeName(sRangeScope,sNamedRange), uno::UNO_QUERY);
+						//range scope name support 
 						if (xNamedRange.is())
 						{
 							uno::Reference <container::XNamed> xNamed (xNamedRange, uno::UNO_QUERY);
@@ -3915,8 +3931,9 @@ void ScXMLExport::WriteNamedExpressions(
 							if (xNamed.is() && xCellRangeReferrer.is())
 							{
 								rtl::OUString sOUName(xNamed->getName());
+							
 								AddAttribute(sAttrName, sOUName);
-
+								
 								OUString sOUBaseCellAddress;
 								ScRangeStringConverter::GetStringFromAddress( sOUBaseCellAddress,
 									xNamedRange->getReferencePosition(), pDoc, FormulaGrammar::CONV_OOO, ' ', sal_False, SCA_ABS_3D );
@@ -3924,7 +3941,15 @@ void ScXMLExport::WriteNamedExpressions(
 
 								sal_uInt16 nRangeIndex;
 								String sName(sOUName);
-								pNamedRanges->SearchName(sName, nRangeIndex);
+								//range scope name support -start
+								SCTAB nScopeName = MAXTABCOUNT;
+								String sScopeName(sRangeScope);
+								if(sScopeName !=EMPTY_STRING)
+								{
+									pDoc->GetTable(sScopeName,nScopeName);
+								}
+								pNamedRanges->SearchName(sName, nRangeIndex,nScopeName);
+								//range scope name support - end
 								ScRangeData* pNamedRange((*pNamedRanges)[nRangeIndex]); //should get directly and not with ScDocument
 								String sContent;
 								pNamedRange->GetSymbol(sContent, pDoc->GetStorageGrammar());

Modified: incubator/ooo/trunk/main/sc/source/filter/xml/xmlexprt.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/xml/xmlexprt.hxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/xml/xmlexprt.hxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/xml/xmlexprt.hxx Fri Aug 31 08:11:09 2012
@@ -201,7 +201,7 @@ class ScXMLExport : public SvXMLExport
 	void WriteScenario();	// core implementation
 	void WriteTheLabelRanges(const com::sun::star::uno::Reference< com::sun::star::sheet::XSpreadsheetDocument >& xSpreadDoc);
 	void WriteLabelRanges( const com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess >& xRangesIAccess, sal_Bool bColumn );
-	void WriteNamedExpressions(const com::sun::star::uno::Reference <com::sun::star::sheet::XSpreadsheetDocument>& xSpreadDoc);
+	void WriteNamedExpressions(const com::sun::star::uno::Reference <com::sun::star::sheet::XSpreadsheetDocument>& xSpreadDoc, sal_Int16 nWhichTable);
     void WriteExternalRefCaches();
 	void WriteConsolidation();	// core implementation
 

Modified: incubator/ooo/trunk/main/sc/source/filter/xml/xmlimprt.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/xml/xmlimprt.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/xml/xmlimprt.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/xml/xmlimprt.cxx Fri Aug 31 08:11:09 2012
@@ -640,6 +640,7 @@ const SvXMLTokenMap& ScXMLImport::GetTab
             { XML_NAMESPACE_TABLE,	XML_TABLE_ROW,					XML_TOK_TABLE_ROW			},
             { XML_NAMESPACE_TABLE,	XML_TABLE_SOURCE,				XML_TOK_TABLE_SOURCE		},
             { XML_NAMESPACE_TABLE,	XML_SCENARIO,					XML_TOK_TABLE_SCENARIO		},
+            { XML_NAMESPACE_TABLE,	XML_NAMED_EXPRESSIONS,			XML_TOK_TABLE_NAMED_EXPRESSIONS			},
             { XML_NAMESPACE_TABLE,	XML_SHAPES, 					XML_TOK_TABLE_SHAPES		},
             { XML_NAMESPACE_OFFICE,	XML_FORMS,						XML_TOK_TABLE_FORMS			},
             { XML_NAMESPACE_OFFICE, XML_EVENT_LISTENERS,            XML_TOK_TABLE_EVENT_LISTENERS },
@@ -2747,7 +2748,10 @@ void ScXMLImport::SetNamedRanges()
                     {
                         try
                         {
-                            xNamedRanges->addNewByName((*aItr)->sName, sTempContent, aCellAddress, GetRangeType((*aItr)->sRangeType));
+                            //xNamedRanges->addNewByName((*aItr)->sName, sTempContent, aCellAddress, GetRangeType((*aItr)->sRangeType));//String::CreateFromInt32( (*aItr)->nNameScope)
+							String sTabName;
+							GetDocument()->GetName( (*aItr)->nNameScope, sTabName);
+							xNamedRanges->addNewByScopeName( sTabName, (*aItr)->sName, (*aItr)->sContent, aCellAddress, GetRangeType((*aItr)->sRangeType) );							
                         }
                         catch( uno::RuntimeException& )
                         {
@@ -2786,7 +2790,12 @@ void ScXMLImport::SetNamedRanges()
                     if (ScRangeStringConverter::GetAddressFromString(
                         aCellAddress, (*aItr)->sBaseCellAddress, GetDocument(), FormulaGrammar::CONV_OOO, nOffset ))
                     {
-                        uno::Reference <sheet::XNamedRange> xNamedRange(xNamedRanges->getByName((*aItr)->sName), uno::UNO_QUERY);
+						String sTableName;
+						GetDocument()->GetName( (*aItr)->nNameScope,  sTableName );
+						rtl::OUString sRangeScope( sTableName);
+                        //uno::Reference <sheet::XNamedRange> xNamedRange(xNamedRanges->getByName((*aItr)->sName), uno::UNO_QUERY);
+						//getByScopeName
+						uno::Reference <sheet::XNamedRange> xNamedRange(xNamedRanges->getByScopeName( sRangeScope,(*aItr)->sName), uno::UNO_QUERY);
                         if (xNamedRange.is())
                         {
                             LockSolarMutex();

Modified: incubator/ooo/trunk/main/sc/source/filter/xml/xmlimprt.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/xml/xmlimprt.hxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/xml/xmlimprt.hxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/xml/xmlimprt.hxx Fri Aug 31 08:11:09 2012
@@ -171,6 +171,7 @@ enum ScXMLTableTokens
 	XML_TOK_TABLE_SCENARIO,
 	XML_TOK_TABLE_SHAPES,
     XML_TOK_TABLE_FORMS,
+    XML_TOK_TABLE_NAMED_EXPRESSIONS,
     XML_TOK_TABLE_EVENT_LISTENERS,
     XML_TOK_TABLE_EVENT_LISTENERS_EXT
 };
@@ -614,6 +615,7 @@ struct ScMyNamedExpression
     rtl::OUString      sRangeType;
     formula::FormulaGrammar::Grammar eGrammar;
     sal_Bool           bIsExpression;
+   SCTAB nNameScope;
 };
 
 typedef std::list<const ScMyNamedExpression*> ScMyNamedExpressions;

Modified: incubator/ooo/trunk/main/sc/source/filter/xml/xmlnexpi.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/xml/xmlnexpi.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/xml/xmlnexpi.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/xml/xmlnexpi.cxx Fri Aug 31 08:11:09 2012
@@ -49,7 +49,8 @@ ScXMLNamedExpressionsContext::ScXMLNamed
 									  const ::rtl::OUString& rLName,
 									  const ::com::sun::star::uno::Reference<
                                       ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) :
-	SvXMLImportContext( rImport, nPrfx, rLName )
+	SvXMLImportContext( rImport, nPrfx, rLName ),
+	nScopeOfNameRange( MAXTABCOUNT )	//aRangeNameScope( MAXTABCOUNT )
 {
 /*	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
 	for( sal_Int16 i=0; i < nAttrCount; ++i )
@@ -86,13 +87,13 @@ SvXMLImportContext *ScXMLNamedExpression
 	{
 	case XML_TOK_NAMED_EXPRESSIONS_NAMED_RANGE:
 		pContext = new ScXMLNamedRangeContext( GetScImport(), nPrefix,
-													  rLName, xAttrList//,
+													  rLName, xAttrList,nScopeOfNameRange//,
 													  //this
 													  );
 		break;
 	case XML_TOK_NAMED_EXPRESSIONS_NAMED_EXPRESSION:
 		pContext = new ScXMLNamedExpressionContext( GetScImport(), nPrefix,
-													  rLName, xAttrList//,
+													  rLName, xAttrList, nScopeOfNameRange//,
 													  //this
 													  );
 		break;
@@ -114,10 +115,11 @@ ScXMLNamedRangeContext::ScXMLNamedRangeC
 									  sal_uInt16 nPrfx,
 									  const ::rtl::OUString& rLName,
 									  const ::com::sun::star::uno::Reference<
-									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
+									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList, SCTAB nScopeOfNameRange) :
 	SvXMLImportContext( rImport, nPrfx, rLName )
 {
 	ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression);
+	pNamedExpression->nNameScope = nScopeOfNameRange;
     // A simple table:cell-range-address is not a formula expression, stored
     // without [] brackets but with dot, .A1
     pNamedExpression->eGrammar = formula::FormulaGrammar::mergeToGrammar(
@@ -185,10 +187,11 @@ ScXMLNamedExpressionContext::ScXMLNamedE
 									  sal_uInt16 nPrfx,
 									  const ::rtl::OUString& rLName,
 									  const ::com::sun::star::uno::Reference<
-									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
+									  ::com::sun::star::xml::sax::XAttributeList>& xAttrList, SCTAB nScopeOfNameRange) :
 	SvXMLImportContext( rImport, nPrfx, rLName )
 {
 	ScMyNamedExpression* pNamedExpression(new ScMyNamedExpression);
+	pNamedExpression->nNameScope = nScopeOfNameRange;
 	sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
 	const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetNamedExpressionAttrTokenMap());
 	for( sal_Int16 i=0; i < nAttrCount; ++i )

Modified: incubator/ooo/trunk/main/sc/source/filter/xml/xmlnexpi.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/xml/xmlnexpi.hxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/xml/xmlnexpi.hxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/xml/xmlnexpi.hxx Fri Aug 31 08:11:09 2012
@@ -25,6 +25,7 @@
 
 #include <xmloff/xmlictxt.hxx>
 #include <xmloff/xmlimp.hxx>
+#include "address.hxx"
 
 class ScXMLImport;
 
@@ -32,7 +33,7 @@ class ScXMLNamedExpressionsContext : pub
 {
 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
-
+	SCTAB nScopeOfNameRange;
 public:
 
 	ScXMLNamedExpressionsContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
@@ -48,6 +49,9 @@ public:
 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
 
 	virtual void EndElement();
+	void SetScope( SCTAB n ){ nScopeOfNameRange = n;}
+	SCTAB GetScope(){ return nScopeOfNameRange;}
+		
 };
 
 class ScXMLNamedRangeContext : public SvXMLImportContext
@@ -60,7 +64,7 @@ public:
 	ScXMLNamedRangeContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
 						const ::rtl::OUString& rLName,
 						const ::com::sun::star::uno::Reference<
-										::com::sun::star::xml::sax::XAttributeList>& xAttrList);
+										::com::sun::star::xml::sax::XAttributeList>& xAttrList,SCTAB nScopeOfNameRange);
 
 	virtual ~ScXMLNamedRangeContext();
 
@@ -82,7 +86,7 @@ public:
 	ScXMLNamedExpressionContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
 						const ::rtl::OUString& rLName,
 						const ::com::sun::star::uno::Reference<
-										::com::sun::star::xml::sax::XAttributeList>& xAttrList);
+										::com::sun::star::xml::sax::XAttributeList>& xAttrList,SCTAB nScopeOfNameRange);
 
 	virtual ~ScXMLNamedExpressionContext();
 

Modified: incubator/ooo/trunk/main/sc/source/filter/xml/xmltabi.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/filter/xml/xmltabi.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/filter/xml/xmltabi.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/filter/xml/xmltabi.cxx Fri Aug 31 08:11:09 2012
@@ -44,6 +44,7 @@
 #include "rangeutl.hxx"
 #include "externalrefmgr.hxx"
 #include "sheetdata.hxx"
+#include "xmlnexpi.hxx"
 
 #include <xmloff/xmltkmap.hxx>
 #include <xmloff/nmspmap.hxx>
@@ -324,6 +325,13 @@ SvXMLImportContext *ScXMLTableContext::C
 			pContext = GetScImport().GetFormImport()->createOfficeFormsContext( GetScImport(), nPrefix, rLName );
 		}
 		break;
+	case XML_TOK_TABLE_NAMED_EXPRESSIONS:
+		{
+			SCTAB nCurrentSheet = static_cast<SCTAB>(GetScImport().GetTables().GetCurrentSheet());
+			pContext = new ScXMLNamedExpressionsContext ( GetScImport(), nPrefix, rLName, xAttrList );//worksheetname
+			static_cast<ScXMLNamedExpressionsContext*>(pContext)->SetScope( nCurrentSheet );
+		}
+		break;
     case XML_TOK_TABLE_EVENT_LISTENERS:
     case XML_TOK_TABLE_EVENT_LISTENERS_EXT:
         {

Modified: incubator/ooo/trunk/main/sc/source/ui/inc/namedlg.hrc
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/ui/inc/namedlg.hrc?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/ui/inc/namedlg.hrc (original)
+++ incubator/ooo/trunk/main/sc/source/ui/inc/namedlg.hrc Fri Aug 31 08:11:09 2012
@@ -33,6 +33,7 @@
 #define FL_NAME         11
 #define ED_NAME			12
 #define FL_ASSIGN       13
+#define LB_NAMES        14
 #define ED_ASSIGN		15
 #define RB_ASSIGN		16
 //

Modified: incubator/ooo/trunk/main/sc/source/ui/inc/namedlg.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/ui/inc/namedlg.hxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/ui/inc/namedlg.hxx (original)
+++ incubator/ooo/trunk/main/sc/source/ui/inc/namedlg.hxx Fri Aug 31 08:11:09 2012
@@ -34,6 +34,8 @@
 #include <vcl/group.hxx>
 #endif
 #include <vcl/fixed.hxx>
+#include <vcl/lstbox.hxx>
+#include <vcl/edit.hxx>
 #include "rangenam.hxx"
 #include "anyrefdg.hxx"
 
@@ -47,7 +49,9 @@ class ScNameDlg : public ScAnyRefDlg
 {
 private:
     FixedLine       aFlName;
-	ComboBox		aEdName;
+	//ComboBox		aEdName;
+	Edit                       aEdName;
+	ListBox     aLBNames;
 
     FixedLine       aFlAssign;
 	formula::RefEdit		aEdAssign;
@@ -76,6 +80,7 @@ private:
 	ScRangeName		aLocalRangeName;
 	const ScAddress	theCursorPos;
 	Selection		theCurSel;
+	SCTAB           aSelectedRangeScope;
 
 #ifdef _NAMEDLG_CXX
 private:

Modified: incubator/ooo/trunk/main/sc/source/ui/namedlg/namedlg.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/ui/namedlg/namedlg.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/ui/namedlg/namedlg.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/ui/namedlg/namedlg.cxx Fri Aug 31 08:11:09 2012
@@ -54,6 +54,7 @@
 #define ABS_SREF3D		ABS_SREF | SCA_TAB_3D
 #define ABS_DREF3D		ABS_DREF | SCA_TAB_3D
 
+const sal_uInt16  SHEETNAMEPOS = 33;
 
 //============================================================================
 // Hilfsklasse: Merken der aktuellen Bereichsoptionen,
@@ -119,6 +120,7 @@ ScNameDlg::ScNameDlg( SfxBindings* pB, S
 		//
         aFlName         ( this, ScResId( FL_NAME ) ),
 		aEdName 		( this, ScResId( ED_NAME ) ),
+		aLBNames 		( this, ScResId( LB_NAMES ) ),
 		//
         aFlAssign       ( this, ScResId( FL_ASSIGN ) ),
         aEdAssign       ( this, this, ScResId( ED_ASSIGN ) ),
@@ -145,7 +147,8 @@ ScNameDlg::ScNameDlg( SfxBindings* pB, S
 		pViewData		( ptrViewData ),
 		pDoc			( ptrViewData->GetDocument() ),
 		aLocalRangeName ( *(pDoc->GetRangeName()) ),
-		theCursorPos	( aCursorPos )  // zum Berechnen der Referenzen
+		theCursorPos	( aCursorPos ),  // zum Berechnen der Referenzen
+		aSelectedRangeScope(MAXTABCOUNT)
 {
 	pSaveObj = new SaveData;
 	Init();
@@ -179,7 +182,7 @@ void __EXPORT ScNameDlg::Init()
 	aEdAssign.SetGetFocusHdl( LINK( this, ScNameDlg, AssignGetFocusHdl ) );
 	aEdAssign.SetModifyHdl	( LINK( this, ScNameDlg, EdModifyHdl ) );
 	aEdName.SetModifyHdl 	( LINK( this, ScNameDlg, EdModifyHdl ) );
-	aEdName.SetSelectHdl 	( LINK( this, ScNameDlg, NameSelectHdl ) );
+	aLBNames.SetSelectHdl 	( LINK( this, ScNameDlg, NameSelectHdl ) );
 
 	aBtnCriteria .Hide();
 	aBtnPrintArea.Hide();
@@ -206,7 +209,8 @@ void __EXPORT ScNameDlg::Init()
 
 	aBtnAdd.Disable();
 	aBtnRemove.Disable();
-	if ( aEdName.GetEntryCount() > 0 )
+	//if ( aEdName.GetEntryCount() > 0 )
+	if ( aLBNames.GetEntryCount() > 0 )
 		aBtnAdd.SetText( aStrAdd );
 	UpdateChecks();
 	EdModifyHdl( 0 );
@@ -270,7 +274,7 @@ void __EXPORT ScNameDlg::UpdateChecks()
 {
 	sal_uInt16		 nCurPos=0;
 
-	if(aLocalRangeName.SearchName( aEdName.GetText(), nCurPos))
+	if(aLocalRangeName.SearchName( aEdName.GetText(), nCurPos, aSelectedRangeScope))
 	{
 		ScRangeData* pData=(ScRangeData*)(aLocalRangeName.At( nCurPos ));
 		aBtnCriteria .Check( pData->HasType( RT_CRITERIA ) );
@@ -285,26 +289,26 @@ void __EXPORT ScNameDlg::UpdateChecks()
 	{
 		if ( !aFlType.IsEnabled() )
 		{
-			aFlType 	 .Enable();
+			aFlType.Enable();
 			aBtnCriteria .Enable();
 			aBtnPrintArea.Enable();
 			aBtnColHeader.Enable();
 			aBtnRowHeader.Enable();
-            aFlAssign    .Enable();
-			aEdAssign    .Enable();
-			aRbAssign    .Enable();
+                        aFlAssign.Enable();
+			aEdAssign.Enable();
+			aRbAssign.Enable();
 		}
 	}
 	else if ( aFlType.IsEnabled() )
 	{
-		aFlType 	 .Disable();
-		aBtnCriteria .Disable();
+		aFlType.Disable();
+		aBtnCriteria.Disable();
 		aBtnPrintArea.Disable();
 		aBtnColHeader.Disable();
 		aBtnRowHeader.Disable();
-        aFlAssign    .Disable();
-		aEdAssign    .Disable();
-		aRbAssign    .Disable();
+                aFlAssign.Disable();
+		aEdAssign.Disable();
+		aRbAssign.Disable();
 	}
 }
 
@@ -315,10 +319,13 @@ void __EXPORT ScNameDlg::UpdateNames()
 {
 	sal_uInt16	nRangeCount = aLocalRangeName.GetCount();
 
-	aEdName.SetUpdateMode( sal_False );
+	//aEdName.SetUpdateMode( FALSE );
+	aLBNames.SetUpdateMode( false );
 	//-----------------------------------------------------------
-	sal_uInt16  nNamePos = aEdName.GetTopEntry();
-	aEdName.Clear();
+	//USHORT  nNamePos = aEdName.GetTopEntry();
+	//aEdName.Clear();
+	sal_uInt16  nNamePos = aLBNames.GetTopEntry();
+	aLBNames.Clear();
 
 	aEdAssign.SetText( EMPTY_STRING );
 
@@ -326,6 +333,7 @@ void __EXPORT ScNameDlg::UpdateNames()
 	{
 		ScRangeData*	pRangeData = NULL;
 		String			aString;
+                SCTAB tabIndex = 0;
 
 		for ( sal_uInt16 i=0; i<nRangeCount; i++ )
 		{
@@ -336,7 +344,21 @@ void __EXPORT ScNameDlg::UpdateNames()
 					&& !pRangeData->HasType( RT_SHARED ) )
 				{
 					pRangeData->GetName( aString );
-					aEdName.InsertEntry( aString );
+					if ( (tabIndex = pRangeData->GetRangeScope() ) != MAXTABCOUNT)
+					{
+                                                 String tabName;
+							pDoc->GetName(tabIndex,tabName);
+							if (aString.Len() < SHEETNAMEPOS)
+								aString.Expand(SHEETNAMEPOS);
+							else
+								aString.AppendAscii( " ");
+							aString.AppendAscii( "(");
+							aString += tabName;
+							aString.AppendAscii( ")"); 
+					}
+					
+					//aEdName.InsertEntry( aString );
+                                   aLBNames.InsertEntry( aString );
 				}
 			}
 		}
@@ -348,9 +370,12 @@ void __EXPORT ScNameDlg::UpdateNames()
 		aBtnRemove.Disable();
 	}
 	//-----------------------------------------------------------
-	aEdName.SetUpdateMode( sal_True );
-	aEdName.SetTopEntry(nNamePos);
-	aEdName.Invalidate();
+	//aEdName.SetUpdateMode( TRUE );
+	//aEdName.SetTopEntry(nNamePos);
+	//aEdName.Invalidate();
+	aLBNames.SetUpdateMode( true );
+	aLBNames.SetTopEntry(nNamePos);
+	aLBNames.Invalidate();	
 }
 
 
@@ -409,7 +434,8 @@ IMPL_LINK( ScNameDlg, AddBtnHdl, void *,
 {
 	sal_Bool	bAdded	  = sal_False;
 	String	aNewEntry = aEdName.GetText();
-	sal_uInt16  nNamePos = aEdName.GetTopEntry();
+	//USHORT  nNamePos = aEdName.GetTopEntry();
+        sal_uInt16  nNamePos = aLBNames.GetTopEntry();
 	aNewEntry.EraseLeadingChars( ' ' );
 	aNewEntry.EraseTrailingChars( ' ' );
 
@@ -431,6 +457,10 @@ IMPL_LINK( ScNameDlg, AddBtnHdl, void *,
 											 theSymbol,
 											 theCursorPos,
 											 nType );
+				if (aBtnAdd.GetText() == aStrModify)
+					pNewEntry->SetRangeScope(aSelectedRangeScope); 
+				else
+					aSelectedRangeScope = MAXTABCOUNT;
 				if (pNewEntry)
 				{
 					nType = nType
@@ -447,7 +477,7 @@ IMPL_LINK( ScNameDlg, AddBtnHdl, void *,
 				if ( 0 == pNewEntry->GetErrCode() )
 				{
 					// Eintrag bereits vorhanden? Dann vorher entfernen (=Aendern)
-					if ( aLocalRangeName.SearchName( aNewEntry, nFoundAt ) )
+					if ( aLocalRangeName.SearchName( aNewEntry, nFoundAt, aSelectedRangeScope ) )
 					{									// alten Index uebernehmen
 						pNewEntry->SetIndex(
 							((ScRangeData*)(aLocalRangeName.At(nFoundAt)))->GetIndex() );
@@ -491,7 +521,8 @@ IMPL_LINK( ScNameDlg, AddBtnHdl, void *,
 		}
 	}
 
-    aEdName.SetTopEntry(nNamePos);
+    //aEdName.SetTopEntry(nNamePos);
+	aLBNames.SetTopEntry(nNamePos);
 	return bAdded;
 }
 
@@ -503,7 +534,7 @@ IMPL_LINK( ScNameDlg, RemoveBtnHdl, void
 	sal_uInt16		 nRemoveAt = 0;
 	const String aStrEntry = aEdName.GetText();
 
-	if ( aLocalRangeName.SearchName( aStrEntry, nRemoveAt ) )
+	if ( aLocalRangeName.SearchName( aStrEntry, nRemoveAt, aSelectedRangeScope ) )
 	{
 		String aStrDelMsg = ScGlobal::GetRscString( STR_QUERY_DELENTRY );
 		String aMsg		  = aStrDelMsg.GetToken( 0, '#' );
@@ -520,6 +551,7 @@ IMPL_LINK( ScNameDlg, RemoveBtnHdl, void
 			bSaved=sal_False;
 			RESTORE_DATA()
 			theCurSel = Selection( 0, SELECTION_MAX );
+			aEdName.SetText(EMPTY_STRING);
 			aBtnAdd.SetText( aStrAdd );
 			aBtnAdd.Disable();
 			aBtnRemove.Disable();
@@ -534,8 +566,21 @@ IMPL_LINK( ScNameDlg, RemoveBtnHdl, void
 IMPL_LINK( ScNameDlg, NameSelectHdl, void *, EMPTYARG )
 {
 	sal_uInt16 nAtPos;
+       String rangeName = aLBNames.GetSelectEntry();
+       if ( ')' == rangeName.GetChar(rangeName.Len()-1) )
+       {
+            xub_StrLen sheetNamePos = rangeName.Search('(');
+	     String sheetName(rangeName, sheetNamePos+1, rangeName.Len()-2-sheetNamePos);
+            pDoc->GetTable(sheetName,aSelectedRangeScope);
+	     rangeName.Erase(sheetNamePos);
+	     rangeName.EraseTrailingChars();
+            
+	}
+	else   
+           aSelectedRangeScope = MAXTABCOUNT;
 
-	if ( aLocalRangeName.SearchName( aEdName.GetText(), nAtPos ) )
+	//if ( aLocalRangeName.SearchName( aEdName.GetText(), nAtPos ) )	
+	if ( aLocalRangeName.SearchName( rangeName, nAtPos, aSelectedRangeScope ) )
 	{
 		String		 aSymbol;
 		ScRangeData* pData	= (ScRangeData*)(aLocalRangeName.At( nAtPos ));
@@ -544,9 +589,13 @@ IMPL_LINK( ScNameDlg, NameSelectHdl, voi
 		{
 			pData->GetSymbol( aSymbol );
 			CalcCurTableAssign( aSymbol, nAtPos );
-			aEdAssign.SetText( aSymbol );
+	   		aEdAssign.SetText( aSymbol );
 			aBtnAdd.SetText( aStrModify );
+			aEdName.SetText(rangeName);
 			theCurSel = Selection( 0, SELECTION_MAX );
+			aBtnAdd.SetText( aStrModify );
+			aBtnAdd.Enable();
+			aBtnRemove.Enable();
 		}
 	}
 	UpdateChecks();
@@ -560,8 +609,8 @@ IMPL_LINK( ScNameDlg, EdModifyHdl, Edit 
 {
 	String	theName 	= aEdName.GetText();
 	String	theSymbol	= aEdAssign.GetText();
-	sal_Bool	bNameFound	= (COMBOBOX_ENTRY_NOTFOUND
-						   != aEdName.GetEntryPos( theName ));
+ bool	bNameFound	= (LISTBOX_ENTRY_NOTFOUND
+						   != aLBNames.GetEntryPos( theName ));
 
 	if ( pEd == &aEdName )
 	{
@@ -579,6 +628,7 @@ IMPL_LINK( ScNameDlg, EdModifyHdl, Edit 
 		}
 		else
 		{
+		 /*      
 			if ( bNameFound )
 			{
 				if ( aBtnAdd.GetText() != aStrModify )
@@ -588,7 +638,7 @@ IMPL_LINK( ScNameDlg, EdModifyHdl, Edit 
 
 				if(!bSaved)
 				{
-					bSaved=sal_True;
+					bSaved=TRUE;
 					SAVE_DATA()
 				}
 				NameSelectHdl( 0 );
@@ -599,9 +649,13 @@ IMPL_LINK( ScNameDlg, EdModifyHdl, Edit 
 					aBtnAdd.SetText( aStrAdd );
 				aBtnRemove.Disable();
 
-				bSaved=sal_False;
+				bSaved=FALSE;
 				RESTORE_DATA()
 			}
+			*/
+
+		       if ( aBtnAdd.GetText() != aStrAdd )
+			    aBtnAdd.SetText( aStrAdd );
 			theSymbol = aEdAssign.GetText();
 
 			if ( theSymbol.Len() > 0 )
@@ -612,6 +666,7 @@ IMPL_LINK( ScNameDlg, EdModifyHdl, Edit 
             aFlAssign.Enable();
 			aEdAssign.Enable();
 			aRbAssign.Enable();
+			aBtnRemove.Disable();
 			//@BugID 54702 raus mit dem Sch.
 			//SFX_APPWINDOW->Enable();
 		}

Modified: incubator/ooo/trunk/main/sc/source/ui/src/namedlg.src
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/ui/src/namedlg.src?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/ui/src/namedlg.src (original)
+++ incubator/ooo/trunk/main/sc/source/ui/src/namedlg.src Fri Aug 31 08:11:09 2012
@@ -75,15 +75,33 @@ ModelessDialog RID_SCDLG_NAMES
 		Size = MAP_APPFONT ( 154 , 8 ) ;
 		Text [ en-US ] = "Name" ;
 	};
+/*	
 	ComboBox ED_NAME
 	{
-	    HelpID = "sc:ComboBox:RID_SCDLG_NAMES:ED_NAME";
         Pos = MAP_APPFONT ( 12 , 14 ) ;
         Size = MAP_APPFONT ( 145 , 92 ) ;
 		TabStop = TRUE ;
 		VScroll = TRUE ;
 		Sort = TRUE ;
 	};
+*/
+        Edit ED_NAME
+	{
+	Border = TRUE ;
+        Pos = MAP_APPFONT ( 12 , 14 ) ;
+        Size = MAP_APPFONT ( 145 , 11 ) ;
+	};
+	
+	ListBox LB_NAMES
+	{
+	Border = TRUE ;
+        Pos = MAP_APPFONT ( 12 , 25 ) ;
+		Size = MAP_APPFONT ( 145 , 84 ) ;
+		TabStop = TRUE ;
+		VScroll = TRUE ;
+		AutoHScroll = TRUE ;
+		Sort = TRUE ;
+	};
     FixedLine FL_ASSIGN
 	{
         Pos = MAP_APPFONT ( 6 , 112 ) ;

Modified: incubator/ooo/trunk/main/sc/source/ui/unoobj/nameuno.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/ui/unoobj/nameuno.cxx?rev=1379349&r1=1379348&r2=1379349&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/ui/unoobj/nameuno.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/ui/unoobj/nameuno.cxx Fri Aug 31 08:11:09 2012
@@ -85,9 +85,10 @@ sal_Bool lcl_UserVisibleName( const ScRa
 
 //------------------------------------------------------------------------
 
-ScNamedRangeObj::ScNamedRangeObj(ScDocShell* pDocSh, const String& rNm) :
+ScNamedRangeObj::ScNamedRangeObj(ScDocShell* pDocSh, const String& rNm, const String& rScopeName) :
 	pDocShell( pDocSh ),
-	aName( rNm )
+	aName( rNm ),
+	aScopeName(rScopeName)
 {
 	pDocShell->GetDocument()->AddUnoObject(*this);
 }
@@ -117,7 +118,12 @@ ScRangeData* ScNamedRangeObj::GetRangeDa
 		if (pNames)
 		{
 			sal_uInt16 nPos = 0;
-			if (pNames->SearchName( aName, nPos ))
+			SCTAB nameScope = MAXTABCOUNT;
+			if ( aScopeName != EMPTY_STRING )
+			{
+				pDocShell->GetDocument()->GetTable( aScopeName, nameScope );
+			}
+			if (pNames->SearchName( aName, nPos, nameScope ))
 			{
 				pRet = (*pNames)[nPos];
 				pRet->ValidateTabRefs();		// adjust relative tab refs to valid tables
@@ -129,59 +135,72 @@ ScRangeData* ScNamedRangeObj::GetRangeDa
 
 // sheet::XNamedRange
 
-void ScNamedRangeObj::Modify_Impl( const String* pNewName, const ScTokenArray* pNewTokens, const String* pNewContent,
+void ScNamedRangeObj::Modify_Impl( const String* pNewRangeName, const ScTokenArray* pNewTokens, const String* pNewContent,
 									const ScAddress* pNewPos, const sal_uInt16* pNewType,
-                                    const formula::FormulaGrammar::Grammar eGrammar )
+                                    const formula::FormulaGrammar::Grammar eGrammar, const String* pNewScopeName )
 {
-	if (pDocShell)
-	{
-		ScDocument* pDoc = pDocShell->GetDocument();
-		ScRangeName* pNames = pDoc->GetRangeName();
-		if (pNames)
-		{
-			sal_uInt16 nPos = 0;
-            if (pNames->SearchName( aName, nPos ))
-			{
-                ScRangeName* pNewRanges = new ScRangeName( *pNames );
-				ScRangeData* pOld = (*pNames)[nPos];
-
-				String aInsName(pOld->GetName());
-				if (pNewName)
-					aInsName = *pNewName;
-				String aContent;                            // Content string based =>
-				pOld->GetSymbol( aContent, eGrammar);   // no problems with changed positions and such.
-				if (pNewContent)
-					aContent = *pNewContent;
-				ScAddress aPos(pOld->GetPos());
-				if (pNewPos)
-					aPos = *pNewPos;
-				sal_uInt16 nType = pOld->GetType();
-				if (pNewType)
-					nType = *pNewType;
-
-                ScRangeData* pNew = NULL;
-                if ( pNewTokens )
-                    pNew = new ScRangeData( pDoc, aInsName, *pNewTokens, aPos, nType );
-                else
-                    pNew = new ScRangeData( pDoc, aInsName, aContent, aPos, nType, eGrammar );
-				pNew->SetIndex( pOld->GetIndex() );
-
-                pNewRanges->AtFree( nPos );
-                if ( pNewRanges->Insert(pNew) )
-				{
-					ScDocFunc aFunc(*pDocShell);
-                    aFunc.SetNewRangeNames( pNewRanges, sal_True );
-
-					aName = aInsName;	//! broadcast?
-				}
-				else
-                {
-					delete pNew;		//! uno::Exception/Fehler oder so
-                    delete pNewRanges;
-                }
-			}
-		}
-	}
+       if (pDocShell)
+       {
+              ScDocument* pDoc = pDocShell->GetDocument();
+              ScRangeName* pNames = pDoc->GetRangeName();
+              if (pNames)
+              {
+                     sal_uInt16 nPos = 0;
+                     SCTAB nameScope = MAXTABCOUNT;
+                     if (aScopeName != EMPTY_STRING ) 
+                         pDoc->GetTable(aScopeName, nameScope);
+					 
+                     if (pNames->SearchName( aName, nPos, nameScope ))
+                     {
+                            SCTAB newNameScope = MAXTABCOUNT;
+                            if (pNewScopeName && *pNewScopeName != EMPTY_STRING && !pDoc->GetTable(*pNewScopeName, newNameScope))
+                                return;
+							//added for namerange renew
+							else if (!pNewScopeName || *pNewScopeName == EMPTY_STRING )
+								newNameScope = nameScope;
+							//end of add
+
+                            ScRangeName* pNewRanges = new ScRangeName( *pNames );
+                            ScRangeData* pOld = (*pNames)[nPos];
+
+                            String aInsName(pOld->GetName());
+                            if (pNewRangeName)
+                                aInsName = *pNewRangeName;
+                            String aContent;                            // Content string based =>
+                            pOld->GetSymbol( aContent, eGrammar);   // no problems with changed positions and such.
+                            if (pNewContent)
+                                aContent = *pNewContent;
+                            ScAddress aPos(pOld->GetPos());
+                            if (pNewPos)
+                                aPos = *pNewPos;
+                            sal_uInt16 nType = pOld->GetType();
+                            if (pNewType)
+                                nType = *pNewType;
+
+                            ScRangeData* pNew = NULL;
+                            if ( pNewTokens )
+                                pNew = new ScRangeData( pDoc, aInsName, *pNewTokens, aPos, nType );
+                            else
+                                pNew = new ScRangeData( pDoc, aInsName, aContent, aPos, nType, eGrammar );
+                            pNew->SetIndex( pOld->GetIndex() );
+                            pNew->SetRangeScope(newNameScope);
+						   	
+                            pNewRanges->AtFree( nPos );
+                            if ( pNewRanges->Insert(pNew) )
+                            {
+                                 ScDocFunc aFunc(*pDocShell);
+                                 aFunc.SetNewRangeNames( pNewRanges, sal_True );
+                                 aName = aInsName;	//! broadcast?
+                                 aScopeName = pNewScopeName ? *pNewScopeName : aScopeName;
+                            }
+                            else
+                            {
+                                 delete pNew;		//! uno::Exception/Fehler oder so
+                                 delete pNewRanges;
+                            }
+                       }
+              }
+       }
 }
 
 
@@ -204,6 +223,27 @@ void SAL_CALL ScNamedRangeObj::setName( 
 	if ( aName != aNewStr )					// some error occured...
 		throw uno::RuntimeException();		// no other exceptions specified
 }
+rtl::OUString SAL_CALL ScNamedRangeObj::getScopeName() throw(uno::RuntimeException)
+{
+	ScUnoGuard aGuard;
+	return aScopeName;
+}
+
+void SAL_CALL ScNamedRangeObj::setScopeAndRangeName( const rtl::OUString& aNewScopeName, const rtl::OUString& aNewRangeName )
+												throw(uno::RuntimeException)
+{
+	ScUnoGuard aGuard;
+	//!	Formeln anpassen ?????
+
+	String aNewRangeStr(aNewRangeName);
+	String aNewScopeStr(aNewScopeName);
+    // GRAM_PODF_A1 for API compatibility.
+	Modify_Impl( &aNewRangeStr, NULL, NULL, NULL, NULL,formula::FormulaGrammar::GRAM_PODF_A1,  aNewScopeName.getLength() == 0 ? NULL : &aNewScopeStr);
+
+	if ( aScopeName != aNewScopeStr || aName != aNewRangeStr  )					// some error occured...
+		throw uno::RuntimeException();		// no other exceptions specified
+}
+
 
 rtl::OUString SAL_CALL ScNamedRangeObj::getContent() throw(uno::RuntimeException)
 {
@@ -513,7 +553,7 @@ ScNamedRangeObj* ScNamedRangesObj::GetOb
 				if (lcl_UserVisibleName(pData))			// interne weglassen
 				{
 					if ( nPos == nIndex )
-						return new ScNamedRangeObj( pDocShell, pData->GetName() );
+						return new ScNamedRangeObj( pDocShell, pData->GetName(), pData->GetScopeSheetName() );
 					++nPos;
 				}
 			}
@@ -529,13 +569,15 @@ ScNamedRangeObj* ScNamedRangesObj::GetOb
 	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)
+ScNamedRangeObj* ScNamedRangesObj::GetObjectByScopeName_Impl(const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName)
+{
+     if ( pDocShell && hasByScopeName(aScopeName, aRangeName) )
+		return new ScNamedRangeObj( pDocShell, String(aRangeName),String(aScopeName) );
+	return NULL;
+}
+void ScNamedRangesObj::ImplAddNewByScopeAndName(SCTAB aScope, const ::rtl::OUString& aRangeName, const ::rtl::OUString& aContent,
+								const ::com::sun::star::table::CellAddress& aPosition, sal_Int32 nUnoType) throw(uno::RuntimeException)
 {
-	ScUnoGuard aGuard;
-	String aNameStr(aName);
-	String aContStr(aContent);
 	ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, aPosition.Sheet );
 
 	sal_uInt16 nNewType = RT_NAME;
@@ -544,29 +586,34 @@ void SAL_CALL ScNamedRangesObj::addNewBy
 	if ( nUnoType & sheet::NamedRangeFlag::COLUMN_HEADER )		nNewType |= RT_COLHEADER;
 	if ( nUnoType & sheet::NamedRangeFlag::ROW_HEADER )			nNewType |= RT_ROWHEADER;
 
-	sal_Bool bDone = sal_False;
+	bool bDone = false;
 	if (pDocShell)
 	{
 		ScDocument* pDoc = pDocShell->GetDocument();
 		ScRangeName* pNames = pDoc->GetRangeName();
-        sal_uInt16 nIndex = 0;
-		if (pNames && !pNames->SearchName(aNameStr, nIndex))
+              sal_uInt16 nIndex = 0;
+              String aNameStr(aRangeName);
+	       String aContStr(aContent);
+		if (pNames && !pNames->SearchName(aNameStr, nIndex,aScope))
 		{
-            ScRangeName* pNewRanges = new ScRangeName( *pNames );
+                   ScRangeName* pNewRanges = new ScRangeName( *pNames );
             // GRAM_PODF_A1 for API compatibility.
-			ScRangeData* pNew = new ScRangeData( pDoc, aNameStr, aContStr,
-												aPos, nNewType,formula::FormulaGrammar::GRAM_PODF_A1 );
-            if ( pNewRanges->Insert(pNew) )
-			{
+                   ScRangeData* pNew = new ScRangeData( pDoc, aNameStr, aContStr,
+												aPos, nNewType,formula::FormulaGrammar::GRAM_PODF_A1 );//GRAM_ODFF,//
+
+                   pNew->SetRangeScope(aScope);
+			
+                   if ( pNewRanges->Insert(pNew) )
+                   {
 				ScDocFunc aFunc(*pDocShell);
-                aFunc.SetNewRangeNames( pNewRanges, sal_True );
-				bDone = sal_True;
-			}
-			else
-            {
+                            aFunc.SetNewRangeNames( pNewRanges, sal_True );
+				bDone = true;
+                   }
+                   else
+                   {
 				delete pNew;
-                delete pNewRanges;
-            }
+                            delete pNewRanges;
+                   }
 		}
 	}
 
@@ -574,6 +621,29 @@ void SAL_CALL ScNamedRangesObj::addNewBy
 		throw uno::RuntimeException();		// no other exceptions specified
 }
 
+void SAL_CALL ScNamedRangesObj::addNewByName( const rtl::OUString& aName,
+		const rtl::OUString& aContent, const table::CellAddress& aPosition,
+		sal_Int32 nUnoType ) throw(uno::RuntimeException)
+{
+       ScUnoGuard aGuard;
+       ImplAddNewByScopeAndName(MAXTABCOUNT, aName, aContent, aPosition, nUnoType);
+}
+
+
+void SAL_CALL ScNamedRangesObj::addNewByScopeName( const rtl::OUString& aScopeName,const rtl::OUString& aRangeName,
+		const rtl::OUString& aContent, const table::CellAddress& aPosition,
+		sal_Int32 nUnoType ) throw(uno::RuntimeException)
+{
+       ScUnoGuard aGuard;
+       SCTAB scope = MAXTABCOUNT;
+       if (aScopeName.getLength() != 0 && pDocShell && 
+		          !pDocShell->GetDocument()->GetTable( String(aScopeName), scope ) )
+           throw uno::RuntimeException();
+       ImplAddNewByScopeAndName(scope, aRangeName, aContent, aPosition, nUnoType);
+		
+		
+}
+
 void SAL_CALL ScNamedRangesObj::addNewFromTitles( const table::CellRangeAddress& aSource,
 									sheet::Border aBorder ) throw(uno::RuntimeException)
 {
@@ -601,26 +671,24 @@ void SAL_CALL ScNamedRangesObj::addNewFr
 	}
 }
 
-void SAL_CALL ScNamedRangesObj::removeByName( const rtl::OUString& aName )
-												throw(uno::RuntimeException)
+void ScNamedRangesObj::ImplRemoveByScopeAndName(SCTAB aScope, const ::rtl::OUString& aRangeName)
+								throw(uno::RuntimeException)
 {
-	ScUnoGuard aGuard;
-	sal_Bool bDone = sal_False;
+	bool bDone = false;
 	if (pDocShell)
 	{
 		ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
 		if (pNames)
 		{
-			String aString(aName);
 			sal_uInt16 nPos = 0;
-			if (pNames->SearchName( aString, nPos ))
+			if (pNames->SearchName( String(aRangeName), nPos, aScope ))
 				if ( lcl_UserVisibleName((*pNames)[nPos]) )
 				{
-                    ScRangeName* pNewRanges = new ScRangeName(*pNames);
+                                   ScRangeName* pNewRanges = new ScRangeName(*pNames);
 					pNewRanges->AtFree(nPos);
 					ScDocFunc aFunc(*pDocShell);
-                    aFunc.SetNewRangeNames( pNewRanges, sal_True );
-					bDone = sal_True;
+                                   aFunc.SetNewRangeNames( pNewRanges, sal_True );
+					bDone = true;
 				}
 		}
 	}
@@ -629,6 +697,26 @@ void SAL_CALL ScNamedRangesObj::removeBy
 		throw uno::RuntimeException();		// no other exceptions specified
 }
 
+void SAL_CALL ScNamedRangesObj::removeByName( const rtl::OUString& aName )
+												throw(uno::RuntimeException)
+{
+     ScUnoGuard aGuard;
+     ImplRemoveByScopeAndName(MAXTABCOUNT, aName);	
+}
+
+
+void SAL_CALL ScNamedRangesObj::removeByScopeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName )
+								throw(uno::RuntimeException)
+{
+       ScUnoGuard aGuard;
+       SCTAB scope = MAXTABCOUNT;
+	if (aScopeName.getLength() != 0 && pDocShell && 
+		                 !pDocShell->GetDocument()->GetTable( String(aScopeName), scope ))
+           throw uno::RuntimeException();
+	ImplRemoveByScopeAndName(scope, aRangeName);	
+}
+
+
 void SAL_CALL ScNamedRangesObj::outputList( const table::CellAddress& aOutputPosition )
 												throw(uno::RuntimeException)
 {
@@ -708,6 +796,18 @@ uno::Any SAL_CALL ScNamedRangesObj::getB
 //    return uno::Any();
 }
 
+uno::Any SAL_CALL ScNamedRangesObj::getByScopeName( const rtl::OUString& aScopeName, const rtl::OUString& aRangeName )
+			throw(container::NoSuchElementException,
+					lang::WrappedTargetException, uno::RuntimeException)
+{
+	ScUnoGuard aGuard;
+	uno::Reference< sheet::XNamedRange >  xRange(GetObjectByScopeName_Impl(aScopeName, aRangeName));
+	if ( xRange.is() )
+        return uno::makeAny(xRange);
+	else
+		throw container::NoSuchElementException();
+//    return uno::Any();
+}
 uno::Sequence<rtl::OUString> SAL_CALL ScNamedRangesObj::getElementNames()
 												throw(uno::RuntimeException)
 {
@@ -736,6 +836,36 @@ uno::Sequence<rtl::OUString> SAL_CALL Sc
 	return uno::Sequence<rtl::OUString>(0);
 }
 
+uno::Sequence< sheet::RangeScopeName > SAL_CALL ScNamedRangesObj::getElementScopeNames()
+												throw(uno::RuntimeException)
+{
+       ScUnoGuard aGuard;
+	if (pDocShell)
+	{
+		ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
+		if (pNames)
+		{
+			long nVisCount = getCount();			// Namen mit lcl_UserVisibleName
+			uno::Sequence<sheet::RangeScopeName> aSeq(nVisCount);
+			sheet::RangeScopeName * pAry = aSeq.getArray();
+
+			sal_uInt16 nCount = pNames->GetCount();
+			sal_uInt16 nVisPos = 0;
+			for (sal_uInt16 i=0; i<nCount; i++)
+			{
+				ScRangeData* pData = (*pNames)[i];
+				if ( lcl_UserVisibleName(pData) )
+				{
+					pAry[nVisPos].RangeName = pData->GetName();
+					pAry[nVisPos++].ScopeName = pData->GetScopeSheetName();
+				}
+			}
+//			DBG_ASSERT(nVisPos == nVisCount, "huch, verzaehlt?");
+			return aSeq;
+		}
+	}
+	return uno::Sequence< sheet::RangeScopeName >(0);
+}
 sal_Bool SAL_CALL ScNamedRangesObj::hasByName( const rtl::OUString& aName )
 										throw(uno::RuntimeException)
 {
@@ -754,6 +884,27 @@ sal_Bool SAL_CALL ScNamedRangesObj::hasB
 	return sal_False;
 }
 
+sal_Bool SAL_CALL ScNamedRangesObj::hasByScopeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName)
+										throw(uno::RuntimeException)
+{
+	ScUnoGuard aGuard;
+	if (pDocShell)
+	{
+	       SCTAB scope = MAXTABCOUNT;
+	       if (aScopeName.getLength() != 0 && !pDocShell->GetDocument()->GetTable( String(aScopeName), scope ) )
+	           return sal_False; 
+			
+		ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
+		if (pNames)
+		{
+			sal_uInt16 nPos = 0;
+			if (pNames->SearchName( String(aRangeName), nPos, scope ))
+				if ( lcl_UserVisibleName((*pNames)[nPos]) )
+					return sal_True;
+		}
+	}
+	return sal_False;
+}
 /** called from the XActionLockable interface methods on initial locking */
 void ScNamedRangesObj::lock()
 {



Mime
View raw message