summaryrefslogtreecommitdiff
path: root/sc/source/ui/vba/vbaworksheet.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sc/source/ui/vba/vbaworksheet.cxx')
-rw-r--r--sc/source/ui/vba/vbaworksheet.cxx200
1 files changed, 102 insertions, 98 deletions
diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx
index be988509aa68..5b1963e3d242 100644
--- a/sc/source/ui/vba/vbaworksheet.cxx
+++ b/sc/source/ui/vba/vbaworksheet.cxx
@@ -24,9 +24,12 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
+
#include <vbahelper/helperdecl.hxx>
#include <cppuhelper/queryinterface.hxx>
+#include "vbaworksheet.hxx"
+
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XIntrospectionAccess.hpp>
#include <com/sun/star/beans/XIntrospection.hpp>
@@ -60,14 +63,15 @@
#include <ooo/vba/XControlProvider.hpp>
#include <comphelper/processfactory.hxx>
+#include <vbahelper/vbashapes.hxx>
#include <tools/string.hxx>
//zhangyun showdataform
#include <sfx2/sfxdlg.hxx>
-#include <scabstdlg.hxx>
-#include <tabvwsh.hxx>
-#include <scitems.hxx>
+#include "scabstdlg.hxx"
+#include "tabvwsh.hxx"
+#include "scitems.hxx"
#include <svx/svdouno.hxx>
#include <svx/svdpage.hxx>
@@ -79,43 +83,22 @@
#include "vbaoutline.hxx"
#include "vbarange.hxx"
#include "vbacomments.hxx"
-#include "vbaworksheet.hxx"
#include "vbachartobjects.hxx"
#include "vbapivottables.hxx"
#include "vbaoleobject.hxx"
#include "vbaoleobjects.hxx"
-#include <vbahelper/vbashapes.hxx>
#include "vbapagesetup.hxx"
#include "vbapagebreaks.hxx"
+#include "vbaworksheets.hxx"
+#include "vbahyperlinks.hxx"
+#include "vbasheetobjects.hxx"
#define STANDARDWIDTH 2267
#define STANDARDHEIGHT 427
#define DOESNOTEXIST -1
+
using namespace com::sun::star;
using namespace ooo::vba;
-bool
-nameExists( uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc, ::rtl::OUString & name, SCTAB& nTab ) throw ( lang::IllegalArgumentException )
-{
- if (!xSpreadDoc.is())
- throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nameExists() xSpreadDoc is null" ) ), uno::Reference< uno::XInterface >(), 1 );
- uno::Reference <sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
- uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
- if ( xIndex.is() )
- {
- SCTAB nCount = static_cast< SCTAB >( xIndex->getCount() );
- for (SCTAB i=0; i < nCount; i++)
- {
- uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(i), uno::UNO_QUERY);
- uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
- if (xNamed->getName() == name)
- {
- nTab = i;
- return true;
- }
- }
- }
- return false;
-}
static void getNewSpreadsheetName (rtl::OUString &aNewName, rtl::OUString aOldName, uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc )
{
@@ -125,7 +108,7 @@ static void getNewSpreadsheetName (rtl::OUString &aNewName, rtl::OUString aOldNa
int currentNum =2;
aNewName = aOldName + aUnderScre+ String::CreateFromInt32(currentNum) ;
SCTAB nTab = 0;
- while ( nameExists(xSpreadDoc,aNewName, nTab ) )
+ while ( ScVbaWorksheets::nameExists(xSpreadDoc,aNewName, nTab ) )
{
aNewName = aOldName + aUnderScre +
String::CreateFromInt32(++currentNum) ;
@@ -152,7 +135,8 @@ static void removeAllSheets( uno::Reference <sheet::XSpreadsheetDocument>& xSpre
}
}
- uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY); uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
+ uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY);
+ uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
if (xNamed.is())
{
xNamed->setName(aSheetName);
@@ -196,6 +180,7 @@ openNewDoc(rtl::OUString aSheetName )
ScVbaWorksheet::ScVbaWorksheet( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext ) : WorksheetImpl_BASE( xParent, xContext )
{
}
+
ScVbaWorksheet::ScVbaWorksheet(const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< sheet::XSpreadsheet >& xSheet,
const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) : WorksheetImpl_BASE( xParent, xContext ), mxSheet( xSheet ), mxModel(xModel)
@@ -216,6 +201,10 @@ ScVbaWorksheet::ScVbaWorksheet( uno::Sequence< uno::Any> const & args,
mxSheet.set( xNameAccess->getByName( sSheetName ), uno::UNO_QUERY_THROW );
}
+ScVbaWorksheet::~ScVbaWorksheet()
+{
+}
+
::rtl::OUString
ScVbaWorksheet::getName() throw (uno::RuntimeException)
{
@@ -261,9 +250,7 @@ ScVbaWorksheet::getEnableSelection() throw (uno::RuntimeException)
{
uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
SCTAB nTab = 0;
- rtl::OUString aSheetName = getName();
- bool bSheetExists = nameExists (xSpreadDoc, aSheetName, nTab);
- if ( bSheetExists )
+ if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) )
{
uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
@@ -301,9 +288,7 @@ ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection ) throw (uno::RuntimeEx
uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
SCTAB nTab = 0;
- rtl::OUString aSheetName = getName();
- bool bSheetExists = nameExists (xSpreadDoc, aSheetName, nTab);
- if ( bSheetExists )
+ if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) )
{
uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
@@ -426,9 +411,8 @@ ScVbaWorksheet::Select() throw (uno::RuntimeException)
void
ScVbaWorksheet::Move( const uno::Any& Before, const uno::Any& After ) throw (uno::RuntimeException)
{
- rtl::OUString aSheetName;
uno::Reference<excel::XWorksheet> xSheet;
- rtl::OUString aCurrSheetName =getName();
+ rtl::OUString aCurrSheetName = getName();
if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
{
@@ -451,9 +435,7 @@ ScVbaWorksheet::Move( const uno::Any& Before, const uno::Any& After ) throw (uno
uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
SCTAB nDest = 0;
- aSheetName = xSheet->getName();
- bool bSheetExists = nameExists (xSpreadDoc, aSheetName, nDest);
- if ( bSheetExists )
+ if ( ScVbaWorksheets::nameExists (xSpreadDoc, xSheet->getName(), nDest) )
{
sal_Bool bAfter = After.hasValue();
if (bAfter)
@@ -466,7 +448,6 @@ ScVbaWorksheet::Move( const uno::Any& Before, const uno::Any& After ) throw (uno
void
ScVbaWorksheet::Copy( const uno::Any& Before, const uno::Any& After ) throw (uno::RuntimeException)
{
- rtl::OUString aSheetName;
uno::Reference<excel::XWorksheet> xSheet;
rtl::OUString aCurrSheetName =getName();
if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
@@ -488,10 +469,8 @@ ScVbaWorksheet::Copy( const uno::Any& Before, const uno::Any& After ) throw (uno
uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY );
SCTAB nDest = 0;
- aSheetName = xSheet->getName();
- bool bSheetExists = nameExists (xSpreadDoc, aSheetName, nDest );
-
- if ( bSheetExists )
+ rtl::OUString aSheetName = xSheet->getName();
+ if ( ScVbaWorksheets::nameExists (xSpreadDoc, aSheetName, nDest ) )
{
sal_Bool bAfter = After.hasValue();
if(bAfter)
@@ -521,7 +500,7 @@ ScVbaWorksheet::Delete() throw (uno::RuntimeException)
if ( xSpreadDoc.is() )
{
SCTAB nTab = 0;
- if (!nameExists(xSpreadDoc, aSheetName, nTab ))
+ if (!ScVbaWorksheets::nameExists(xSpreadDoc, aSheetName, nTab ))
{
return;
}
@@ -539,11 +518,8 @@ ScVbaWorksheet::getSheetAtOffset(SCTAB offset) throw (uno::RuntimeException)
uno::Reference <sheet::XSpreadsheets> xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY_THROW );
- rtl::OUString aName = getName();
SCTAB nIdx = 0;
- bool bSheetExists = nameExists (xSpreadDoc, aName, nIdx );
-
- if ( !bSheetExists )
+ if ( !ScVbaWorksheets::nameExists (xSpreadDoc, getName(), nIdx ) )
return uno::Reference< excel::XWorksheet >();
nIdx = nIdx + offset;
uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(nIdx), uno::UNO_QUERY_THROW);
@@ -677,13 +653,25 @@ ScVbaWorksheet::Comments( const uno::Any& Index ) throw (uno::RuntimeException)
uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xSheet, uno::UNO_QUERY_THROW );
uno::Reference< sheet::XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), uno::UNO_QUERY_THROW );
uno::Reference< container::XIndexAccess > xIndexAccess( xAnnos, uno::UNO_QUERY_THROW );
- uno::Reference< XCollection > xColl( new ScVbaComments( this, mxContext, xIndexAccess ) );
+ uno::Reference< XCollection > xColl( new ScVbaComments( this, mxContext, mxModel, xIndexAccess ) );
if ( Index.hasValue() )
return xColl->Item( Index, uno::Any() );
return uno::makeAny( xColl );
}
uno::Any SAL_CALL
+ScVbaWorksheet::Hyperlinks( const uno::Any& aIndex ) throw (uno::RuntimeException)
+{
+ /* The worksheet always returns the same Hyperlinks object.
+ See vbahyperlinks.hxx for more details. */
+ if( !mxHlinks.is() )
+ mxHlinks.set( new ScVbaHyperlinks( this, mxContext ) );
+ if( aIndex.hasValue() )
+ return uno::Reference< XCollection >( mxHlinks, uno::UNO_QUERY_THROW )->Item( aIndex, uno::Any() );
+ return uno::Any( mxHlinks );
+}
+
+uno::Any SAL_CALL
ScVbaWorksheet::OLEObjects( const uno::Any& Index ) throw (uno::RuntimeException)
{
ScVbaOLEObjects* aOleObjects;
@@ -716,6 +704,66 @@ ScVbaWorksheet::Shapes( const uno::Any& aIndex ) throw (uno::RuntimeException)
return uno::makeAny( xVbaShapes );
}
+uno::Any SAL_CALL
+ScVbaWorksheet::Buttons( const uno::Any& rIndex ) throw (uno::RuntimeException)
+{
+ if( !mxButtons.is() )
+ mxButtons.set( new ScVbaButtons( this, mxContext, mxModel, mxSheet ) );
+ else
+ mxButtons->collectShapes();
+ if( rIndex.hasValue() )
+ return mxButtons->Item( rIndex, uno::Any() );
+ return uno::Any( uno::Reference< XCollection >( mxButtons.get() ) );
+}
+
+uno::Any SAL_CALL
+ScVbaWorksheet::CheckBoxes( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
+{
+ throw uno::RuntimeException();
+}
+
+uno::Any SAL_CALL
+ScVbaWorksheet::DropDowns( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
+{
+ throw uno::RuntimeException();
+}
+
+uno::Any SAL_CALL
+ScVbaWorksheet::GroupBoxes( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
+{
+ throw uno::RuntimeException();
+}
+
+uno::Any SAL_CALL
+ScVbaWorksheet::Labels( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
+{
+ throw uno::RuntimeException();
+}
+
+uno::Any SAL_CALL
+ScVbaWorksheet::ListBoxes( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
+{
+ throw uno::RuntimeException();
+}
+
+uno::Any SAL_CALL
+ScVbaWorksheet::OptionButtons( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
+{
+ throw uno::RuntimeException();
+}
+
+uno::Any SAL_CALL
+ScVbaWorksheet::ScrollBars( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
+{
+ throw uno::RuntimeException();
+}
+
+uno::Any SAL_CALL
+ScVbaWorksheet::Spinners( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
+{
+ throw uno::RuntimeException();
+}
+
void SAL_CALL
ScVbaWorksheet::ShowDataForm( ) throw (uno::RuntimeException)
{
@@ -882,52 +930,8 @@ ScVbaWorksheet::getServiceNames()
rtl::OUString SAL_CALL
ScVbaWorksheet::getCodeName() throw (css::uno::RuntimeException)
{
-#ifdef VBA_OOBUILD_HACK
- uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
- SCTAB nTab = 0;
- rtl::OUString aSheetName = getName();
- bool bSheetExists = nameExists (xSpreadDoc, aSheetName, nTab);
- if ( bSheetExists )
- {
- uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
- ScDocument* pDoc = getDocShell( xModel )->GetDocument();
- ScExtDocOptions* pExtOptions = pDoc->GetExtDocOptions();
- rtl::OUString sCodeName = pExtOptions->GetCodeName( nTab );
- return sCodeName;
- }
- else
- throw uno::RuntimeException(::rtl::OUString(
- RTL_CONSTASCII_USTRINGPARAM( "Sheet Name does not exist. ") ),
- uno::Reference< XInterface >() );
-#else
- throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
-#endif
-}
-#ifdef VBA_OOBUILD_HACK
-void SAL_CALL
-ScVbaWorksheet::setCodeName( const rtl::OUString& sCodeName ) throw (css::uno::RuntimeException)
-{
- uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
- SCTAB nTab = 0;
- rtl::OUString aSheetName = getName();
- bool bSheetExists = nameExists (xSpreadDoc, aSheetName, nTab);
- if ( bSheetExists )
- {
- uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
- ScDocument* pDoc = getDocShell( xModel )->GetDocument();
- ScExtDocOptions* pExtOptions = pDoc->GetExtDocOptions();
- pExtOptions->SetCodeName( sCodeName, nTab );
- }
- else
- throw uno::RuntimeException(::rtl::OUString(
- RTL_CONSTASCII_USTRINGPARAM( "Sheet Name does not exist. ") ),
- uno::Reference< XInterface >() );
-#else
-void SAL_CALL
-ScVbaWorksheet::setCodeName( const rtl::OUString& ) throw (css::uno::RuntimeException)
-{
- throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
-#endif
+ uno::Reference< beans::XPropertySet > xSheetProp( mxSheet, uno::UNO_QUERY_THROW );
+ return xSheetProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CodeName" ) ) ).get< ::rtl::OUString >();
}
sal_Int16