summaryrefslogtreecommitdiff
path: root/sc/source/ui/vba
diff options
context:
space:
mode:
Diffstat (limited to 'sc/source/ui/vba')
-rw-r--r--sc/source/ui/vba/excelvbahelper.cxx7
-rw-r--r--sc/source/ui/vba/excelvbahelper.hxx4
-rwxr-xr-x[-rw-r--r--]sc/source/ui/vba/testvba/runTests.pl2
-rwxr-xr-xsc/source/ui/vba/testvba/testclientbin39390 -> 50595 bytes
-rw-r--r--sc/source/ui/vba/vbaapplication.cxx78
-rw-r--r--sc/source/ui/vba/vbaformat.cxx60
-rw-r--r--sc/source/ui/vba/vbaformat.hxx5
-rw-r--r--sc/source/ui/vba/vbarange.cxx66
-rw-r--r--sc/source/ui/vba/vbarange.hxx11
9 files changed, 140 insertions, 93 deletions
diff --git a/sc/source/ui/vba/excelvbahelper.cxx b/sc/source/ui/vba/excelvbahelper.cxx
index 4912863a446e..b1c4db637434 100644
--- a/sc/source/ui/vba/excelvbahelper.cxx
+++ b/sc/source/ui/vba/excelvbahelper.cxx
@@ -208,12 +208,11 @@ getViewFrame( const uno::Reference< frame::XModel >& xModel )
}
SfxItemSet*
-ScVbaCellRangeAccess::GetDataSet( ScCellRangeObj* pRangeObj )
+ScVbaCellRangeAccess::GetDataSet( ScCellRangesBase* pRangeObj )
{
- SfxItemSet* pDataSet = pRangeObj ? pRangeObj->GetCurrentDataSet( true ) : NULL ;
- return pDataSet;
-
+ return pRangeObj ? pRangeObj->GetCurrentDataSet( true ) : 0;
}
+
} //excel
} //vba
} //ooo
diff --git a/sc/source/ui/vba/excelvbahelper.hxx b/sc/source/ui/vba/excelvbahelper.hxx
index 34b099e6db46..9af804ab169f 100644
--- a/sc/source/ui/vba/excelvbahelper.hxx
+++ b/sc/source/ui/vba/excelvbahelper.hxx
@@ -30,7 +30,7 @@
#include<vbahelper/vbahelper.hxx>
#include <docsh.hxx>
-class ScCellRangeObj;
+class ScCellRangesBase;
namespace ooo
{
@@ -51,7 +51,7 @@ namespace ooo
class ScVbaCellRangeAccess
{
public:
- static SfxItemSet* GetDataSet( ScCellRangeObj* pRangeObj );
+ static SfxItemSet* GetDataSet( ScCellRangesBase* pRangeObj );
};
}
}
diff --git a/sc/source/ui/vba/testvba/runTests.pl b/sc/source/ui/vba/testvba/runTests.pl
index f5051516a9c4..e686a1d4cb89 100644..100755
--- a/sc/source/ui/vba/testvba/runTests.pl
+++ b/sc/source/ui/vba/testvba/runTests.pl
@@ -20,7 +20,7 @@ my $theResult;
my $officepath = shift || die "please specify path to office installation program dir";
my $DocName = shift || "";
my $programpath = "$officepath"."3/program:$officepath/program:";
-my $basiclibrarypath = "$officepath/basis3.2/program";
+my $basiclibrarypath = "$officepath/basis3.3/program";
my $urelibpath = "$officepath/ure/lib";
my $binext = "";
my $testDocDir = "$binDir/TestDocuments";
diff --git a/sc/source/ui/vba/testvba/testclient b/sc/source/ui/vba/testvba/testclient
index 12e9ca1659f4..c9cde8c5b052 100755
--- a/sc/source/ui/vba/testvba/testclient
+++ b/sc/source/ui/vba/testvba/testclient
Binary files differ
diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx
index 5d9e513dabeb..3d5af01acef1 100644
--- a/sc/source/ui/vba/vbaapplication.cxx
+++ b/sc/source/ui/vba/vbaapplication.cxx
@@ -132,10 +132,16 @@ ScVbaApplication::getActiveWorkbook() throw (uno::RuntimeException)
{
return new ActiveWorkbook( this, mxContext );
}
+
uno::Reference< excel::XWorkbook > SAL_CALL
ScVbaApplication::getThisWorkbook() throw (uno::RuntimeException)
{
- return getActiveWorkbook();
+ uno::Reference< frame::XModel > xModel = getThisExcelDoc(mxContext);
+ if( !xModel.is() )
+ return uno::Reference< excel::XWorkbook >();
+
+ ScVbaWorkbook *pWb = new ScVbaWorkbook( this, mxContext, xModel );
+ return uno::Reference< excel::XWorkbook > (pWb);
}
uno::Reference< XAssistant > SAL_CALL
@@ -769,46 +775,74 @@ bool lcl_canJoin( ScRange& r1, ScRange& r2 )
void lcl_strip_containedRanges( Ranges& vRanges )
{
// get rid of ranges that are surrounded by other ranges
- for( Ranges::iterator it = vRanges.begin(); it != vRanges.end(); ++it )
+ Ranges::iterator it_outer = vRanges.begin();
+ while( it_outer != vRanges.end() )
{
- for( Ranges::iterator it_inner = vRanges.begin(); it_inner != vRanges.end(); ++it_inner )
+ bool it_outer_erased = false; // true = it_outer erased from vRanges
+ Ranges::iterator it_inner = vRanges.begin();
+ /* Exit the inner loop if outer iterator has been erased in its last
+ iteration (this means it has been joined to last it_inner, or that
+ the it_inner contains it completely). The inner loop will restart
+ with next element of the outer loop, and all elements (from the
+ beginning of the list) will be checked against that new element. */
+ while( !it_outer_erased && (it_inner != vRanges.end()) )
{
- if ( it != it_inner )
+ bool it_inner_erased = false; // true = it_inner erased from vRanges
+ if ( it_outer != it_inner )
{
#ifdef DEBUG
- String r1;
- String r2;
- it->Format( r1, SCA_VALID ) ;
- it_inner->Format( r2, SCA_VALID ) ;
- OSL_TRACE( "try strip/join address %s with %s ",
- rtl::OUStringToOString( r1, RTL_TEXTENCODING_UTF8 ).getStr(),
- rtl::OUStringToOString( r2, RTL_TEXTENCODING_UTF8 ).getStr() );
+ String r1;
+ String r2;
+ it_outer->Format( r1, SCA_VALID ) ;
+ it_inner->Format( r2, SCA_VALID ) ;
+ OSL_TRACE( "try strip/join address %s with %s ",
+ rtl::OUStringToOString( r1, RTL_TEXTENCODING_UTF8 ).getStr(),
+ rtl::OUStringToOString( r2, RTL_TEXTENCODING_UTF8 ).getStr() );
#endif
- if ( it->In( *it_inner ) )
+ if ( it_outer->In( *it_inner ) )
+ {
it_inner = vRanges.erase( it_inner );
- else if ( it_inner->In( *it ) )
- it = vRanges.erase( it );
+ it_inner_erased = true;
+ }
+ else if ( it_inner->In( *it_outer ) )
+ {
+ it_outer = vRanges.erase( it_outer );
+ it_outer_erased = true;
+ }
#ifndef OWN_JOIN
- else if ( (*it_inner).aStart.Row() == (*it).aStart.Row()
- && (*it_inner).aEnd.Row() == (*it).aEnd.Row() )
+ else if ( (*it_inner).aStart.Row() == (*it_outer).aStart.Row()
+ && (*it_inner).aEnd.Row() == (*it_outer).aEnd.Row() )
{
- it->ExtendTo( *it_inner );
+ it_outer->ExtendTo( *it_inner );
it_inner = vRanges.erase( it_inner );
+ it_inner_erased = true;
}
#else
- else if ( lcl_canJoin( *it, *it_inner ) )
+ else if ( lcl_canJoin( *it_outer, *it_inner ) )
{
- it->ExtendTo( *it_inner );
+ it_outer->ExtendTo( *it_inner );
it_inner = vRanges.erase( it_inner );
+ it_inner_erased = true;
}
- else if ( lcl_canJoin( *it_inner, *it) )
+ else if ( lcl_canJoin( *it_inner, *it_outer) )
{
- it_inner->ExtendTo( *it );
- it = vRanges.erase( it );
+ it_inner->ExtendTo( *it_outer );
+ it_outer = vRanges.erase( it_outer );
+ it_outer_erased = true;
}
#endif
}
+ /* If it_inner has not been erased from vRanges, continue inner
+ loop with next element. Otherwise, it_inner already points to
+ the next element (return value of list::erase()). */
+ if( !it_inner_erased )
+ ++it_inner;
}
+ /* If it_outer has not been erased from vRanges, continue outer loop
+ with next element. Otherwise, it_outer already points to the next
+ element (return value of list::erase()). */
+ if( !it_outer_erased )
+ ++it_outer;
}
}
diff --git a/sc/source/ui/vba/vbaformat.cxx b/sc/source/ui/vba/vbaformat.cxx
index c98029fb1292..23c2bf96a810 100644
--- a/sc/source/ui/vba/vbaformat.cxx
+++ b/sc/source/ui/vba/vbaformat.cxx
@@ -45,7 +45,10 @@
#include "vbafont.hxx"
#include "vbainterior.hxx"
-#include "unonames.hxx"
+#include <unonames.hxx>
+#include <cellsuno.hxx>
+#include <scitems.hxx>
+#include <attrib.hxx>
using namespace ::ooo::vba;
using namespace ::com::sun::star;
@@ -571,14 +574,24 @@ ScVbaFormat<Ifc1>::getLocked( ) throw (script::BasicErrorException, uno::Runtim
uno::Any aCellProtection = aNULL();
try
{
-
rtl::OUString sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO ) );
+
if (!isAmbiguous(sCellProt))
{
- util::CellProtection cellProtection;
- mxPropertySet->getPropertyValue(sCellProt) >>= cellProtection;
-
- aCellProtection = uno::makeAny( cellProtection.IsLocked );
+ SfxItemSet* pDataSet = getCurrentDataSet();
+ if ( pDataSet )
+ {
+ const ScProtectionAttr& rProtAttr = (const ScProtectionAttr &) pDataSet->Get(ATTR_PROTECTION, TRUE);
+ SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION, TRUE, NULL);
+ if(eState != SFX_ITEM_DONTCARE)
+ aCellProtection = uno::makeAny(rProtAttr.GetProtection());
+ }
+ else // fallback to propertyset
+ {
+ util::CellProtection cellProtection;
+ mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
+ aCellProtection = uno::makeAny( cellProtection.IsLocked );
+ }
}
}
catch (uno::Exception& )
@@ -598,9 +611,20 @@ ScVbaFormat<Ifc1>::getFormulaHidden( ) throw (script::BasicErrorException, uno:
rtl::OUString sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO ) );
if (!isAmbiguous(sCellProt))
{
- util::CellProtection aCellProtection;
- mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
- aBoolRet = uno::makeAny( aCellProtection.IsFormulaHidden );
+ SfxItemSet* pDataSet = getCurrentDataSet();
+ if ( pDataSet )
+ {
+ const ScProtectionAttr& rProtAttr = (const ScProtectionAttr &) pDataSet->Get(ATTR_PROTECTION, TRUE);
+ SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION, TRUE, NULL);
+ if(eState != SFX_ITEM_DONTCARE)
+ aBoolRet = uno::makeAny(rProtAttr.GetHideFormula());
+ }
+ else
+ {
+ util::CellProtection aCellProtection;
+ mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
+ aBoolRet = uno::makeAny( aCellProtection.IsFormulaHidden );
+ }
}
}
catch (uno::Exception e)
@@ -794,6 +818,24 @@ ScVbaFormat<Ifc1>::getServiceNames()
return aServiceNames;
}
+template< typename Ifc1 >
+ScCellRangesBase*
+ScVbaFormat<Ifc1>::getCellRangesBase() throw ( ::uno::RuntimeException )
+{
+ return ScCellRangesBase::getImplementation( mxPropertySet );
+}
+
+template< typename Ifc1 >
+SfxItemSet*
+ScVbaFormat<Ifc1>::getCurrentDataSet( ) throw ( uno::RuntimeException )
+{
+ SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() );
+ if ( !pDataSet )
+ throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't access Itemset for XPropertySet" ) ), uno::Reference< uno::XInterface >() );
+ return pDataSet;
+}
+
+
template class ScVbaFormat< excel::XStyle >;
template class ScVbaFormat< excel::XRange >;
diff --git a/sc/source/ui/vba/vbaformat.hxx b/sc/source/ui/vba/vbaformat.hxx
index e024cd68b9ad..bfa88d6c7cb8 100644
--- a/sc/source/ui/vba/vbaformat.hxx
+++ b/sc/source/ui/vba/vbaformat.hxx
@@ -38,6 +38,8 @@
#include <com/sun/star/beans/XPropertyState.hpp>
#include <vbahelper/vbahelperinterface.hxx>
+class ScCellRangesBase;
+
template< typename Ifc1 >
class ScVbaFormat : public InheritedHelperInterfaceImpl1< Ifc1 >
{
@@ -60,6 +62,9 @@ protected:
css::uno::Reference< css::beans::XPropertyState > getXPropertyState() throw ( css::uno::RuntimeException );
void initializeNumberFormats() throw ( css::script::BasicErrorException );
void setNumberFormat( css::lang::Locale _aLocale, const rtl::OUString& _sFormatString) throw( css::script::BasicErrorException );
+ SfxItemSet* getCurrentDataSet( ) throw ( css::uno::RuntimeException );
+protected:
+ virtual ScCellRangesBase* getCellRangesBase() throw ( css::uno::RuntimeException );
public:
ScVbaFormat( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet, const css::uno::Reference< css::frame::XModel >& xModel, bool bCheckAmbiguoity ) throw ( css::script::BasicErrorException );
virtual ~ScVbaFormat() {}
diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx
index b3307ffdc55d..1a153b440b15 100644
--- a/sc/source/ui/vba/vbarange.cxx
+++ b/sc/source/ui/vba/vbarange.cxx
@@ -238,21 +238,28 @@ uno::Reference< excel::XRange > lcl_makeXRangeFromSheetCellRanges( const uno::Re
return xRange;
}
-ScCellRangeObj* ScVbaRange::getCellRangeObj() throw ( uno::RuntimeException )
+ScCellRangesBase* ScVbaRange::getCellRangesBase() throw ( uno::RuntimeException )
{
- uno::Reference< uno::XInterface > xIf;
- if ( mxRanges.is() )
- xIf.set( mxRanges, uno::UNO_QUERY_THROW );
- else
- xIf.set( mxRange, uno::UNO_QUERY_THROW );
- ScCellRangeObj* pUnoCellRange = dynamic_cast< ScCellRangeObj* >( xIf.get() );
- return pUnoCellRange;
+ if( mxRanges.is() )
+ return ScCellRangesBase::getImplementation( mxRanges );
+ if( mxRange.is() )
+ return ScCellRangesBase::getImplementation( mxRange );
+ throw uno::RuntimeException( rtl::OUString::createFromAscii("General Error creating range - Unknown" ), uno::Reference< uno::XInterface >() );
+}
+
+ScCellRangeObj* ScVbaRange::getCellRangeObj() throw ( uno::RuntimeException )
+{
+ return dynamic_cast< ScCellRangeObj* >( getCellRangesBase() );
+}
+
+ScCellRangesObj* ScVbaRange::getCellRangesObj() throw ( uno::RuntimeException )
+{
+ return dynamic_cast< ScCellRangesObj* >( getCellRangesBase() );
}
SfxItemSet* ScVbaRange::getCurrentDataSet( ) throw ( uno::RuntimeException )
{
- ScCellRangeObj* pUnoCellRange = getCellRangeObj();
- SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( pUnoCellRange );
+ SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() );
if ( !pDataSet )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't access Itemset for range" ) ), uno::Reference< uno::XInterface >() );
return pDataSet;
@@ -3852,25 +3859,6 @@ ScVbaRange::getWorksheet() throw (uno::RuntimeException)
return xSheet;
}
-ScCellRangesBase*
-ScVbaRange::getCellRangesBase() throw( uno::RuntimeException )
-{
- ScCellRangesBase* pUnoRangesBase = NULL;
- if ( mxRanges.is() )
- {
- uno::Reference< uno::XInterface > xIf( mxRanges, uno::UNO_QUERY_THROW );
- pUnoRangesBase = dynamic_cast< ScCellRangesBase* >( xIf.get() );
- }
- else if ( mxRange.is() )
- {
- uno::Reference< uno::XInterface > xIf( mxRange, uno::UNO_QUERY_THROW );
- pUnoRangesBase = dynamic_cast< ScCellRangesBase* >( xIf.get() );
- }
- else
- throw uno::RuntimeException( rtl::OUString::createFromAscii("General Error creating range - Unknown" ), uno::Reference< uno::XInterface >() );
- return pUnoRangesBase;
-}
-
// #TODO remove this ugly application processing
// Process an application Range request e.g. 'Range("a1,b2,a4:b6")
uno::Reference< excel::XRange >
@@ -4589,26 +4577,6 @@ ScVbaRange::getValidation() throw (css::uno::RuntimeException)
return m_xValidation;
}
-uno::Any ScVbaRange::getFormulaHidden() throw ( script::BasicErrorException, css::uno::RuntimeException)
-{
- SfxItemSet* pDataSet = getCurrentDataSet();
- const ScProtectionAttr& rProtAttr = (const ScProtectionAttr &)
- pDataSet->Get(ATTR_PROTECTION, TRUE);
- SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION, TRUE, NULL);
- if(eState == SFX_ITEM_DONTCARE)
- return aNULL();
- return uno::makeAny(rProtAttr.GetHideFormula());
-
-}
-void ScVbaRange::setFormulaHidden(const uno::Any& Hidden) throw ( script::BasicErrorException, css::uno::RuntimeException)
-{
- uno::Reference< beans::XPropertySet > xProps(mxRange, ::uno::UNO_QUERY_THROW);
- util::CellProtection rCellAttr;
- xProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CELLPRO))) >>= rCellAttr;
- Hidden >>= rCellAttr.IsFormulaHidden;
- xProps->setPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CELLPRO)), uno::makeAny(rCellAttr));
-}
-
uno::Any ScVbaRange::getShowDetail() throw ( css::uno::RuntimeException)
{
// #FIXME, If the specified range is in a PivotTable report
diff --git a/sc/source/ui/vba/vbarange.hxx b/sc/source/ui/vba/vbarange.hxx
index 89ae741c7535..1f161a79d973 100644
--- a/sc/source/ui/vba/vbarange.hxx
+++ b/sc/source/ui/vba/vbarange.hxx
@@ -57,6 +57,7 @@
class ScTableSheetsObj;
class ScCellRangesBase;
class ScCellRangeObj;
+class ScCellRangesObj;
class ScDocShell;
class ScDocument;
@@ -111,14 +112,16 @@ class ScVbaRange : public ScVbaRange_BASE
virtual css::uno::Any getFormulaValue( formula::FormulaGrammar::Grammar ) throw (css::uno::RuntimeException);
virtual void setFormulaValue( const css::uno::Any& aValue, formula::FormulaGrammar::Grammar ) throw ( css::uno::RuntimeException);
css::uno::Reference< ov::excel::XRange > getArea( sal_Int32 nIndex ) throw( css::uno::RuntimeException );
- ScCellRangesBase* getCellRangesBase() throw ( css::uno::RuntimeException );
ScCellRangeObj* getCellRangeObj( ) throw ( css::uno::RuntimeException );
- SfxItemSet* getCurrentDataSet( ) throw ( css::uno::RuntimeException );
+ ScCellRangesObj* getCellRangesObj() throw ( css::uno::RuntimeException );
css::uno::Reference< ov::XCollection >& getBorders();
void groupUnGroup( bool bUnGroup = false ) throw ( css::script::BasicErrorException, css::uno::RuntimeException );
css::uno::Reference< ov::excel::XRange > PreviousNext( bool bIsPrevious );
css::uno::Reference< ov::excel::XRange > SpecialCellsImpl( sal_Int32 nType, const css::uno::Any& _oValue) throw ( css::script::BasicErrorException );
css::awt::Point getPosition() throw ( css::uno::RuntimeException );
+protected:
+ virtual ScCellRangesBase* getCellRangesBase() throw ( css::uno::RuntimeException );
+ virtual SfxItemSet* getCurrentDataSet( ) throw ( css::uno::RuntimeException );
public:
ScVbaRange( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::table::XCellRange >& xRange, sal_Bool bIsRows = false, sal_Bool bIsColumns = false ) throw ( css::lang::IllegalArgumentException );
ScVbaRange( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::sheet::XSheetCellRangeContainer >& xRanges, sal_Bool bIsRows = false, sal_Bool bIsColumns = false ) throw ( css::lang::IllegalArgumentException );
@@ -170,10 +173,6 @@ public:
virtual css::uno::Any SAL_CALL getPageBreak() throw (css::uno::RuntimeException);
virtual void SAL_CALL setPageBreak( const css::uno::Any& _pagebreak ) throw (css::uno::RuntimeException);
virtual css::uno::Reference< ov::excel::XValidation > SAL_CALL getValidation() throw (css::uno::RuntimeException);
- virtual css::uno::Any SAL_CALL getFormulaHidden() throw (css::script::BasicErrorException, css::uno::RuntimeException);
- virtual void SAL_CALL setFormulaHidden(const css::uno::Any& aHidden) throw (css::script::BasicErrorException, css::uno::RuntimeException);
- //virtual css::uno::Any SAL_CALL getLocked() throw (css::script::BasicErrorException, css::uno::RuntimeException);
- //virtual void SAL_CALL setLocked(const css::uno::Any& aLocked) throw (css::script::BasicErrorException, css::uno::RuntimeException);
virtual css::uno::Any SAL_CALL getShowDetail() throw (css::uno::RuntimeException);
virtual void SAL_CALL setShowDetail(const css::uno::Any& aShowDetail) throw (css::uno::RuntimeException);
// Methods