update ooo310-m15
[ooovba.git] / applied_patches / 0351-vba-allow-ranges-for-cell-functions.diff
blobcfa38a9fa0b951f3b6d41144efc6e9f6b8c424a4
1 --- sc/source/core/tool/interpr4.cxx.old 2009-04-06 16:41:48.000000000 +0000
2 +++ sc/source/core/tool/interpr4.cxx 2009-04-06 16:41:58.000000000 +0000
3 @@ -36,10 +36,12 @@
4 #include <sfx2/app.hxx>
5 #include <sfx2/docfile.hxx>
6 #include <sfx2/objsh.hxx>
7 +#include <sfx2/docfilt.hxx>
8 #include <basic/sbmeth.hxx>
9 #include <basic/sbmod.hxx>
10 #include <basic/sbstar.hxx>
11 #include <basic/sbx.hxx>
12 +#include <basic/sbuno.hxx>
13 #include <svtools/zforlist.hxx>
14 #include <tools/urlobj.hxx>
15 #include <rtl/logfile.hxx>
16 @@ -48,6 +50,7 @@
17 #include <signal.h>
19 #include <com/sun/star/table/XCellRange.hpp>
20 +#include <comphelper/processfactory.hxx>
22 #include "interpre.hxx"
23 #include "global.hxx"
24 @@ -2503,7 +2506,38 @@ void ScInterpreter::ScMissing()
25 PushTempToken( new FormulaMissingToken );
29 +bool
30 +lcl_setVBARange( ScRange& aRange, ScDocument* pDok, SbxVariable* pPar )
32 + bool bOk = false;
33 + try
34 + {
35 + uno::Reference< uno::XInterface > xVBARange;
36 + uno::Reference< lang::XMultiComponentFactory > xSMgr( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
37 + uno::Reference< beans::XPropertySet > xProps( xSMgr, uno::UNO_QUERY_THROW );
38 + uno::Reference< uno::XComponentContext > xCtx( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW );
39 + uno::Reference<table::XCellRange> xCellRange = ScCellRangeObj::CreateRangeFromDoc( pDok, aRange );
40 + // hmm probably better not to have to include the vba generated headers
41 + // here, but... if they ever become always available certainly the
42 + // line below is more coder friendly
43 + //xRange = ooo::vba::excel::Range::createRangeFromXCellRange( xCtx , uno::Reference< ooo::vba::XHelperInterface >(), xCellRange );
44 + uno::Sequence< uno::Any > aArgs(2);
45 + aArgs[0] = uno::Any( uno::Reference< uno::XInterface >() ); // dummy parent
46 + aArgs[1] = uno::Any( xCellRange );
47 + xVBARange = xSMgr->createInstanceWithArgumentsAndContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Range") ), aArgs, xCtx );
48 + if ( xVBARange.is() )
49 + {
50 + String sDummy(RTL_CONSTASCII_USTRINGPARAM("A-Range") );
51 + SbxObjectRef aObj = GetSbUnoObject( sDummy, uno::Any( xVBARange ) );
52 + SetSbUnoObjectDfltPropName( aObj );
53 + bOk = pPar->PutObject( aObj );
54 + }
55 + }
56 + catch( uno::Exception& )
57 + {
58 + }
59 + return bOk;
61 void ScInterpreter::ScMacro()
63 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "Eike.Rathke@sun.com", "ScInterpreter::ScMacro" );
64 @@ -2542,6 +2576,7 @@ void ScInterpreter::ScMacro()
66 SbMethod* pMethod = (SbMethod*)pVar;
67 SbModule* pModule = pMethod->GetModule();
68 + bool bUseVBAObjects = pModule->IsVBACompat();
69 SbxObject* pObject = pModule->GetParent();
70 DBG_ASSERT(pObject->IsA(TYPE(StarBASIC)), "Kein Basic gefunden!");
71 String aMacroStr = pObject->GetName();
72 @@ -2551,7 +2586,13 @@ void ScInterpreter::ScMacro()
73 aMacroStr += pMethod->GetName();
74 String aBasicStr;
75 if (pObject->GetParent())
76 + {
77 aBasicStr = pObject->GetParent()->GetName(); // Dokumentenbasic
78 + const SfxFilter* pFilter = NULL;
79 + SfxMedium* pMedium = pDok->GetDocumentShell()->GetMedium();
80 + if ( pMedium )
81 + pFilter = pMedium->GetFilter();
82 + }
83 else
84 aBasicStr = SFX_APP()->GetName(); // Applikationsbasic
86 @@ -2575,7 +2616,13 @@ void ScInterpreter::ScMacro()
88 ScAddress aAdr;
89 PopSingleRef( aAdr );
90 - bOk = SetSbxVariable( pPar, aAdr );
91 + if ( bUseVBAObjects )
92 + {
93 + ScRange aRange( aAdr );
94 + bOk = lcl_setVBARange( aRange, pDok, pPar );
95 + }
96 + else
97 + bOk = SetSbxVariable( pPar, aAdr );
99 break;
100 case svDoubleRef:
101 @@ -2594,24 +2641,32 @@ void ScInterpreter::ScMacro()
103 else
105 - SbxDimArrayRef refArray = new SbxDimArray;
106 - refArray->AddDim32( 1, nRow2 - nRow1 + 1 );
107 - refArray->AddDim32( 1, nCol2 - nCol1 + 1 );
108 - ScAddress aAdr( nCol1, nRow1, nTab1 );
109 - for( SCROW nRow = nRow1; bOk && nRow <= nRow2; nRow++ )
111 - aAdr.SetRow( nRow );
112 - INT32 nIdx[ 2 ];
113 - nIdx[ 0 ] = nRow-nRow1+1;
114 - for( SCCOL nCol = nCol1; bOk && nCol <= nCol2; nCol++ )
116 - aAdr.SetCol( nCol );
117 - nIdx[ 1 ] = nCol-nCol1+1;
118 - SbxVariable* p = refArray->Get32( nIdx );
119 - bOk = SetSbxVariable( p, aAdr );
120 + if ( bUseVBAObjects )
122 + ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
123 + bOk = lcl_setVBARange( aRange, pDok, pPar );
125 + else
127 + SbxDimArrayRef refArray = new SbxDimArray;
128 + refArray->AddDim32( 1, nRow2 - nRow1 + 1 );
129 + refArray->AddDim32( 1, nCol2 - nCol1 + 1 );
130 + ScAddress aAdr( nCol1, nRow1, nTab1 );
131 + for( SCROW nRow = nRow1; bOk && nRow <= nRow2; nRow++ )
133 + aAdr.SetRow( nRow );
134 + INT32 nIdx[ 2 ];
135 + nIdx[ 0 ] = nRow-nRow1+1;
136 + for( SCCOL nCol = nCol1; bOk && nCol <= nCol2; nCol++ )
138 + aAdr.SetCol( nCol );
139 + nIdx[ 1 ] = nCol-nCol1+1;
140 + SbxVariable* p = refArray->Get32( nIdx );
141 + bOk = SetSbxVariable( p, aAdr );
144 + pPar->PutObject( refArray );
146 - pPar->PutObject( refArray );
149 break;
150 --- basic/inc/basic/sbmod.hxx.old 2009-04-02 10:49:18.000000000 +0000
151 +++ basic/inc/basic/sbmod.hxx 2009-04-06 16:41:58.000000000 +0000
152 @@ -66,6 +66,7 @@ protected:
153 SbiImage* pImage; // das Image
154 SbiBreakpoints* pBreaks; // Breakpoints
155 SbClassData* pClassData;
156 + bool mbVBACompat;
158 void StartDefinitions();
159 SbMethod* GetMethod( const String&, SbxDataType );
160 @@ -126,6 +127,7 @@ public:
161 BOOL LoadBinaryData( SvStream& );
162 BOOL ExceedsLegacyModuleSize();
163 void fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg = NULL ) const;
164 + bool IsVBACompat() { return mbVBACompat; }
167 #ifndef __SB_SBMODULEREF_HXX
168 --- basic/source/classes/sbxmod.cxx.old 2009-04-02 10:49:17.000000000 +0000
169 +++ basic/source/classes/sbxmod.cxx 2009-04-06 16:41:58.000000000 +0000
170 @@ -92,7 +92,7 @@ SV_IMPL_VARARR(HighlightPortions, Highli
172 SbModule::SbModule( const String& rName )
173 : SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("StarBASICModule") ) ),
174 - pImage( NULL ), pBreaks( NULL ), pClassData( NULL )
175 + pImage( NULL ), pBreaks( NULL ), pClassData( NULL ), mbVBACompat( false )
177 SetName( rName );
178 SetFlag( SBX_EXTSEARCH | SBX_GBLSEARCH );
179 @@ -399,8 +399,9 @@ void SbModule::SetSource32( const ::rtl:
180 if( eCurTok == OPTION )
182 eCurTok = aTok.Next();
183 + mbVBACompat = ( eCurTok == VBASUPPORT ) && ( aTok.Next() == NUMBER ) && ( aTok.GetDbl()== 1 );
184 if( eCurTok == COMPATIBLE
185 - || ( ( eCurTok == VBASUPPORT ) && ( aTok.Next() == NUMBER ) && ( aTok.GetDbl()== 1 ) ) )
186 + || mbVBACompat )
187 aTok.SetCompatible( true );
190 --- basic/source/classes/sbunoobj.cxx.old 2009-04-02 10:49:17.000000000 +0000
191 +++ basic/source/classes/sbunoobj.cxx 2009-04-06 16:41:58.000000000 +0000
192 @@ -153,6 +153,21 @@ SbxVariable* getDefaultProp( SbxVariable
193 return pDefaultProp;
196 +void SetSbUnoObjectDfltPropName( SbxObject* pObj )
198 + SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,(SbxObject*) pObj);
199 + if ( pUnoObj )
201 + String sDfltPropName;
203 + if ( SbUnoObject::getDefaultPropName( pUnoObj, sDfltPropName ) )
205 + OSL_TRACE("SetSbUnoObjectDfltPropName setting dflt prop for %s", rtl::OUStringToOString( pObj->GetName(), RTL_TEXTENCODING_UTF8 ).getStr() );
206 + pUnoObj->SetDfltProperty( sDfltPropName );
211 Reference< XComponentContext > getComponentContext_Impl( void )
213 static Reference< XComponentContext > xContext;
214 --- basic/inc/basic/sbuno.hxx.old 2009-04-02 10:49:18.000000000 +0000
215 +++ basic/inc/basic/sbuno.hxx 2009-04-06 16:41:58.000000000 +0000
216 @@ -41,6 +41,7 @@ SbxObjectRef GetSbUnoObject( const Strin
218 // Force creation of all properties for debugging
219 void createAllObjectProperties( SbxObject* pObj );
220 +void SetSbUnoObjectDfltPropName( SbxObject* pObj );
222 ::com::sun::star::uno::Any sbxToUnoValue( SbxVariable* pVar );