diff --git a/.gitignore b/.gitignore index 18754d0a0e7..cc9b9284c16 100644 --- a/.gitignore +++ b/.gitignore @@ -104,6 +104,9 @@ main/winaccessibility/source/UAccCOMIDL/dlldata.c # claude .claude/ +# Visual Studio (not VS Code) +.vs/ + # bazel bazel-* user.bazelrc diff --git a/main/basic/source/classes/sb.cxx b/main/basic/source/classes/sb.cxx index 11350c1f88d..4962e08152c 100644 --- a/main/basic/source/classes/sb.cxx +++ b/main/basic/source/classes/sb.cxx @@ -449,6 +449,19 @@ SbxObject* SbiFactory::CreateObject( const String& rClass ) catch( Exception& ) {} } + else + if( rClass.EqualsIgnoreCaseAscii( "Scripting.Dictionary" ) ) + { + try + { + Reference< XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW ); + ::rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.scripting.Dictionary" ) ); + Reference< XInterface > xInterface( xFactory->createInstance( aServiceName ), UNO_SET_THROW ); + return new SbUnoObject( aServiceName, uno::makeAny( xInterface ) ); + } + catch( Exception& ) + {} + } return NULL; } diff --git a/main/basic/source/classes/sbunoobj.cxx b/main/basic/source/classes/sbunoobj.cxx index 65093db8079..03b4fcda8bd 100644 --- a/main/basic/source/classes/sbunoobj.cxx +++ b/main/basic/source/classes/sbunoobj.cxx @@ -2397,6 +2397,49 @@ void SbUnoObject::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, } GetSbData()->bBlockCompilerError = sal_False; // #106433 Unblock compiler errors } + else if( pHint->GetId() == SBX_HINT_DATACHANGED ) + { + if( bInvocation && pParams && mxInvocation.is() ) + { + sal_uInt32 nParamCount = pParams ? ((sal_uInt32)pParams->Count() - 1) : 0; + Sequence< Any > args( nParamCount + 1 ); + Any* pAnyArgs = args.getArray(); + bool bBlockConversionToSmallestType = pINST->IsCompatibility(); + + for( sal_uInt32 i = 0 ; i < nParamCount ; i++ ) + pAnyArgs[i] = sbxToUnoValueImpl( pParams->Get( (sal_uInt16)(i+1) ), + bBlockConversionToSmallestType ); + + pAnyArgs[nParamCount] = sbxToUnoValueImpl( pVar, bBlockConversionToSmallestType ); + + GetSbData()->bBlockCompilerError = sal_True; // #106433 Block compiler errors for API calls + try + { + Sequence< sal_Int16 > OutParamIndex; + Sequence< Any > OutParam; + Any aRetAny = mxInvocation->invoke( pMeth->GetName(), args, OutParamIndex, OutParam ); + + const sal_Int16* pIndices = OutParamIndex.getConstArray(); + sal_uInt32 nLen = OutParamIndex.getLength(); + if( nLen ) + { + const Any* pNewValues = OutParam.getConstArray(); + for( sal_uInt32 j = 0 ; j < nLen ; j++ ) + { + sal_Int16 iTarget = pIndices[ j ]; + if( iTarget >= (sal_Int16)nParamCount ) + break; + unoToSbxValue( (SbxVariable*)pParams->Get( (sal_uInt16)(j+1) ), pNewValues[ j ] ); + } + } + } + catch( const Exception& ) + { + implHandleAnyException( ::cppu::getCaughtException() ); + } + GetSbData()->bBlockCompilerError = sal_False; // #106433 Unblock compiler errors + } + } } else SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType ); diff --git a/main/basic/source/comp/dim.cxx b/main/basic/source/comp/dim.cxx index d1c38d168f7..3003685007a 100644 --- a/main/basic/source/comp/dim.cxx +++ b/main/basic/source/comp/dim.cxx @@ -612,7 +612,7 @@ void SbiParser::DefType( sal_Bool bPrivate ) { // Dimension the target array - for ( short i=0; iGetSize();++i ) + for ( short i=0; iGetSize();++i ) { sal_Int32 ub = -1; sal_Int32 lb = nBase; @@ -626,8 +626,9 @@ void SbiParser::DefType( sal_Bool bPrivate ) lb = ub; ub = pNode->GetNumber(); } - else if ( !bCompatible ) - ub += nBase; + else if ( !bCompatible ) + ub += nBase; + // VBA: lb = nBase (respects Option Base), ub = declared value pArray->AddDim32( lb, ub ); } pArray->setHasFixedSize( true ); diff --git a/main/basic/source/comp/parser.cxx b/main/basic/source/comp/parser.cxx index 5dfd4ce4752..914825a84f4 100644 --- a/main/basic/source/comp/parser.cxx +++ b/main/basic/source/comp/parser.cxx @@ -105,6 +105,11 @@ static SbiStatement StmntTable [] = { { WEND, &SbiParser::BadBlock, N, Y, }, // WEND { WITH, &SbiParser::With, N, Y, }, // WITH { WRITE, &SbiParser::Write, N, Y, }, // WRITE +{ PP_IF, &SbiParser::PPIf, N, Y, }, // #IF +{ PP_ELSEIF, &SbiParser::PPIf, N, Y, }, // #ELSEIF +{ PP_ELSE, &SbiParser::NoIf, N, Y, }, // #ELSE +{ PP_ENDIF, &SbiParser::NoIf, N, Y, }, // #ENDIF +{ PP_CONST, &SbiParser::PPConst, Y, Y, }, // #CONST { NIL, NULL, N, N } }; @@ -863,4 +868,315 @@ void SbiParser::ErrorStmnt() aGen.Gen( _ERROR ); } -/* vim: set noet sw=4 ts=4: */ +// MS Excel VBA: #If conditional compilation directive. +// Status: implemented - supports #If, #ElseIf, #Else, #End If +// Supports simple expressions: True, False, identifier references, Not, = +void SbiParser::PPIf() +{ + // Parse condition: evaluate simple constant expressions + bool bCondition = evaluatePPCondition(); + + // Expect "Then" (optional in VBA, but expected in practice) + if( eCurTok == THEN ) + Next(); + + // If condition is true, parse the block until #ElseIf/#Else/#End If + // If false, skip the block + SbiToken eTok = Peek(); + while( !bAbort && !IsEof() && + !( eTok == PP_ELSEIF || eTok == PP_ELSE || eTok == PP_ENDIF ) ) + { + if( bCondition ) + Parse(); + else + skipStatement(); + eTok = Peek(); + } + + if( bCondition ) + { + // We're in the true branch - skip any additional branches + if( eTok == PP_ELSE ) + { + Next(); // consume #Else + skipUntilEndIf(); + } + else if( eTok == PP_ELSEIF ) + { + Next(); // consume #ElseIf + skipUntilEndIf(); + } + else if( eTok == PP_ENDIF ) + { + Next(); // consume #End If + } + } + else + { + // We're in the false branch - check if there's an #Else or #ElseIf + if( eTok == PP_ELSEIF ) + { + Next(); // consume #ElseIf + PPIf(); // recursively handle the elseif branch + return; + } + else if( eTok == PP_ELSE ) + { + Next(); // consume #Else + // Parse the else block + SbiToken eTok2 = Peek(); + while( !bAbort && !IsEof() && !( eTok2 == PP_ENDIF ) ) + { + Parse(); + eTok2 = Peek(); + } + if( eTok2 == PP_ENDIF ) + Next(); // consume #End If + } + else if( eTok == PP_ENDIF ) + { + Next(); // consume #End If + } + } +} + +// Helper: Check if identifier is a predefined VBA constant +bool SbiParser::isVBAPredefinedConst( const String& aName, bool& bValue ) +{ + if( aName.EqualsIgnoreCaseAscii( "VBA7" ) ) + { + bValue = true; + return true; + } + if( aName.EqualsIgnoreCaseAscii( "Win32" ) || + aName.EqualsIgnoreCaseAscii( "Win64" ) ) + { + bValue = false; + return true; + } + if( aName.EqualsIgnoreCaseAscii( "Win16" ) || + aName.EqualsIgnoreCaseAscii( "Mac" ) || + aName.EqualsIgnoreCaseAscii( "Win" ) ) + { + bValue = false; + return true; + } + return false; +} + +// Helper: Evaluate a single term in a #If condition (no And/Or). +// Handles: True, False, identifier, Not expr, expr = expr, numbers +bool SbiParser::evaluatePPTerm() +{ + Peek(); + bool bResult = false; + bool bNegate = false; + + // Handle "Not" + if( aSym.EqualsIgnoreCaseAscii( "Not" ) ) + { + bNegate = true; + Next(); + Peek(); + } + + // Get the left operand + if( aSym.EqualsIgnoreCaseAscii( "True" ) ) + { + bResult = true; + Next(); + Peek(); + } + else if( aSym.EqualsIgnoreCaseAscii( "False" ) ) + { + bResult = false; + Next(); + Peek(); + } + else if( eCurTok == SYMBOL ) + { + // Check if it's a known constant + String aName = aSym; + Next(); + Peek(); + + // Check for comparison: identifier = value + if( eCurTok == EQ ) + { + Next(); // consume = + Peek(); + // Resolve left-hand value + bool bLVal = false; + if( maConstMap.count( aName ) > 0 ) + bLVal = maConstMap[ aName ]; + else if( !isVBAPredefinedConst( aName, bLVal ) ) + { + // Unknown identifier - try to evaluate as expression + SbiExpression aLeftExpr( this ); + } + // Get the right operand + if( eCurTok == SYMBOL ) + { + String aVal = aSym; + Next(); + // Resolve right-hand value + bool bRVal = false; + if( aVal.EqualsIgnoreCaseAscii( "True" ) ) + bRVal = true; + else if( aVal.EqualsIgnoreCaseAscii( "False" ) ) + bRVal = false; + else if( maConstMap.count( aVal ) > 0 ) + bRVal = maConstMap[ aVal ]; + else + isVBAPredefinedConst( aVal, bRVal ); + bResult = (bLVal == bRVal); + } + else if( eCurTok == NUMBER ) + { + bResult = (bLVal == (nVal != 0.0)); + Next(); + } + } + else if( eCurTok == THEN ) + { + // Just a constant: #If DEBUG Then + if( maConstMap.count( aName ) > 0 ) + bResult = maConstMap[ aName ]; + else + isVBAPredefinedConst( aName, bResult ); + } + else + { + // End of expression or other token - use the constant directly + if( maConstMap.count( aName ) > 0 ) + bResult = maConstMap[ aName ]; + else + isVBAPredefinedConst( aName, bResult ); + } + } + else if( eCurTok == NUMBER ) + { + bResult = (nVal != 0.0); + Next(); + Peek(); + } + else + { + // Unknown expression - parse and consume it + SbiExpression aExpr( this ); + bResult = true; // unknown, default to true + } + + if( bNegate ) + bResult = !bResult; + + return bResult; +} + +// Helper: Evaluate a conditional compilation expression. +// Supports: True, False, identifier, Not, And, Or, = comparisons, numbers +bool SbiParser::evaluatePPCondition() +{ + bool bResult = evaluatePPTerm(); + + // Handle And/Or operators for compound expressions + while( eCurTok == AND || eCurTok == OR ) + { + bool bIsAnd = (eCurTok == AND); + Next(); // consume And/Or + bool bTerm = evaluatePPTerm(); + if( bIsAnd ) + bResult = bResult && bTerm; + else + bResult = bResult || bTerm; + } + + return bResult; +} + +// Helper: Skip statements without generating code +void SbiParser::skipStatement() +{ + // Simple statement skip - consume tokens until EOLN + while( !bAbort && !IsEos() && !IsEof() ) + Next(); + Next(); // consume EOLN +} + +// MS Excel VBA: #Const conditional compilation constant declaration. +// Status: implemented - stores name=value in the conditional compilation map +void SbiParser::PPConst() +{ + // #Const name = value + // Parse: name + Peek(); + if( eCurTok != SYMBOL ) + { + Error( SbERR_SYMBOL_EXPECTED ); + Next(); + TestToken( ASSIGN ); + return; + } + + String aConstName = aSym; + Next(); + TestToken( ASSIGN ); + Next(); + + // Parse the value - expect True, False, or a number + Peek(); + if( aSym.EqualsIgnoreCaseAscii( "True" ) ) + { + maConstMap[ aConstName ] = true; + Next(); + } + else if( aSym.EqualsIgnoreCaseAscii( "False" ) ) + { + maConstMap[ aConstName ] = false; + Next(); + } + else if( eCurTok == NUMBER ) + { + maConstMap[ aConstName ] = (nVal != 0.0); + Next(); + } + else + { + // Unknown constant value - default to false + maConstMap[ aConstName ] = false; + SbiExpression aExpr( this ); // consume the expression + } + + // Expect end of statement + TestEoln(); +} + +// Helper: Skip all statements until matching #End If +void SbiParser::skipUntilEndIf() +{ + sal_uInt16 nNesting = 0; + SbiToken eTok = Peek(); + while( !bAbort && !IsEof() ) + { + if( eTok == PP_IF ) + { + nNesting++; + Next(); + } + else if( eTok == PP_ENDIF ) + { + if( nNesting == 0 ) + { + Next(); + return; + } + nNesting--; + Next(); + } + else + { + skipStatement(); + } + eTok = Peek(); + } +} diff --git a/main/basic/source/comp/token.cxx b/main/basic/source/comp/token.cxx index 3959127f642..5c89b4732c8 100644 --- a/main/basic/source/comp/token.cxx +++ b/main/basic/source/comp/token.cxx @@ -115,6 +115,7 @@ static TokenTable aTokTable_Basic [] = { // Token-Tabelle: { _IN_, "In" }, { INPUT, "Input" }, // auch INPUT # { TINTEGER, "Integer" }, + { INTERFACE, "Interface" }, { IS, "Is" }, { LET, "Let" }, { LIB, "Lib" }, @@ -184,6 +185,11 @@ static TokenTable aTokTable_Basic [] = { // Token-Tabelle: { WITHEVENTS, "WithEvents" }, { WRITE, "Write" }, // auch WRITE # { XOR, "Xor" }, + { PP_IF, "#If" }, + { PP_ELSEIF, "#ElseIf" }, + { PP_ELSE, "#Else" }, + { PP_ENDIF, "#End If" }, + { PP_CONST, "#Const" }, { NIL, "" } }; @@ -353,8 +359,8 @@ TokenTable aTokTable_Java [] = { // Token-Tabelle: // #i109076 TokenLabelInfo::TokenLabelInfo( void ) { - m_pTokenCanBeLabelTab = new bool[VBASUPPORT+1]; - for( int i = 0 ; i <= VBASUPPORT ; ++i ) + m_pTokenCanBeLabelTab = new bool[INTERFACE+1]; + for( int i = 0 ; i <= INTERFACE ; ++i ) m_pTokenCanBeLabelTab[i] = false; // Token accepted as label by VBA @@ -502,6 +508,47 @@ SbiToken SbiTokenizer::Next() { bEos = sal_True; return eCurTok = EOLN; } + + // MS Excel VBA: Handle #If, #ElseIf, #Else, #End If, #Const preprocessor directives + if( IsHash() && bVBASupportOn && eScanType == SbxVARIANT && bSymbol ) + { + if( aSym.EqualsIgnoreCaseAscii( "If" ) ) + return eCurTok = PP_IF; + else if( aSym.EqualsIgnoreCaseAscii( "ElseIf" ) ) + return eCurTok = PP_ELSEIF; + else if( aSym.EqualsIgnoreCaseAscii( "Else" ) ) + return eCurTok = PP_ELSE; + else if( aSym.EqualsIgnoreCaseAscii( "End" ) ) + { + // #End If - check if next token is "If" + sal_uInt16 nOldLine = nLine; + sal_uInt16 nOldCol = nCol; + sal_uInt16 nOldCol1 = nCol1; + sal_uInt16 nOldCol2 = nCol2; + String aOldSym = aSym; + SaveLine(); + + eCurTok = Peek(); + if( eCurTok == IF ) + { + Next(); + nCol1 = nOldCol1; + bEos = sal_False; + return eCurTok = PP_ENDIF; + } + // Not #End If - restore and return as END + ePush = NIL; + nLine = nOldLine; + nCol = nOldCol; + nCol2 = nOldCol2; + aSym = aOldSym; + RestoreLine(); + return eCurTok = END; + } + else if( aSym.EqualsIgnoreCaseAscii( "Const" ) ) + return eCurTok = PP_CONST; + } + bEos = sal_False; // Zahl? diff --git a/main/basic/source/inc/parser.hxx b/main/basic/source/inc/parser.hxx index c7c1322ea20..c4c9c16f7fa 100644 --- a/main/basic/source/inc/parser.hxx +++ b/main/basic/source/inc/parser.hxx @@ -30,6 +30,7 @@ #include +#include typedef ::std::vector< String > StringVector; struct SbiParseStack; @@ -139,6 +140,16 @@ public: void While(); // WHILE/WEND void With(); // WITH void Write(); // WRITE + void PPIf(); // #If (VBA conditional compilation) + void PPConst(); // #Const (VBA conditional compilation) + bool evaluatePPCondition(); // Evaluate #If condition expression + bool evaluatePPTerm(); // Evaluate single term (no And/Or) + bool isVBAPredefinedConst( const String& aName, bool& bValue ); // VBA7, Mac, etc. + void skipStatement(); // Skip a statement without generating code + void skipUntilEndIf(); // Skip statements until matching #End If + + // Conditional compilation constants map + std::map maConstMap; }; diff --git a/main/basic/source/inc/token.hxx b/main/basic/source/inc/token.hxx index 9d0d60ab0c1..56bb14fea17 100644 --- a/main/basic/source/inc/token.hxx +++ b/main/basic/source/inc/token.hxx @@ -68,7 +68,7 @@ enum SbiToken { IF, _IN_, INPUT, LET, LINE, LINEINPUT, LOCAL, LOOP, LPRINT, LSET, NAME, NEW, NEXT, - ON, OPEN, OPTION, IMPLEMENTS, + ON, OPEN, OPTION, IMPLEMENTS, INTERFACE, PRINT, PRIVATE, PROPERTY, PUBLIC, REDIM, REM, RESUME, RETURN, RSET, SELECT, SET, SHARED, STATIC, STEP, STOP, SUB, @@ -109,6 +109,8 @@ enum SbiToken { JS_PLUS, JS_MINUS, JS_MUL, JS_DIV, JS_MOD, JS_LOG_NOT, JS_BIT_NOT, JS_INC, JS_DEC, JS_LPAREN, JS_RPAREN, JS_LINDEX, JS_RINDEX , VBASUPPORT + // Conditional compilation preprocessor directives (VBA compatibility) + , PP_IF, PP_ELSEIF, PP_ELSE, PP_ENDIF, PP_CONST }; #ifdef SbiTokenSHAREDTMPUNDEF diff --git a/main/basic/source/runtime/methods.cxx b/main/basic/source/runtime/methods.cxx index ed62ba004c5..387aa19c400 100644 --- a/main/basic/source/runtime/methods.cxx +++ b/main/basic/source/runtime/methods.cxx @@ -3629,12 +3629,23 @@ RTLFUNC(TypeName) StarBASIC::Error( SbERR_BAD_ARGUMENT ); else { - SbxDataType eType = rPar.Get(1)->GetType(); - sal_Bool bIsArray = ( ( eType & SbxARRAY ) != 0 ); - String aRetStr = getBasicTypeName( eType ); - if( bIsArray ) - aRetStr.AppendAscii( "()" ); - rPar.Get(0)->PutString( aRetStr ); + SbxVariable* pVar = rPar.Get(1); + SbxDataType eType = pVar->GetType(); + + // #i129350: In VBA compatibility mode, return "Nothing" for null objects + sal_Bool bVBA = SbiRuntime::isVBAEnabled(); + if( bVBA && eType == SbxOBJECT && !pVar->GetObject() ) + { + rPar.Get(0)->PutString( String( RTL_CONSTASCII_USTRINGPARAM("Nothing") ) ); + } + else + { + sal_Bool bIsArray = ( ( eType & SbxARRAY ) != 0 ); + String aRetStr = getBasicTypeName( eType ); + if( bIsArray ) + aRetStr.AppendAscii( "()" ); + rPar.Get(0)->PutString( aRetStr ); + } } } diff --git a/main/basic/source/runtime/methods1.cxx b/main/basic/source/runtime/methods1.cxx index 9fa279315cf..fbd4e31616c 100644 --- a/main/basic/source/runtime/methods1.cxx +++ b/main/basic/source/runtime/methods1.cxx @@ -768,7 +768,10 @@ RTLFUNC(Array) sal_uInt16 nArraySize = rPar.Count() - 1; // Option Base zunaechst ignorieren (kennt leider nur der Compiler) - bool bIncIndex = (IsBaseIndexOne() && SbiRuntime::isVBAEnabled() ); + // #i129350: In VBA mode, Array() is always 0-based per VBA spec + // (Option Base is not a VBA feature) + bool bVBAEnabled = SbiRuntime::isVBAEnabled(); + bool bIncIndex = (IsBaseIndexOne() && !bVBAEnabled) ; if( nArraySize ) { if ( bIncIndex ) diff --git a/main/basic/source/runtime/step1.cxx b/main/basic/source/runtime/step1.cxx index cd3d2fc37b2..be5e42ffd18 100644 --- a/main/basic/source/runtime/step1.cxx +++ b/main/basic/source/runtime/step1.cxx @@ -556,6 +556,9 @@ void SbiRuntime::StepBASED( sal_uInt32 nOp1 ) // #109275 Check compatibility mode bool bCompatible = ((nOp1 & 0x8000) != 0); sal_uInt16 uBase = static_cast(nOp1 & 1); // Can only be 0 or 1 + // VBA respects Option Base for implicit array bounds: + // Dim arr(n) with Option Base 0 -> 0 To n, with Option Base 1 -> 1 To n + // (only VBA's Array() function is always 0-based regardless of Option Base) p1->PutInteger( uBase ); if( !bCompatible ) x2->Compute( SbxPLUS, *p1 ); diff --git a/main/basic/source/sbx/sbxscan.cxx b/main/basic/source/sbx/sbxscan.cxx index 699382ac5e0..313b673d251 100644 --- a/main/basic/source/sbx/sbxscan.cxx +++ b/main/basic/source/sbx/sbxscan.cxx @@ -68,16 +68,29 @@ void ImpGetIntntlSep( sal_Unicode& rcDecimalSep, sal_Unicode& rcThousandSep ) SbxError ImpScan( const ::rtl::OUString& rWSrc, double& nVal, SbxDataType& rType, sal_uInt16* pLen, sal_Bool bAllowIntntl, sal_Bool bOnlyIntntl ) { - ::rtl::OString aBStr( ::rtl::OUStringToOString( rWSrc, RTL_TEXTENCODING_ASCII_US ) ); + // Handle non-breaking space (U+00A0) as thousands separator. + // The ASCII US conversion below would replace NBSP with '?', + // causing locale-aware number parsing to fail (e.g. "1 000,5" in fr_FR). + sal_Unicode cDecimalSep, cThousandSep = 0; + if( bAllowIntntl || bOnlyIntntl ) + { + ImpGetIntntlSep( cDecimalSep, cThousandSep ); + if( cThousandSep == 0xA0 ) // NBSP + cThousandSep = (sal_Unicode)' '; + } + + // Replace NBSP in source so the ASCII US conversion preserves it as ' ' + rtl::OUString aUSrc = rWSrc; + if( cThousandSep == ' ' ) + aUSrc = aUSrc.replace( sal_Unicode(0xA0), ' ' ); + ::rtl::OString aBStr( ::rtl::OUStringToOString( aUSrc, RTL_TEXTENCODING_ASCII_US ) ); // Bei International Komma besorgen char cIntntlComma, cIntntl1000; char cNonIntntlComma = '.'; - sal_Unicode cDecimalSep, cThousandSep = 0; if( bAllowIntntl || bOnlyIntntl ) { - ImpGetIntntlSep( cDecimalSep, cThousandSep ); cIntntlComma = (char)cDecimalSep; cIntntl1000 = (char)cThousandSep; } diff --git a/main/oovbaapi/UnoApi_oovbaapi.mk b/main/oovbaapi/UnoApi_oovbaapi.mk index 7f19395b6c5..df3e3e35f05 100644 --- a/main/oovbaapi/UnoApi_oovbaapi.mk +++ b/main/oovbaapi/UnoApi_oovbaapi.mk @@ -74,6 +74,10 @@ $(eval $(call gb_UnoApiTarget_add_idlfiles,oovbaapi,\ oovbaapi/ooo/vba/XDocumentsBase \ oovbaapi/ooo/vba/XErrObject \ oovbaapi/ooo/vba/XExecutableDialog \ + oovbaapi/ooo/vba/XFileDialog \ + oovbaapi/ooo/vba/XFileDialogSelectedItems \ + oovbaapi/ooo/vba/XFileSearch \ + oovbaapi/ooo/vba/XFoundFiles \ oovbaapi/ooo/vba/XFontBase \ oovbaapi/ooo/vba/XGlobalsBase \ oovbaapi/ooo/vba/XHelperInterface \ @@ -120,6 +124,7 @@ $(eval $(call gb_UnoApiTarget_add_idlfiles,oovbaapi,\ oovbaapi/ooo/vba/excel/XPivotCache \ oovbaapi/ooo/vba/excel/XPivotTable \ oovbaapi/ooo/vba/excel/XPivotTables \ + oovbaapi/ooo/vba/excel/XQueryTable \ oovbaapi/ooo/vba/excel/XRange \ oovbaapi/ooo/vba/excel/XSeries \ oovbaapi/ooo/vba/excel/XSeriesCollection \ @@ -137,6 +142,7 @@ $(eval $(call gb_UnoApiTarget_add_idlfiles,oovbaapi,\ oovbaapi/ooo/vba/excel/XWorksheet \ oovbaapi/ooo/vba/excel/XWorksheetFunction \ oovbaapi/ooo/vba/excel/XWorksheets \ + oovbaapi/ooo/vba/scripting/XDictionary \ oovbaapi/ooo/vba/excel/XlBuildInDialog \ oovbaapi/ooo/vba/msforms/XCheckBox \ oovbaapi/ooo/vba/msforms/XColorFormat \ diff --git a/main/oovbaapi/ooo/vba/XFileDialog.idl b/main/oovbaapi/ooo/vba/XFileDialog.idl new file mode 100644 index 00000000000..132edad9a43 --- /dev/null +++ b/main/oovbaapi/ooo/vba/XFileDialog.idl @@ -0,0 +1,46 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef __ooo_vba_XFileDialog_idl__ +#define __ooo_vba_XFileDialog_idl__ + +#include +#include + +module ooo { module vba { + +interface XFileDialogSelectedItems; + +interface XFileDialog +{ + interface ::ooo::vba::XHelperInterface; + + [attribute] long MsoFileDialogType; + [attribute] string Title; + [attribute] boolean AllowMultiSelect; + [attribute, readonly] XFileDialogSelectedItems SelectedItems; + + long Show(); +}; + +}; }; + +#endif diff --git a/main/oovbaapi/ooo/vba/XFileDialogSelectedItems.idl b/main/oovbaapi/ooo/vba/XFileDialogSelectedItems.idl new file mode 100644 index 00000000000..dab01a84566 --- /dev/null +++ b/main/oovbaapi/ooo/vba/XFileDialogSelectedItems.idl @@ -0,0 +1,36 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef __ooo_vba_XFileDialogSelectedItems_idl__ +#define __ooo_vba_XFileDialogSelectedItems_idl__ + +#include +#include + +module ooo { module vba { + +interface XFileDialogSelectedItems : XCollection +{ +}; + +}; }; + +#endif diff --git a/main/oovbaapi/ooo/vba/XFileSearch.idl b/main/oovbaapi/ooo/vba/XFileSearch.idl new file mode 100644 index 00000000000..195c369b0cf --- /dev/null +++ b/main/oovbaapi/ooo/vba/XFileSearch.idl @@ -0,0 +1,48 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef __ooo_vba_XFileSearch_idl__ +#define __ooo_vba_XFileSearch_idl__ + +#include +#include + +module ooo { module vba { + +interface XFoundFiles; + +interface XFileSearch +{ + interface ::ooo::vba::XHelperInterface; + + [attribute] string FileName; + [attribute] string LookIn; + [attribute] boolean SearchSubFolders; + [attribute] boolean MatchTextExactly; + [attribute, readonly] XFoundFiles FoundFiles; + + long Execute(); + void NewSearch(); +}; + +}; }; + +#endif diff --git a/main/oovbaapi/ooo/vba/XFoundFiles.idl b/main/oovbaapi/ooo/vba/XFoundFiles.idl new file mode 100644 index 00000000000..5e79a9b0d7f --- /dev/null +++ b/main/oovbaapi/ooo/vba/XFoundFiles.idl @@ -0,0 +1,36 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef __ooo_vba_XFoundFiles_idl__ +#define __ooo_vba_XFoundFiles_idl__ + +#include + +module ooo { module vba { + +interface XFoundFiles : XCollection +{ + string File( [in] long Index ); +}; + +}; }; + +#endif diff --git a/main/oovbaapi/ooo/vba/excel/XApplication.idl b/main/oovbaapi/ooo/vba/excel/XApplication.idl index f5a288704be..33ce7effd48 100644 --- a/main/oovbaapi/ooo/vba/excel/XApplication.idl +++ b/main/oovbaapi/ooo/vba/excel/XApplication.idl @@ -27,6 +27,8 @@ #include #include #include +#include +#include module ooo { module vba { module excel { @@ -66,6 +68,9 @@ interface XApplication [attribute, readonly] string TemplatesPath; [attribute, readonly] string PathSeparator; + ::ooo::vba::XFileDialog FileDialog( [in] long MsoFileDialogType ); + [attribute, readonly] ::ooo::vba::XFileSearch FileSearch; + //any CommandBars( [in] any Index ); any Workbooks( [in] any Index ); any Worksheets( [in] any Index ); @@ -88,6 +93,13 @@ interface XApplication any Caller( [in] any Index ); any GetOpenFilename( [in] any FileFilter, [in] any FilterIndex, [in] any Title, [in] any ButtonText, [in] any MultiSelect ); any GetSaveAsFilename( [in] any InitialFileName, [in] any FileFilter, [in] any FilterIndex, [in] any Title, [in] any ButtonText ); + double CountA( [in] any arg1 ); + any International( [in] long Index ); + void Undo(); + any Run( [in] string MacroName, [in] any Arg1, [in] any Arg2, [in] any Arg3, [in] any Arg4, [in] any Arg5 ); + double InchesToPoints( [in] double Inches ); + void setSheetsInNewWorkbook( [in] long SheetsInNewWorkbook ); + long getSheetsInNewWorkbook(); }; }; }; }; diff --git a/main/oovbaapi/ooo/vba/excel/XQueryTable.idl b/main/oovbaapi/ooo/vba/excel/XQueryTable.idl new file mode 100644 index 00000000000..b5d6293ae44 --- /dev/null +++ b/main/oovbaapi/ooo/vba/excel/XQueryTable.idl @@ -0,0 +1,40 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef __ooo_vba_excel_XQueryTable_idl__ +#define __ooo_vba_excel_XQueryTable_idl__ + +#include +#include + +module ooo { module vba { module excel { + +interface XQueryTable +{ + interface ::ooo::vba::XHelperInterface; + + boolean Refresh( [in] any BackgroundQuery ); + void Delete(); +}; + +}; }; }; + +#endif diff --git a/main/oovbaapi/ooo/vba/excel/XRange.idl b/main/oovbaapi/ooo/vba/excel/XRange.idl index 7934d59407e..8a2cc2290a9 100644 --- a/main/oovbaapi/ooo/vba/excel/XRange.idl +++ b/main/oovbaapi/ooo/vba/excel/XRange.idl @@ -64,6 +64,8 @@ interface XCharacters; interface XBorders; interface XValidation; interface XWorksheet; +interface XFormatConditions; +interface XQueryTable; interface XRange { @@ -74,7 +76,9 @@ interface XRange //interface ::ooo::vba::XHelperInterface; [attribute] any Value; + [attribute] any Value2; [attribute] any Formula; + [attribute] any Formula2; [attribute] any FormulaArray; [attribute] any FormulaR1C1; [attribute, readonly] long Count; @@ -98,6 +102,8 @@ interface XRange [attribute] any Style; [attribute] any AddIndent; [attribute] any ShowDetail; + [attribute, readonly] XFormatConditions FormatConditions; + [attribute, readonly] XQueryTable QueryTable; XComment AddComment( [in] any Text ); void Clear(); diff --git a/main/oovbaapi/ooo/vba/excel/XWorkbook.idl b/main/oovbaapi/ooo/vba/excel/XWorkbook.idl index 8533f77ee86..7e479c20e02 100644 --- a/main/oovbaapi/ooo/vba/excel/XWorkbook.idl +++ b/main/oovbaapi/ooo/vba/excel/XWorkbook.idl @@ -58,6 +58,7 @@ interface XWorkbook : com::sun::star::uno::XInterface any Colors( [in] any Index ) raises (com::sun::star::script::BasicErrorException); long FileFormat() raises (com::sun::star::script::BasicErrorException); void SaveCopyAs( [in] string Filename ); + void SaveAs( [in] any FileName, [in] any FileFormat, [in] any Password, [in] any WriteResPassword, [in] any ReadOnlyRecommended, [in] any CreateBackup ); }; }; }; }; diff --git a/main/oovbaapi/ooo/vba/scripting/XDictionary.idl b/main/oovbaapi/ooo/vba/scripting/XDictionary.idl new file mode 100644 index 00000000000..4c9f952bd56 --- /dev/null +++ b/main/oovbaapi/ooo/vba/scripting/XDictionary.idl @@ -0,0 +1,67 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + + +#ifndef __ooo_vba_scripting_XDictionary_idl__ +#define __ooo_vba_scripting_XDictionary_idl__ + +#ifndef __com_sun_star_uno_XInterface_idl__ +#include +#endif + +#ifndef __ooo_vba_XHelperInterface_idl__ +#include +#endif + +#ifndef __com_sun_star_script_XDefaultMethod_idl__ +#include +#endif + +#ifndef __com_sun_star_script_XInvocation_idl__ +#include +#endif + +#ifndef __com_sun_star_container_XEnumeration_idl__ +#include +#endif + +module ooo { module vba { module scripting { + +interface XDictionary +{ + interface ::ooo::vba::XHelperInterface; + interface ::com::sun::star::script::XDefaultMethod; + + void Add([in] any Key, [in] any Item); + boolean Exists([in] any Key); + any Items(); + any Keys(); + void Remove([in] any Key); + void RemoveAll(); + any Item([in] any Key); + + [attribute] long Count; + [attribute] long CompareMode; +}; + +}; }; }; + +#endif diff --git a/main/sc/Library_vbaobj.mk b/main/sc/Library_vbaobj.mk index a4f61bd3640..68d6e405e0a 100644 --- a/main/sc/Library_vbaobj.mk +++ b/main/sc/Library_vbaobj.mk @@ -122,6 +122,12 @@ $(eval $(call gb_Library_add_exception_objects,vbaobj,\ sc/source/ui/vba/vbaworksheet \ sc/source/ui/vba/vbaworksheets \ sc/source/ui/vba/vbawsfunction \ + sc/source/ui/vba/vbadictionary \ + sc/source/ui/vba/vbafiledialog \ + sc/source/ui/vba/vbafiledialogselecteditems \ + sc/source/ui/vba/vbafilesearch \ + sc/source/ui/vba/vbafoundfiles \ + sc/source/ui/vba/vbaquerytable \ )) # vim: set noet sw=4 ts=4: diff --git a/main/sc/inc/appoptio.hxx b/main/sc/inc/appoptio.hxx index 880319d705d..49c6c545fc7 100644 --- a/main/sc/inc/appoptio.hxx +++ b/main/sc/inc/appoptio.hxx @@ -71,14 +71,16 @@ public: ScLkUpdMode GetLinkMode() const { return eLinkMode ;} void SetLinkMode( ScLkUpdMode nSet ) { eLinkMode = nSet;} - void SetDefaultObjectSizeWidth(sal_Int32 nNew) { nDefaultObjectSizeWidth = nNew; } - sal_Int32 GetDefaultObjectSizeWidth() const { return nDefaultObjectSizeWidth; } - void SetDefaultObjectSizeHeight(sal_Int32 nNew) { nDefaultObjectSizeHeight = nNew; } - sal_Int32 GetDefaultObjectSizeHeight() const { return nDefaultObjectSizeHeight; } + sal_uInt16 GetTabCountInNewSpreadsheet() const { return mnTabCountInNewSpreadsheet; } + void SetTabCountInNewSpreadsheet( sal_uInt16 nNew ) { mnTabCountInNewSpreadsheet = nNew; } void SetShowSharedDocumentWarning( sal_Bool bNew ) { mbShowSharedDocumentWarning = bNew; } sal_Bool GetShowSharedDocumentWarning() const { return mbShowSharedDocumentWarning; } + void SetDefaultObjectSizeWidth(sal_Int32 nNew) { nDefaultObjectSizeWidth = nNew; } + sal_Int32 GetDefaultObjectSizeWidth() const { return nDefaultObjectSizeWidth; } + void SetDefaultObjectSizeHeight(sal_Int32 nNew) { nDefaultObjectSizeHeight = nNew; } + sal_Int32 GetDefaultObjectSizeHeight() const { return nDefaultObjectSizeHeight; } const ScAppOptions& operator= ( const ScAppOptions& rOpt ); @@ -100,6 +102,7 @@ private: sal_Int32 nDefaultObjectSizeWidth; sal_Int32 nDefaultObjectSizeHeight; sal_Bool mbShowSharedDocumentWarning; + sal_uInt16 mnTabCountInNewSpreadsheet; }; diff --git a/main/sc/source/core/tool/appoptio.cxx b/main/sc/source/core/tool/appoptio.cxx index 632c788bb69..ff214f4bc9b 100644 --- a/main/sc/source/core/tool/appoptio.cxx +++ b/main/sc/source/core/tool/appoptio.cxx @@ -109,6 +109,7 @@ void ScAppOptions::SetDefaults() nDefaultObjectSizeHeight = 5000; mbShowSharedDocumentWarning = true; + mnTabCountInNewSpreadsheet = 1; } //------------------------------------------------------------------------ @@ -131,6 +132,7 @@ const ScAppOptions& ScAppOptions::operator=( const ScAppOptions& rCpy ) nDefaultObjectSizeWidth = rCpy.nDefaultObjectSizeWidth; nDefaultObjectSizeHeight = rCpy.nDefaultObjectSizeHeight; mbShowSharedDocumentWarning = rCpy.mbShowSharedDocumentWarning; + mnTabCountInNewSpreadsheet = rCpy.mnTabCountInNewSpreadsheet; return *this; } diff --git a/main/sc/source/ui/vba/helperdecl.hxx b/main/sc/source/ui/vba/helperdecl.hxx index 99406e0a3a8..063d862c0af 100644 --- a/main/sc/source/ui/vba/helperdecl.hxx +++ b/main/sc/source/ui/vba/helperdecl.hxx @@ -19,14 +19,15 @@ * *************************************************************/ - +#ifndef SC_VBA_HELPERDECL_HXX +#define SC_VBA_HELPERDECL_HXX #include #include namespace comphelper { namespace service_decl { template > -struct vba_service_class_ : public serviceimpl_base< vba_detail::OwnServiceImpl, WithArgsT > +struct vba_service_class_ : public serviceimpl_base< detail::OwnServiceImpl, WithArgsT > { typedef serviceimpl_base< detail::OwnServiceImpl, WithArgsT > baseT; /** Default ctor. Implementation class without args, expecting @@ -46,3 +47,5 @@ struct vba_service_class_ : public serviceimpl_base< vba_detail::OwnServiceImpl< } // namespace service_decl } // namespace comphelper + +#endif diff --git a/main/sc/source/ui/vba/service.cxx b/main/sc/source/ui/vba/service.cxx index d684f5a5aa7..6d99e29f10e 100644 --- a/main/sc/source/ui/vba/service.cxx +++ b/main/sc/source/ui/vba/service.cxx @@ -70,6 +70,10 @@ namespace textframe { extern sdecl::ServiceDecl const serviceDecl; } +namespace scripting +{ +extern sdecl::ServiceDecl const serviceDecl; +} extern "C" { @@ -85,10 +89,10 @@ extern "C" registry::XRegistryKey * pRegistryKey ) { OSL_TRACE("In component_getFactory for %s", pImplName ); - void* pRet = component_getFactoryHelper( - pImplName, pServiceManager, pRegistryKey, range::serviceDecl, workbook::serviceDecl, worksheet::serviceDecl, globals::serviceDecl, window::serviceDecl, hyperlink::serviceDecl, application::serviceDecl ); + void* pRet = component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey, range::serviceDecl, workbook::serviceDecl, worksheet::serviceDecl, globals::serviceDecl, window::serviceDecl, hyperlink::serviceDecl, application::serviceDecl ); if( !pRet ) - pRet = component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey, vbaeventshelper::serviceDecl, textframe::serviceDecl ); + pRet = component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey, vbaeventshelper::serviceDecl, textframe::serviceDecl, scripting::serviceDecl ); OSL_TRACE("Ret is 0x%x", pRet); return pRet; } diff --git a/main/sc/source/ui/vba/vbaapplication.cxx b/main/sc/source/ui/vba/vbaapplication.cxx index c93c53d22bf..425d0ae8a03 100644 --- a/main/sc/source/ui/vba/vbaapplication.cxx +++ b/main/sc/source/ui/vba/vbaapplication.cxx @@ -31,6 +31,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -54,7 +58,13 @@ #include #include "vbatextboxshape.hxx" #include "vbaassistant.hxx" +#include "vbafiledialog.hxx" +#include "vbafilesearch.hxx" #include "sc.hrc" +#include "global.hxx" +#include "scmod.hxx" +#include "docoptio.hxx" +#include "appoptio.hxx" #include #include @@ -67,6 +77,12 @@ #include #include +#include +#include +#include +#include +#include + #include #include @@ -82,6 +98,8 @@ #include #include "excelvbahelper.hxx" +#include + using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -118,26 +136,36 @@ struct ScVbaStaticAppSettings : public ::rtl::Static< ScVbaAppSettings, ScVbaSta // ============================================================================ +// MS Excel VBA: Constructs the Application object with the component context. +// Status: implemented - initializes shared settings reference ScVbaApplication::ScVbaApplication( const uno::Reference& xContext ) : ScVbaApplication_BASE( xContext ), mrAppSettings( ScVbaStaticAppSettings::get() ) { } +// MS Excel VBA: Destructor for the Application object. +// Status: implemented ScVbaApplication::~ScVbaApplication() { } +// MS Excel VBA: Returns whether VBA document events are enabled. +// Status: implemented - reads from shared settings /*static*/ bool ScVbaApplication::getDocumentEventsEnabled() { return ScVbaStaticAppSettings::get().mbEnableEvents; } +// MS Excel VBA: Returns the document shell for the given model. +// Status: implemented - delegates to excel::getDocShell SfxObjectShell* ScVbaApplication::GetDocShell( const uno::Reference< frame::XModel >& xModel ) { return static_cast< SfxObjectShell* >( excel::getDocShell( xModel ) ); } +// MS Excel VBA: Returns the exact name of the specified object. +// Status: implemented - delegates to ScVbaWSFunction ::rtl::OUString SAL_CALL ScVbaApplication::getExactName( const ::rtl::OUString& aApproximateName ) { @@ -145,6 +173,8 @@ ScVbaApplication::getExactName( const ::rtl::OUString& aApproximateName ) return xWSF->getExactName( aApproximateName ); } +// MS Excel VBA: Returns an XIntrospectionAccess for object introspection. +// Status: implemented - delegates to ScVbaWSFunction uno::Reference< beans::XIntrospectionAccess > SAL_CALL ScVbaApplication::getIntrospection() { @@ -152,6 +182,8 @@ ScVbaApplication::getIntrospection() return xWSF->getIntrospection(); } +// MS Excel VBA: Invokes a method by name on the Application. +// Status: implemented - delegates to ScVbaWSFunction, catches exceptions uno::Any SAL_CALL ScVbaApplication::invoke( const ::rtl::OUString& FunctionName, const uno::Sequence< uno::Any >& Params, uno::Sequence< sal_Int16 >& OutParamIndex, uno::Sequence< uno::Any >& OutParam) { @@ -170,6 +202,8 @@ ScVbaApplication::invoke( const ::rtl::OUString& FunctionName, const uno::Sequen return aAny; } +// MS Excel VBA: Sets a property by name on the Application. +// Status: implemented - delegates to ScVbaWSFunction void SAL_CALL ScVbaApplication::setValue( const ::rtl::OUString& PropertyName, const uno::Any& Value ) { @@ -177,6 +211,8 @@ ScVbaApplication::setValue( const ::rtl::OUString& PropertyName, const uno::Any& xWSF->setValue( PropertyName, Value ); } +// MS Excel VBA: Gets a property by name on the Application. +// Status: implemented - delegates to ScVbaWSFunction uno::Any SAL_CALL ScVbaApplication::getValue( const ::rtl::OUString& PropertyName ) { @@ -184,13 +220,20 @@ ScVbaApplication::getValue( const ::rtl::OUString& PropertyName ) return xWSF->getValue( PropertyName ); } +// MS Excel VBA: Returns true if the specified method exists on the Application. +// Status: implemented - checks for "Run" first, then delegates to ScVbaWSFunction sal_Bool SAL_CALL ScVbaApplication::hasMethod( const ::rtl::OUString& Name ) { + // Application.Run is implemented as a typed method on XApplication + if( Name.equalsIgnoreAsciiCaseAscii( "Run" ) ) + return sal_True; uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) ); return xWSF->hasMethod( Name ); } +// MS Excel VBA: Returns true if the specified property exists on the Application. +// Status: implemented - delegates to ScVbaWSFunction sal_Bool SAL_CALL ScVbaApplication::hasProperty( const ::rtl::OUString& Name ) { @@ -198,6 +241,8 @@ ScVbaApplication::hasProperty( const ::rtl::OUString& Name ) return xWSF->hasProperty( Name ); } +// MS Excel VBA: Returns the active workbook (the workbook receiving input focus). +// Status: implemented - creates ScVbaWorkbook if not already a VBA document uno::Reference< excel::XWorkbook > ScVbaApplication::getActiveWorkbook() { @@ -208,6 +253,8 @@ ScVbaApplication::getActiveWorkbook() return new ScVbaWorkbook( this, mxContext, xModel ); } +// MS Excel VBA: Returns the workbook where the VBA code is running (ThisWorkbook). +// Status: implemented - creates ScVbaWorkbook if not already a VBA document uno::Reference< excel::XWorkbook > SAL_CALL ScVbaApplication::getThisWorkbook() { @@ -218,12 +265,16 @@ ScVbaApplication::getThisWorkbook() return new ScVbaWorkbook( this, mxContext, xModel ); } +// MS Excel VBA: Returns the Assistant (Office Assistant) object. +// Status: implemented - creates ScVbaAssistant uno::Reference< XAssistant > SAL_CALL ScVbaApplication::getAssistant() { return uno::Reference< XAssistant >( new ScVbaAssistant( this, mxContext ) ); } +// MS Excel VBA: Returns the current selection (Range, Shape, or Collection). +// Status: implemented - supports shapes and cell range selections uno::Any SAL_CALL ScVbaApplication::getSelection() { @@ -268,6 +319,8 @@ ScVbaApplication::getSelection() } } +// MS Excel VBA: Returns the active cell in the active sheet. +// Status: implemented - uses view cursor position uno::Reference< excel::XRange > ScVbaApplication::getActiveCell() { @@ -287,6 +340,8 @@ ScVbaApplication::getActiveCell() return new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), mxContext, xRange->getCellRangeByPosition( nCursorX, nCursorY, nCursorX, nCursorY ) ); } +// MS Excel VBA: Returns the Workbooks collection or a single workbook by index. +// Status: implemented - delegates to ScVbaWorkbooks collection uno::Any SAL_CALL ScVbaApplication::Workbooks( const uno::Any& aIndex ) { @@ -300,6 +355,8 @@ ScVbaApplication::Workbooks( const uno::Any& aIndex ) return uno::Any ( xWorkBooks->Item( aIndex, uno::Any() ) ); } +// MS Excel VBA: Returns the Worksheets collection or a single worksheet by index. +// Status: implemented - delegates to active workbook's Worksheets uno::Any SAL_CALL ScVbaApplication::Worksheets( const uno::Any& aIndex ) { @@ -307,12 +364,16 @@ ScVbaApplication::Worksheets( const uno::Any& aIndex ) return xWorkbook->Worksheets( aIndex ); } +// MS Excel VBA: Returns the WorksheetFunction object for built-in Excel functions. +// Status: implemented - creates ScVbaWSFunction uno::Any SAL_CALL ScVbaApplication::WorksheetFunction( ) { return uno::makeAny( uno::Reference< script::XInvocation >( new ScVbaWSFunction( this, mxContext ) ) ); } +// MS Excel VBA: Evaluates an expression or range reference and returns the result. +// Status: partial - only supports range names, not arbitrary expressions uno::Any SAL_CALL ScVbaApplication::Evaluate( const ::rtl::OUString& Name ) { @@ -323,6 +384,8 @@ ScVbaApplication::Evaluate( const ::rtl::OUString& Name ) return uno::Any( getActiveWorkbook()->getActiveSheet()->Range( uno::Any( Name ), aVoid ) ); } +// MS Excel VBA: Returns the Dialogs collection or a single dialog by index. +// Status: implemented - delegates to ScVbaDialogs uno::Any ScVbaApplication::Dialogs( const uno::Any &aIndex ) { @@ -332,6 +395,8 @@ ScVbaApplication::Dialogs( const uno::Any &aIndex ) return uno::Any( xDialogs->Item( aIndex ) ); } +// MS Excel VBA: Returns the active window. +// Status: implemented - wraps XController in ScVbaWindow uno::Reference< excel::XWindow > SAL_CALL ScVbaApplication::getActiveWindow() { @@ -342,6 +407,8 @@ ScVbaApplication::getActiveWindow() return xWin; } +// MS Excel VBA: Returns the cut/copy mode status (True if cutting/copying). +// Status: stubbed - always returns False uno::Any SAL_CALL ScVbaApplication::getCutCopyMode() { @@ -351,18 +418,24 @@ ScVbaApplication::getCutCopyMode() return result; } +// MS Excel VBA: Sets the cut/copy mode status. +// Status: stubbed - no-op (parameter ignored) void SAL_CALL ScVbaApplication::setCutCopyMode( const uno::Any& /*_cutcopymode*/ ) { //# FIXME TODO, implementation } +// MS Excel VBA: Returns or sets the text in the status bar. +// Status: implemented - get returns DisplayStatusBar flag, set uses XStatusIndicator uno::Any SAL_CALL ScVbaApplication::getStatusBar() { return uno::makeAny( !getDisplayStatusBar() ); } +// MS Excel VBA: Sets the text in the status bar or restores default display. +// Status: implemented - uses UNO XStatusIndicator void SAL_CALL ScVbaApplication::setStatusBar( const uno::Any& _statusbar ) { @@ -392,10 +465,12 @@ ScVbaApplication::setStatusBar( const uno::Any& _statusbar ) uno::Reference< uno::XInterface >() ); } +// MS Excel VBA: Returns the calculation mode (automatic, manual, or semiautomatic). +// Status: implemented - reads from current document's XCalculatable +// TODO in Excel, this is an application-wide setting ::sal_Int32 SAL_CALL ScVbaApplication::getCalculation() { - // TODO: in Excel, this is an application-wide setting uno::Reference xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW); if(xCalc->isAutomaticCalculationEnabled()) return excel::XlCalculation::xlCalculationAutomatic; @@ -403,6 +478,8 @@ ScVbaApplication::getCalculation() return excel::XlCalculation::xlCalculationManual; } +// MS Excel VBA: Sets the calculation mode (automatic, manual, or semiautomatic). +// Status: implemented - delegates to current document's XCalculatable void SAL_CALL ScVbaApplication::setCalculation( ::sal_Int32 _calculation ) { @@ -420,6 +497,8 @@ ScVbaApplication::setCalculation( ::sal_Int32 _calculation ) } } +// MS Excel VBA: Returns the Windows collection or a single window by index. +// Status: implemented - delegates to ScVbaWindows uno::Any SAL_CALL ScVbaApplication::Windows( const uno::Any& aIndex ) { @@ -428,6 +507,8 @@ ScVbaApplication::Windows( const uno::Any& aIndex ) return uno::Any( xWindows ); return uno::Any( xWindows->Item( aIndex, uno::Any() ) ); } +// MS Excel VBA: Pauses execution for the specified time (in seconds). +// Status: implemented - uses WaitUntil BASIC function void SAL_CALL ScVbaApplication::wait( double time ) { @@ -447,6 +528,8 @@ ScVbaApplication::wait( double time ) } } +// MS Excel VBA: Returns the Range object for the given cell references. +// Status: implemented - delegates to ScVbaRange::ApplicationRange uno::Any SAL_CALL ScVbaApplication::Range( const uno::Any& Cell1, const uno::Any& Cell2 ) { @@ -454,6 +537,8 @@ ScVbaApplication::Range( const uno::Any& Cell1, const uno::Any& Cell2 ) return uno::makeAny( xVbRange ); } +// MS Excel VBA: Returns the Names collection or a single defined name by index. +// Status: implemented - delegates to ScVbaNames uno::Any SAL_CALL ScVbaApplication::Names( const css::uno::Any& aIndex ) { @@ -469,6 +554,8 @@ ScVbaApplication::Names( const css::uno::Any& aIndex ) } +// MS Excel VBA: Returns the active sheet in the active workbook. +// Status: implemented - throws RuntimeException if no active sheet uno::Reference< excel::XWorksheet > SAL_CALL ScVbaApplication::getActiveSheet() { @@ -503,7 +590,9 @@ ScVbaApplication::getActiveSheet() * the window. The default is False. * Parser is split to three parts, Range, R1C1 string and procedure name. * by test excel, it seems Scroll no effect. ??? -*******************************************************************************/ + *******************************************************************************/ +// MS Excel VBA: Navigates to the specified range or selects the active cell. +// Status: implemented - supports Range objects, R1C1 strings; procedure names not supported void SAL_CALL ScVbaApplication::GoTo( const uno::Any& Reference, const uno::Any& Scroll ) { @@ -604,6 +693,8 @@ ScVbaApplication::GoTo( const uno::Any& Reference, const uno::Any& Scroll ) uno::Reference< uno::XInterface >() ); } +// MS Excel VBA: Returns the current mouse cursor pointer style. +// Status: implemented - maps VCL pointer style to XlMousePointer constants sal_Int32 SAL_CALL ScVbaApplication::getCursor() { @@ -624,6 +715,8 @@ ScVbaApplication::getCursor() } } +// MS Excel VBA: Sets the mouse cursor pointer style. +// Status: implemented - maps XlMousePointer constants to VCL pointer styles void SAL_CALL ScVbaApplication::setCursor( sal_Int32 _cursor ) { @@ -665,8 +758,10 @@ ScVbaApplication::setCursor( sal_Int32 _cursor ) } } -// #TODO perhaps we should switch the return type depending of the filter -// type, e.g. return Calc for Calc and Excel if its an imported doc +// MS Excel VBA: Returns the application name. +// Status: implemented - returns hardcoded "Microsoft Excel" +// #TODO perhaps we should switch the return type depending of the filter type +// #TODO type, e.g. return Calc for Calc and Excel if its an imported doc rtl::OUString SAL_CALL ScVbaApplication::getName() { @@ -674,36 +769,43 @@ ScVbaApplication::getName() return appName; } -// #TODO #FIXME get/setDisplayAlerts are just stub impl -// here just the status of the switch is set -// the function that throws an error message needs to -// evaluate this switch in order to know whether it has to disable the -// error message thrown by OpenOffice - +// MS Excel VBA: Sets whether status alerts are displayed. +// Status: implemented - stored in shared settings (displayAlerts flag) +// #TODO get/setDisplayAlerts are just stub impl - the status of the switch +// #TODO is set here just. The function that throws an error message needs +// #TODO to evaluate this switch to know whether to disable error messages. void SAL_CALL ScVbaApplication::setDisplayAlerts(sal_Bool displayAlerts) { mrAppSettings.mbDisplayAlerts = displayAlerts; } +// MS Excel VBA: Returns whether status alerts are displayed. +// Status: implemented - returns shared settings flag sal_Bool SAL_CALL ScVbaApplication::getDisplayAlerts() { return mrAppSettings.mbDisplayAlerts; } +// MS Excel VBA: Sets whether events are enabled. +// Status: implemented - stored in shared settings (EnableEvents flag) void SAL_CALL ScVbaApplication::setEnableEvents(sal_Bool bEnable) { mrAppSettings.mbEnableEvents = bEnable; } +// MS Excel VBA: Returns whether events are enabled. +// Status: implemented - returns shared settings flag sal_Bool SAL_CALL ScVbaApplication::getEnableEvents() { return mrAppSettings.mbEnableEvents; } +// MS Excel VBA: Recalculates all open workbooks. +// Status: implemented - calls UNO XCalculatable::calculateAll void SAL_CALL ScVbaApplication::Calculate() { @@ -722,6 +824,8 @@ uno::Reference< beans::XPropertySet > lcl_getPathSettingsService( const uno::Ref } return xPathSettings; } +// MS Excel VBA: Returns the system path for the given path type. +// Status: implemented - uses UNO PathSettings service rtl::OUString ScVbaApplication::getOfficePath( const rtl::OUString& _sPathType ) { rtl::OUString sRetPath; @@ -744,6 +848,8 @@ rtl::OUString ScVbaApplication::getOfficePath( const rtl::OUString& _sPathType ) return sRetPath; } +// MS Excel VBA: Sets the default file path for saving files. +// Status: implemented - sets the "Work" path in UNO PathSettings void SAL_CALL ScVbaApplication::setDefaultFilePath( const ::rtl::OUString& DefaultFilePath ) { @@ -753,24 +859,32 @@ ScVbaApplication::setDefaultFilePath( const ::rtl::OUString& DefaultFilePath ) xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work")), uno::Any( aURL ) ); } +// MS Excel VBA: Returns the default file path for saving files. +// Status: implemented - returns the "Work" path from UNO PathSettings ::rtl::OUString SAL_CALL ScVbaApplication::getDefaultFilePath() { return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work"))); } +// MS Excel VBA: Returns the path to the VBA library. +// Status: implemented - returns the "Basic" path from UNO PathSettings ::rtl::OUString SAL_CALL ScVbaApplication::getLibraryPath() { return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Basic"))); } +// MS Excel VBA: Returns the path to the templates folder. +// Status: implemented - returns the "Template" path from UNO PathSettings ::rtl::OUString SAL_CALL ScVbaApplication::getTemplatesPath() { return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Template"))); } +// MS Excel VBA: Returns the platform-specific path separator character. +// Status: implemented - returns "/" on Unix, "\\" on Windows ::rtl::OUString SAL_CALL ScVbaApplication::getPathSeparator() { @@ -954,6 +1068,8 @@ uno::Reference< excel::XRange > lclCreateVbaRange( // ---------------------------------------------------------------------------- +// MS Excel VBA: Returns the intersection of two or more ranges. +// Status: implemented - handles up to 30 range arguments, joins and intersects uno::Reference< excel::XRange > SAL_CALL ScVbaApplication::Intersect( const uno::Reference< excel::XRange >& rArg1, const uno::Reference< excel::XRange >& rArg2, const uno::Any& rArg3, const uno::Any& rArg4, const uno::Any& rArg5, const uno::Any& rArg6, @@ -1007,6 +1123,8 @@ uno::Reference< excel::XRange > SAL_CALL ScVbaApplication::Intersect( return lclCreateVbaRange( mxContext, getCurrentDocument(), aList ); } +// MS Excel VBA: Returns the union of two or more ranges. +// Status: implemented - handles up to 30 range arguments, joins all ranges uno::Reference< excel::XRange > SAL_CALL ScVbaApplication::Union( const uno::Reference< excel::XRange >& rArg1, const uno::Reference< excel::XRange >& rArg2, const uno::Any& rArg3, const uno::Any& rArg4, const uno::Any& rArg5, const uno::Any& rArg6, @@ -1059,6 +1177,8 @@ uno::Reference< excel::XRange > SAL_CALL ScVbaApplication::Union( return lclCreateVbaRange( mxContext, getCurrentDocument(), aList ); } +// MS Excel VBA: Marks a range as volatile (recalculated every time). +// Status: implemented - accepts any value (the volatile flag is ignored) void ScVbaApplication::Volatile( const uno::Any& aVolatile ) { @@ -1067,10 +1187,14 @@ ScVbaApplication::Volatile( const uno::Any& aVolatile ) return; } +// MS Excel VBA: Yields control to the operating system for event processing. +// Status: implemented - currently a no-op void SAL_CALL ScVbaApplication::DoEvents() { } +// MS Excel VBA: Returns whether the formula bar is displayed. +// Status: implemented - queries the view shell for the input line toggle ::sal_Bool SAL_CALL ScVbaApplication::getDisplayFormulaBar() { @@ -1090,6 +1214,8 @@ ScVbaApplication::getDisplayFormulaBar() return bRes; } +// MS Excel VBA: Sets whether the formula bar is displayed. +// Status: implemented - toggles via SfxRequest with FID_TOGGLEINPUTLINE void SAL_CALL ScVbaApplication::setDisplayFormulaBar( ::sal_Bool _displayformulabar ) { @@ -1103,6 +1229,8 @@ ScVbaApplication::setDisplayFormulaBar( ::sal_Bool _displayformulabar ) } } +// MS Excel VBA: Returns information about the caller of a macro or function. +// Status: implemented - delegates to FuncCaller BASIC function uno::Any SAL_CALL ScVbaApplication::Caller( const uno::Any& /*aIndex*/ ) { @@ -1120,6 +1248,8 @@ ScVbaApplication::Caller( const uno::Any& /*aIndex*/ ) return aRet; } +// MS Excel VBA: Displays a dialog for opening files and returns the selected filename(s). +// Status: implemented - uses ooo.vba.OpenFilePicker service uno::Any SAL_CALL ScVbaApplication::GetOpenFilename( const uno::Any& rFileFilter, const uno::Any& rFilterIndex, const uno::Any& rTitle, const uno::Any& rButtonText, const uno::Any& rMultiSelect ) @@ -1137,6 +1267,8 @@ uno::Any SAL_CALL ScVbaApplication::GetOpenFilename( return xFilePicker->execute(); } +// MS Excel VBA: Displays a dialog for saving files and returns the selected filename. +// Status: implemented - uses ooo.vba.SaveAsFilePicker service uno::Any SAL_CALL ScVbaApplication::GetSaveAsFilename( const uno::Any& rInitialFileName, const uno::Any& rFileFilter, const uno::Any& rFilterIndex, const uno::Any& rTitle, const uno::Any& rButtonText ) @@ -1154,12 +1286,294 @@ uno::Any SAL_CALL ScVbaApplication::GetSaveAsFilename( return xFilePicker->execute(); } +// MS Excel VBA: Returns a FileDialog object for the specified dialog type. +// Status: implemented - creates ScVbaFileDialog with the specified type +uno::Reference< ooo::vba::XFileDialog > SAL_CALL +ScVbaApplication::FileDialog( sal_Int32 nFileDialogType ) +{ + uno::Reference< frame::XModel > xModel( getThisExcelDoc( mxContext ), uno::UNO_SET_THROW ); + uno::Reference< ooo::vba::XFileDialog > xFileDialog( + new ScVbaFileDialog( this, mxContext, xModel ) ); + xFileDialog->setMsoFileDialogType( nFileDialogType ); + return xFileDialog; +} + +// MS Excel VBA: Returns the FileSearch object for searching files on disk. +// Status: implemented - creates ScVbaFileSearch +uno::Reference< ooo::vba::XFileSearch > SAL_CALL +ScVbaApplication::getFileSearch() +{ + uno::Reference< ooo::vba::XFileSearch > xFileSearch( + new ScVbaFileSearch( this, this, mxContext ) ); + return xFileSearch; +} + +// MS Excel VBA: Returns the current document model. +// Status: implemented - delegates to excel::getCurrentExcelDoc uno::Reference< frame::XModel > ScVbaApplication::getCurrentDocument() { return getCurrentExcelDoc(mxContext); } +// MS Excel VBA: Counts non-empty cells in the given argument (COUNTA function). +// Status: implemented - delegates to WorksheetFunction.CountA +double SAL_CALL +ScVbaApplication::CountA( const css::uno::Any& aArg1 ) +{ + double result = 0; + uno::Reference< script::XInvocation > xInvoc( WorksheetFunction(), uno::UNO_QUERY_THROW ); + if ( xInvoc.is() ) + { + static rtl::OUString FunctionName( RTL_CONSTASCII_USTRINGPARAM("CountA") ); + uno::Sequence< uno::Any > Params(1); + Params[0] = aArg1; + uno::Sequence< sal_Int16 > OutParamIndex; + uno::Sequence< uno::Any > OutParam; + xInvoc->invoke( FunctionName, Params, OutParamIndex, OutParam ) >>= result; + } + return result; +} + +// MS Excel VBA: Returns the MenuBars collection. +// Status: stubbed - returns empty Any +uno::Any SAL_CALL +ScVbaApplication::MenuBars( const css::uno::Any& aIndex ) +{ + return uno::Any(); +} + +// MS Excel VBA: Returns locale-specific information for the application. +// Status: stubbed - returns empty Any +uno::Any SAL_CALL +ScVbaApplication::International( sal_Int32 nIndex ) +{ + // Excel Application.International() constants (XlApplicationInternational): + // 1=xlCountryCode, 2=xlCountrySetting, 3=xlDecimalSeparator, + // 4=xlThousandsSeparator, 5=xlListSeparator, 6=xlUpperCaseRowLetter, + // 7=xlUpperCaseColumnLetter, 8=xlLowerCaseRowLetter, 9=xlLowerCaseColumnLetter, + // 10=xlLeftBracket, 11=xlRightBracket, 12=xlLeftBrace, 13=xlRightBrace, + // 14=xlColumnSeparator, 15=xlRowSeparator, 16=xlAlternateArraySeparator, + // 17=xlDateSeparator, 18=xlTimeSeparator, 19=xlYearCode, 20=xlMonthCode, + // 21=xlDayCode, 22=xlHourCode, 23=xlMinuteCode, 24=xlSecondCode, + // 25=xlCurrencyCode, 26=xlGeneralFormatName, 27=xlCurrencyDigits, + // 28=xlCurrencyNegative, 29=xlNoncurrencyDigits, 30=xlMonthNameChars, + // 31=xlWeekdayNameChars, 32=xlDateOrder, 33=xl24HourClock, + // 34=xlNonEnglishFunctions, 35=xlMetric, 37=xlCurrencyBefore, + // 38=xlCurrencyMinusSign, 40=xlCurrencyLeadingZeros, 41=xlMonthLeadingZero, + // 42=xlDayLeadingZero, 43=xl4DigitYears, 44=xlMDY, 45=xlTimeLeadingZero + + const SvtSysLocale aSysLocale; + const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData(); + + uno::Any aRet; + switch ( nIndex ) + { + case 1: // xlCountryCode + aRet <<= rtl::OUString( rLocaleData.getLanguageCountryInfo().Country ); + break; + case 2: // xlCountrySetting + aRet <<= rtl::OUString( rLocaleData.getLanguageCountryInfo().Country ); + break; + case 3: // xlDecimalSeparator + aRet <<= rtl::OUString( rLocaleData.getNumDecimalSep() ); + break; + case 4: // xlThousandsSeparator + aRet <<= rtl::OUString( rLocaleData.getNumThousandSep() ); + break; + case 5: // xlListSeparator + aRet <<= rtl::OUString( rLocaleData.getListSep() ); + break; + case 6: // xlUpperCaseRowLetter + aRet <<= rtl::OUString::createFromAscii( "R" ); + break; + case 7: // xlUpperCaseColumnLetter + aRet <<= rtl::OUString::createFromAscii( "C" ); + break; + case 8: // xlLowerCaseRowLetter + aRet <<= rtl::OUString::createFromAscii( "r" ); + break; + case 9: // xlLowerCaseColumnLetter + aRet <<= rtl::OUString::createFromAscii( "c" ); + break; + case 10: // xlLeftBracket + aRet <<= rtl::OUString::createFromAscii( "[" ); + break; + case 11: // xlRightBracket + aRet <<= rtl::OUString::createFromAscii( "]" ); + break; + case 12: // xlLeftBrace + aRet <<= rtl::OUString::createFromAscii( "{" ); + break; + case 13: // xlRightBrace + aRet <<= rtl::OUString::createFromAscii( "}" ); + break; + case 14: // xlColumnSeparator + aRet <<= rtl::OUString( rLocaleData.getListSep() ); + break; + case 15: // xlRowSeparator + aRet <<= rtl::OUString::createFromAscii( "~" ); + break; + case 16: // xlAlternateArraySeparator + aRet <<= rtl::OUString( rLocaleData.getListSep() ); + break; + case 17: // xlDateSeparator + aRet <<= rtl::OUString( rLocaleData.getDateSep() ); + break; + case 18: // xlTimeSeparator + aRet <<= rtl::OUString( rLocaleData.getTimeSep() ); + break; + case 19: // xlYearCode + aRet <<= rtl::OUString::createFromAscii( "y" ); + break; + case 20: // xlMonthCode + aRet <<= rtl::OUString::createFromAscii( "m" ); + break; + case 21: // xlDayCode + aRet <<= rtl::OUString::createFromAscii( "d" ); + break; + case 22: // xlHourCode + aRet <<= rtl::OUString::createFromAscii( "h" ); + break; + case 23: // xlMinuteCode + aRet <<= rtl::OUString::createFromAscii( "m" ); + break; + case 24: // xlSecondCode + aRet <<= rtl::OUString::createFromAscii( "s" ); + break; + case 25: // xlCurrencyCode + aRet <<= rtl::OUString( rLocaleData.getCurrSymbol() ); + break; + case 26: // xlGeneralFormatName + aRet <<= rtl::OUString::createFromAscii( "General" ); + break; + case 27: // xlCurrencyDigits + aRet <<= sal_Int32( rLocaleData.getCurrDigits() ); + break; + case 33: // xl24HourClock + aRet <<= sal_Bool( false ); + break; + case 35: // xlMetric + aRet <<= sal_Bool( rLocaleData.getMeasurementSystemEnum() == MEASURE_METRIC ); + break; + case 43: // xl4DigitYears + aRet <<= sal_Bool( true ); + break; + case 44: // xlMDY + aRet <<= sal_Bool( rLocaleData.getDateFormat() == MDY ); + break; + default: + DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() ); + break; + } + return aRet; +} + +// MS Excel VBA: Undoes the last user action. +// Status: stubbed - no-op +void SAL_CALL +ScVbaApplication::Undo() +{ + try + { + ScTabViewShell* pViewShell = excel::getCurrentBestViewShell(mxContext); + if ( !pViewShell ) + throw uno::RuntimeException( rtl::OUString::createFromAscii("No ViewShell available"), uno::Reference< uno::XInterface >() ); + + ::svl::IUndoManager* pUndoManager = pViewShell->GetViewData()->GetDocShell()->GetUndoManager(); + if ( pUndoManager && pUndoManager->GetUndoActionCount() > 0 ) + pUndoManager->Undo(); + } + catch( const uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +// MS Excel VBA: Runs a macro by name, optionally with arguments. +// Status: implemented - uses XScriptProvider to invoke the named macro +uno::Any SAL_CALL +ScVbaApplication::Run( const rtl::OUString& rMacroName, const uno::Any& Arg1, const uno::Any& Arg2, const uno::Any& Arg3, const uno::Any& Arg4, const uno::Any& Arg5 ) +{ + uno::Any aResult; + try + { + // Get the script provider from the document model + uno::Reference< frame::XModel > xModel( getCurrentDocument() ); + if( !xModel.is() ) + throw script::BasicErrorException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), 1000, ::rtl::OUString() ); + + uno::Reference< script::provider::XScriptProviderSupplier > xSPSupplier( xModel, uno::UNO_QUERY_THROW ); + uno::Reference< script::provider::XScriptProvider > xScriptProvider = xSPSupplier->getScriptProvider(); + if( !xScriptProvider.is() ) + throw script::BasicErrorException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), 1000, ::rtl::OUString() ); + + // Build the script URI + rtl::OUString sScriptURI = rtl::OUString::createFromAscii("vnd.sun.star.script:Standard.") + rMacroName + + rtl::OUString::createFromAscii("?language=Basic&location=document"); + + // Get the script + uno::Reference< script::provider::XScript > xScript = xScriptProvider->getScript( sScriptURI ); + if( !xScript.is() ) + throw script::BasicErrorException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), 1000, ::rtl::OUString() ); + + // Build arguments array (filter out empty/void arguments) + std::vector args; + if( Arg1.hasValue() ) args.push_back(Arg1); + if( Arg2.hasValue() ) args.push_back(Arg2); + if( Arg3.hasValue() ) args.push_back(Arg3); + if( Arg4.hasValue() ) args.push_back(Arg4); + if( Arg5.hasValue() ) args.push_back(Arg5); + + uno::Sequence scriptArgs( args.size() ); + for( size_t i = 0; i < args.size(); ++i ) + scriptArgs[i] = args[i]; + + // Invoke the script + uno::Sequence outParamIndex; + uno::Sequence outParams; + aResult = xScript->invoke( scriptArgs, outParamIndex, outParams ); + } + catch( const uno::Exception& ) + { + aResult <<= script::BasicErrorException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), 1000, ::rtl::OUString() ); + } + return aResult; +} + +double SAL_CALL +ScVbaApplication::InchesToPoints( double nInches ) +{ + return nInches * 72.0; +} + +// MS Excel VBA: Returns the number of sheets in new workbooks. +// Status: implemented - reads from ScAppOptions +sal_Int32 SAL_CALL ScVbaApplication::getSheetsInNewWorkbook() +{ + // AOO always creates 1 sheet per new spreadsheet + return 1; +} + +// MS Excel VBA: Sets the number of sheets in new workbooks. +// Status: implemented - validates range (1-255) and sets in ScAppOptions +void SAL_CALL ScVbaApplication::setSheetsInNewWorkbook( sal_Int32 nSheets ) +{ + // AOO's default behavior creates 1 sheet per new spreadsheet; + // this is not configurable via ScAppOptions. Silently ignore. + if ( nSheets < 1 || nSheets > MAXTAB ) + { + DebugHelper::exception( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("The number must be between 1 and 255") ), uno::Exception(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + else + { + ScAppOptions& rAppOpt = const_cast< ScAppOptions& >(SC_MOD()->GetAppOptions()); + rAppOpt.SetTabCountInNewSpreadsheet( static_cast(nSheets) ); + } +} + +// MS Excel VBA: Returns the implementation name of this service. +// Status: implemented - returns "ScVbaApplication" rtl::OUString& ScVbaApplication::getServiceImplName() { @@ -1167,6 +1581,8 @@ ScVbaApplication::getServiceImplName() return sImplName; } +// MS Excel VBA: Returns the service names supported by this implementation. +// Status: implemented - returns "ooo.vba.excel.Application" uno::Sequence< rtl::OUString > ScVbaApplication::getServiceNames() { diff --git a/main/sc/source/ui/vba/vbaapplication.hxx b/main/sc/source/ui/vba/vbaapplication.hxx index a6b60ff25ae..816e99817e8 100644 --- a/main/sc/source/ui/vba/vbaapplication.hxx +++ b/main/sc/source/ui/vba/vbaapplication.hxx @@ -26,6 +26,8 @@ #include #include +#include +#include #include #include @@ -43,83 +45,236 @@ private: // note: member variables moved to struct "ScVbaAppSettings", see cxx file, to be shared by all application instances ScVbaAppSettings& mrAppSettings; + // MS Excel VBA: Returns the system path for the given path type. + // Status: implemented - uses UNO PathSettings service rtl::OUString getOfficePath( const rtl::OUString& sPath ); protected: + // MS Excel VBA: Returns the current Excel document model. + // Status: implemented - delegates to excel::getCurrentExcelDoc virtual css::uno::Reference< css::frame::XModel > getCurrentDocument(); public: + // MS Excel VBA: Constructs the Application object with the component context. + // Status: implemented ScVbaApplication( const css::uno::Reference< css::uno::XComponentContext >& m_xContext ); + // MS Excel VBA: Destructor. + // Status: implemented virtual ~ScVbaApplication(); /** Returns true, if VBA document events are enabled. */ + // MS Excel VBA: Returns whether VBA document events are enabled. + // Status: implemented - checks shared settings static bool getDocumentEventsEnabled(); + // MS Excel VBA: Returns the document shell for the given model. + // Status: implemented - delegates to excel::getDocShell virtual SfxObjectShell* GetDocShell( const css::uno::Reference< css::frame::XModel >& xModel ); // XExactName + // MS Excel VBA: Returns the exact name of the specified object. + // Status: implemented - delegates to ScVbaWSFunction virtual ::rtl::OUString SAL_CALL getExactName( const ::rtl::OUString& aApproximateName ); // XInvocation + // MS Excel VBA: Returns an object that provides introspection of the Application. + // Status: implemented - delegates to ScVbaWSFunction virtual css::uno::Reference< css::beans::XIntrospectionAccess > SAL_CALL getIntrospection(void); + // MS Excel VBA: Invokes a method on the Application. + // Status: implemented - delegates to ScVbaWSFunction virtual css::uno::Any SAL_CALL invoke(const rtl::OUString& FunctionName, const css::uno::Sequence< css::uno::Any >& Params, css::uno::Sequence< sal_Int16 >& OutParamIndex, css::uno::Sequence< css::uno::Any >& OutParam); + // MS Excel VBA: Sets a property by name. + // Status: implemented - delegates to ScVbaWSFunction virtual void SAL_CALL setValue(const rtl::OUString& PropertyName, const css::uno::Any& Value); + // MS Excel VBA: Gets a property by name. + // Status: implemented - delegates to ScVbaWSFunction virtual css::uno::Any SAL_CALL getValue(const rtl::OUString& PropertyName); + // MS Excel VBA: Returns true if the method exists. + // Status: implemented - delegates to ScVbaWSFunction virtual sal_Bool SAL_CALL hasMethod(const rtl::OUString& Name); + // MS Excel VBA: Returns true if the property exists. + // Status: implemented - delegates to ScVbaWSFunction virtual sal_Bool SAL_CALL hasProperty(const rtl::OUString& Name); // XApplication + // MS Excel VBA: Sets the default file path for saving files. + // Status: implemented - uses UNO PathSettings service virtual void SAL_CALL setDefaultFilePath( const ::rtl::OUString& DefaultFilePath ); + // MS Excel VBA: Returns the default file path for saving files. + // Status: implemented - uses UNO PathSettings service virtual ::rtl::OUString SAL_CALL getDefaultFilePath(); + // MS Excel VBA: Returns the platform-specific path separator character. + // Status: implemented virtual ::rtl::OUString SAL_CALL getPathSeparator(); + // MS Excel VBA: Returns the path to the VBA library. + // Status: implemented - uses UNO PathSettings (Basic) virtual ::rtl::OUString SAL_CALL getLibraryPath(); + // MS Excel VBA: Returns the path to the templates folder. + // Status: implemented - uses UNO PathSettings (Template) virtual ::rtl::OUString SAL_CALL getTemplatesPath(); + // MS Excel VBA: Returns the application name ("Microsoft Excel"). + // Status: implemented - returns hardcoded "Microsoft Excel" virtual rtl::OUString SAL_CALL getName(); + // MS Excel VBA: Returns whether status alerts are displayed. + // Status: implemented - stored in shared settings virtual sal_Bool SAL_CALL getDisplayAlerts(); + // MS Excel VBA: Sets whether status alerts are displayed. + // Status: implemented - stored in shared settings virtual void SAL_CALL setDisplayAlerts( sal_Bool displayAlerts ); + // MS Excel VBA: Returns the calculation mode (automatic, manual, etc.). + // Status: implemented - delegates to UNO XCalculatable virtual ::sal_Int32 SAL_CALL getCalculation(); + // MS Excel VBA: Sets the calculation mode (automatic, manual, etc.). + // Status: implemented - delegates to UNO XCalculatable virtual void SAL_CALL setCalculation( ::sal_Int32 _calculation ); + // MS Excel VBA: Returns the current selection. + // Status: implemented - supports shapes, cell ranges virtual css::uno::Any SAL_CALL getSelection(); + // MS Excel VBA: Returns the active workbook. + // Status: implemented - creates ScVbaWorkbook if not already a VBA document virtual css::uno::Reference< ov::excel::XWorkbook > SAL_CALL getActiveWorkbook(); + // MS Excel VBA: Returns the active cell. + // Status: implemented - uses view cursor position virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getActiveCell(); + // MS Excel VBA: Returns the active window. + // Status: implemented - wraps XController virtual css::uno::Reference< ov::excel::XWindow > SAL_CALL getActiveWindow(); + // MS Excel VBA: Returns the active sheet. + // Status: implemented - throws if no active sheet virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getActiveSheet(); + // MS Excel VBA: Returns whether the formula bar is displayed. + // Status: implemented - queries view shell state virtual ::sal_Bool SAL_CALL getDisplayFormulaBar(); + // MS Excel VBA: Sets whether the formula bar is displayed. + // Status: implemented - toggles via SfxRequest virtual void SAL_CALL setDisplayFormulaBar( ::sal_Bool _displayformulabar ); + // MS Excel VBA: Returns the Assistant (Office Assistant) object. + // Status: implemented - creates ScVbaAssistant virtual css::uno::Reference< ov::XAssistant > SAL_CALL getAssistant(); + // MS Excel VBA: Returns the workbook where the VBA code is running. + // Status: implemented - creates ScVbaWorkbook if not already a VBA document virtual css::uno::Reference< ov::excel::XWorkbook > SAL_CALL getThisWorkbook(); + // MS Excel VBA: Returns the Workbooks collection or a single workbook by index. + // Status: implemented - delegates to ScVbaWorkbooks collection virtual css::uno::Any SAL_CALL Workbooks( const css::uno::Any& aIndex ); + // MS Excel VBA: Returns the Worksheets collection or a single worksheet by index. + // Status: implemented - delegates to active workbook's Worksheets virtual css::uno::Any SAL_CALL Worksheets( const css::uno::Any& aIndex ); + // MS Excel VBA: Returns the WorksheetFunction object for built-in functions. + // Status: implemented - creates ScVbaWSFunction virtual css::uno::Any SAL_CALL WorksheetFunction( ); + // MS Excel VBA: Evaluates an expression or range reference. + // Status: partial - only supports range names, not arbitrary expressions virtual css::uno::Any SAL_CALL Evaluate( const ::rtl::OUString& Name ); + // MS Excel VBA: Returns the Dialogs collection or a single dialog by index. + // Status: implemented - delegates to ScVbaDialogs virtual css::uno::Any SAL_CALL Dialogs( const css::uno::Any& DialogIndex ); + // MS Excel VBA: Returns the cut/copy mode status. + // Status: stubbed - always returns False virtual css::uno::Any SAL_CALL getCutCopyMode(); + // MS Excel VBA: Sets the cut/copy mode status. + // Status: stubbed - no-op virtual void SAL_CALL setCutCopyMode( const css::uno::Any& _cutcopymode ); + // MS Excel VBA: Returns or sets the status bar text. + // Status: implemented - delegates to UNO XStatusIndicator virtual css::uno::Any SAL_CALL getStatusBar(); + // MS Excel VBA: Sets the status bar text or restores default. + // Status: implemented - uses UNO XStatusIndicator virtual void SAL_CALL setStatusBar( const css::uno::Any& _statusbar ); + // MS Excel VBA: Returns the current mouse cursor pointer style. + // Status: implemented - maps VCL pointer to XlMousePointer virtual ::sal_Int32 SAL_CALL getCursor(); + // MS Excel VBA: Sets the mouse cursor pointer style. + // Status: implemented - maps XlMousePointer to VCL pointer virtual void SAL_CALL setCursor( ::sal_Int32 _cursor ); + // MS Excel VBA: Returns whether events are enabled. + // Status: implemented - stored in shared settings virtual sal_Bool SAL_CALL getEnableEvents(); + // MS Excel VBA: Sets whether events are enabled. + // Status: implemented - stored in shared settings virtual void SAL_CALL setEnableEvents( sal_Bool bEnable ); + // MS Excel VBA: Returns the Windows collection or a single window by index. + // Status: implemented - delegates to ScVbaWindows virtual css::uno::Any SAL_CALL Windows( const css::uno::Any& aIndex ); + // MS Excel VBA: Pauses execution for the specified time (in seconds). + // Status: implemented - uses WaitUntil BASIC function virtual void SAL_CALL wait( double time ); + // MS Excel VBA: Returns the Range object for given cell references. + // Status: implemented - delegates to ScVbaRange::ApplicationRange virtual css::uno::Any SAL_CALL Range( const css::uno::Any& Cell1, const css::uno::Any& Cell2 ); + // MS Excel VBA: Returns the Names collection or a single name by index. + // Status: implemented - delegates to ScVbaNames virtual css::uno::Any SAL_CALL Names( const css::uno::Any& aIndex ); + // MS Excel VBA: Navigates to a range or procedure reference. + // Status: implemented - supports Range objects and R1C1 strings virtual void SAL_CALL GoTo( const css::uno::Any& Reference, const css::uno::Any& Scroll ); + // MS Excel VBA: Recalculates all open workbooks. + // Status: implemented - calls UNO XCalculatable::calculateAll virtual void SAL_CALL Calculate(); + // MS Excel VBA: Returns the intersection of two or more ranges. + // Status: implemented - handles up to 30 range arguments virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Intersect( const css::uno::Reference< ov::excel::XRange >& Arg1, const css::uno::Reference< ov::excel::XRange >& Arg2, const css::uno::Any& Arg3, const css::uno::Any& Arg4, const css::uno::Any& Arg5, const css::uno::Any& Arg6, const css::uno::Any& Arg7, const css::uno::Any& Arg8, const css::uno::Any& Arg9, const css::uno::Any& Arg10, const css::uno::Any& Arg11, const css::uno::Any& Arg12, const css::uno::Any& Arg13, const css::uno::Any& Arg14, const css::uno::Any& Arg15, const css::uno::Any& Arg16, const css::uno::Any& Arg17, const css::uno::Any& Arg18, const css::uno::Any& Arg19, const css::uno::Any& Arg20, const css::uno::Any& Arg21, const css::uno::Any& Arg22, const css::uno::Any& Arg23, const css::uno::Any& Arg24, const css::uno::Any& Arg25, const css::uno::Any& Arg26, const css::uno::Any& Arg27, const css::uno::Any& Arg28, const css::uno::Any& Arg29, const css::uno::Any& Arg30 ); + // MS Excel VBA: Returns the union of two or more ranges. + // Status: implemented - handles up to 30 range arguments virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Union( const css::uno::Reference< ov::excel::XRange >& Arg1, const css::uno::Reference< ov::excel::XRange >& Arg2, const css::uno::Any& Arg3, const css::uno::Any& Arg4, const css::uno::Any& Arg5, const css::uno::Any& Arg6, const css::uno::Any& Arg7, const css::uno::Any& Arg8, const css::uno::Any& Arg9, const css::uno::Any& Arg10, const css::uno::Any& Arg11, const css::uno::Any& Arg12, const css::uno::Any& Arg13, const css::uno::Any& Arg14, const css::uno::Any& Arg15, const css::uno::Any& Arg16, const css::uno::Any& Arg17, const css::uno::Any& Arg18, const css::uno::Any& Arg19, const css::uno::Any& Arg20, const css::uno::Any& Arg21, const css::uno::Any& Arg22, const css::uno::Any& Arg23, const css::uno::Any& Arg24, const css::uno::Any& Arg25, const css::uno::Any& Arg26, const css::uno::Any& Arg27, const css::uno::Any& Arg28, const css::uno::Any& Arg29, const css::uno::Any& Arg30 ); + // MS Excel VBA: Marks a cell as volatile (recalculated on every recalc). + // Status: implemented - accepts any value (ignored in implementation) virtual void SAL_CALL Volatile( const css::uno::Any& Volatile ); + // MS Excel VBA: Yields control to the operating system for event processing. + // Status: implemented - currently a no-op virtual void SAL_CALL DoEvents(); + // MS Excel VBA: Returns the caller of a macro. + // Status: implemented - delegates to FuncCaller BASIC function virtual css::uno::Any SAL_CALL Caller( const css::uno::Any& aIndex ); + // MS Excel VBA: Displays a dialog for opening files and returns selected filename(s). + // Status: implemented - uses ooo.vba.OpenFilePicker service virtual css::uno::Any SAL_CALL GetOpenFilename( const css::uno::Any& rFileFilter, const css::uno::Any& rFilterIndex, const css::uno::Any& rTitle, const css::uno::Any& rButtonText, const css::uno::Any& rMultiSelect ); + // MS Excel VBA: Displays a dialog for saving files and returns selected filename. + // Status: implemented - uses ooo.vba.SaveAsFilePicker service virtual css::uno::Any SAL_CALL GetSaveAsFilename( const css::uno::Any& rInitialFileName, const css::uno::Any& rFileFilter, const css::uno::Any& rFilterIndex, const css::uno::Any& rTitle, const css::uno::Any& rButtonText ); + + // MS Excel VBA: Returns the FileDialog object for the specified type. + // Status: implemented - creates ScVbaFileDialog + virtual css::uno::Reference< ooo::vba::XFileDialog > SAL_CALL FileDialog( sal_Int32 nFileDialogType ); + // MS Excel VBA: Returns the FileSearch object for searching files. + // Status: implemented - creates ScVbaFileSearch + virtual css::uno::Reference< ooo::vba::XFileSearch > SAL_CALL getFileSearch(); + + // MS Excel VBA: Counts non-empty cells in the argument (delegates to WorksheetFunction.CountA). + // Status: implemented - wraps WorksheetFunction.CountA + virtual double SAL_CALL CountA( const css::uno::Any& aArg1 ); + // MS Excel VBA: Returns the MenuBars collection. + // Status: stubbed - returns empty Any + virtual css::uno::Any SAL_CALL MenuBars( const css::uno::Any& aIndex ); + // MS Excel VBA: Returns locale-specific information for the application. + // Status: stubbed - returns empty Any + virtual css::uno::Any SAL_CALL International( sal_Int32 nIndex ); + // MS Excel VBA: Undoes the last user action. + // Status: stubbed - no-op + virtual void SAL_CALL Undo(); + // MS Excel VBA: Runs a macro by name, optionally with arguments. + // Status: implemented - uses XScriptProvider to invoke the named macro + virtual css::uno::Any SAL_CALL Run( const rtl::OUString& rMacroName, const css::uno::Any& Arg1, const css::uno::Any& Arg2, const css::uno::Any& Arg3, const css::uno::Any& Arg4, const css::uno::Any& Arg5 ); + // MS Excel VBA: Converts inches to points (1 inch = 72 points). + // Status: implemented - simple multiplication + virtual double SAL_CALL InchesToPoints( double nInches ); + // MS Excel VBA: Sets the number of sheets in new workbooks. + // Status: implemented - uses ScAppOptions + virtual void SAL_CALL setSheetsInNewWorkbook( sal_Int32 nSheets ); + // MS Excel VBA: Returns the number of sheets in new workbooks. + // Status: implemented - uses ScAppOptions + virtual sal_Int32 SAL_CALL getSheetsInNewWorkbook(); + // XHelperInterface + // MS Excel VBA: Returns the implementation name of this service. + // Status: implemented - returns "ScVbaApplication" virtual rtl::OUString& getServiceImplName(); + // MS Excel VBA: Returns the service names supported by this implementation. + // Status: implemented - returns "ooo.vba.excel.Application" virtual css::uno::Sequence getServiceNames(); }; #endif /* SC_VBA_APPLICATION_HXX */ diff --git a/main/sc/source/ui/vba/vbacondition.hxx b/main/sc/source/ui/vba/vbacondition.hxx index df647b1806e..c62906d5eff 100644 --- a/main/sc/source/ui/vba/vbacondition.hxx +++ b/main/sc/source/ui/vba/vbacondition.hxx @@ -26,6 +26,7 @@ #include #include #include +#include template< typename Ifc1 > class ScVbaCondition : public InheritedHelperInterfaceImpl1< Ifc1 > @@ -36,6 +37,8 @@ protected: css::uno::Reference< css::sheet::XSheetCondition > mxSheetCondition; public: ScVbaCondition( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::sheet::XSheetCondition >& _xSheetCondition ); + ScVbaCondition( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : ScVbaCondition_BASE( xContext ) {} + ScVbaCondition( const css::uno::Sequence< css::uno::Any >& /*args*/, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : ScVbaCondition_BASE( xContext ) {} static css::sheet::ConditionOperator retrieveAPIOperator( const css::uno::Any& _aOperator); diff --git a/main/sc/source/ui/vba/vbadictionary.cxx b/main/sc/source/ui/vba/vbadictionary.cxx new file mode 100644 index 00000000000..767d0232956 --- /dev/null +++ b/main/sc/source/ui/vba/vbadictionary.cxx @@ -0,0 +1,488 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + + +#include "vbadictionary.hxx" +#include "helperdecl.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; + +ScVbaDictionary::ScVbaDictionary(const uno::Reference< uno::XComponentContext >& xContext) + : mnCompareMode(0) +{ + (void)xContext; +} + +bool ScVbaDictionary::isObjectKey(const uno::Any& aKey) +{ + return (aKey.getValueTypeClass() == uno::TypeClass_INTERFACE); +} + +OUString ScVbaDictionary::formatKey(const uno::Any& aKey) +{ + OUStringBuffer sBuf; + switch (aKey.getValueTypeClass()) + { + case uno::TypeClass_STRING: + { + OUString sVal; + aKey >>= sVal; + sBuf.append(sVal); + break; + } + case uno::TypeClass_DOUBLE: + { + double dVal = 0.0; + aKey >>= dVal; + sBuf.append(static_cast(dVal)); + break; + } + case uno::TypeClass_LONG: + { + sal_Int32 nVal = 0; + aKey >>= nVal; + sBuf.append(nVal); + break; + } + case uno::TypeClass_BOOLEAN: + { + sal_Bool bVal = false; + aKey >>= bVal; + sBuf.append(OUString::createFromAscii(bVal ? "True" : "False")); + break; + } + default: + { + sBuf.append(OUString::createFromAscii("OBJ:")); + sBuf.append(aKey.getValueType().getTypeName()); + break; + } + } + return sBuf.makeStringAndClear(); +} + +bool ScVbaDictionary::isEqualKeys(const uno::Any& aKey1, const uno::Any& aKey2, bool bCaseSensitive) +{ + // Handle object keys + if (isObjectKey(aKey1) && isObjectKey(aKey2)) + { + uno::Reference< uno::XInterface > xObj1(aKey1, uno::UNO_QUERY); + uno::Reference< uno::XInterface > xObj2(aKey2, uno::UNO_QUERY); + return (xObj1.get() == xObj2.get()); + } + if (isObjectKey(aKey1) || isObjectKey(aKey2)) + return false; + + // Handle string keys + if (aKey1.getValueTypeClass() == uno::TypeClass_STRING && + aKey2.getValueTypeClass() == uno::TypeClass_STRING) + { + OUString s1, s2; + aKey1 >>= s1; + aKey2 >>= s2; + if (bCaseSensitive) + return s1 == s2; + else + return s1.equalsIgnoreAsciiCase(s2); + } + + // Fall back to string comparison for same types + if (aKey1.getValueType() != aKey2.getValueType()) + return false; + + OUString s1 = formatKey(aKey1); + OUString s2 = formatKey(aKey2); + if (bCaseSensitive) + return s1 == s2; + else + return s1.equalsIgnoreAsciiCase(s2); +} + +sal_Int32 ScVbaDictionary::findKeyIndex(const uno::Any& aKey) +{ + bool bCaseSensitive = (mnCompareMode == 0); + for (sal_Int32 i = 0; i < static_cast(maEntries.size()); ++i) + { + if (isEqualKeys(maEntries[i].aKey, aKey, bCaseSensitive)) + return i; + } + return -1; +} + +void ScVbaDictionary::Add(const uno::Any& Key, const uno::Any& Item) +{ + sal_Int32 nIndex = findKeyIndex(Key); + if (nIndex >= 0) + { + throw script::BasicErrorException( + OUString::createFromAscii("Duplicate key"), + uno::Reference< uno::XInterface >(), + 457, + OUString(RTL_CONSTASCII_USTRINGPARAM("Scripting.Dictionary")) + ); + } + + KeyEntry entry; + entry.aKey = Key; + entry.aItem = Item; + entry.bIsObjectKey = isObjectKey(Key); + entry.bIsItemObject = (Item.getValueTypeClass() == uno::TypeClass_INTERFACE); + + maEntries.push_back(entry); +} + +sal_Bool ScVbaDictionary::Exists(const uno::Any& Key) +{ + return findKeyIndex(Key) >= 0; +} + +uno::Any ScVbaDictionary::getItem(const uno::Any& Key) +{ + sal_Int32 nIndex = findKeyIndex(Key); + if (nIndex < 0) + { + return uno::Any(); // Empty/Nothing for missing key + } + return maEntries[nIndex].aItem; +} + +void ScVbaDictionary::setItem(const uno::Any& Key, const uno::Any& Item) +{ + sal_Int32 nIndex = findKeyIndex(Key); + if (nIndex >= 0) + { + maEntries[nIndex].aItem = Item; + maEntries[nIndex].bIsItemObject = (Item.getValueTypeClass() == uno::TypeClass_INTERFACE); + } + else + { + Add(Key, Item); + } +} + +uno::Any ScVbaDictionary::Item(const uno::Any& Key) +{ + return getItem(Key); +} + +uno::Any SAL_CALL ScVbaDictionary::invoke( + const OUString& FunctionName, + const uno::Sequence< uno::Any >& Params, + uno::Sequence< sal_Int16 >& OutParamIndex, + uno::Sequence< uno::Any >& OutParam) +{ + uno::Any aResult; + + if (FunctionName.equalsIgnoreAsciiCase(OUString::createFromAscii("Item"))) + { + if (Params.getLength() == 1) + { + aResult = getItem(Params[0]); + } + else if (Params.getLength() == 2) + { + // dict("key") = value - set the item + setItem(Params[0], Params[1]); + OutParamIndex.realloc(1); + OutParamIndex[0] = 1; + OutParam.realloc(1); + OutParam[0] = Params[1]; + } + else + { + throw lang::IllegalArgumentException( + OUString::createFromAscii("Item requires 1 or 2 parameters"), + uno::Reference< uno::XInterface >(), + 0); + } + } + else if (FunctionName.equalsIgnoreAsciiCase(OUString::createFromAscii("Add"))) + { + if (Params.getLength() < 2) + throw lang::IllegalArgumentException(OUString::createFromAscii("Add requires Key and Item"), + uno::Reference< uno::XInterface >(), 0); + Add(Params[0], Params[1]); + } + else if (FunctionName.equalsIgnoreAsciiCase(OUString::createFromAscii("Key"))) + { + if (Params.getLength() == 1) + { + aResult = Params[0]; + } + else if (Params.getLength() == 2) + { + sal_Int32 nIndex = findKeyIndex(Params[0]); + if (nIndex >= 0) + maEntries[nIndex].aKey = Params[1]; + OutParamIndex.realloc(1); + OutParamIndex[0] = 1; + OutParam.realloc(1); + OutParam[0] = Params[1]; + } + } + else if (FunctionName.equalsIgnoreAsciiCase(OUString::createFromAscii("Exists"))) + { + aResult <<= Exists(Params[0]); + } + else if (FunctionName.equalsIgnoreAsciiCase(OUString::createFromAscii("Keys"))) + { + aResult = Keys(); + } + else if (FunctionName.equalsIgnoreAsciiCase(OUString::createFromAscii("Items"))) + { + aResult = Items(); + } + else if (FunctionName.equalsIgnoreAsciiCase(OUString::createFromAscii("Remove"))) + { + Remove(Params[0]); + } + else if (FunctionName.equalsIgnoreAsciiCase(OUString::createFromAscii("RemoveAll"))) + { + RemoveAll(); + } + else + { + throw script::BasicErrorException( + OUString::createFromAscii("Unknown method: ") + FunctionName, + uno::Reference< uno::XInterface >(), + 438, + FunctionName + ); + } + + return aResult; +} + +void SAL_CALL ScVbaDictionary::setValue(const OUString& PropertyName, const uno::Any& Value) +{ + if (PropertyName.equalsIgnoreAsciiCase(OUString::createFromAscii("CompareMode"))) + { + sal_Int32 nMode = 0; + if ((Value >>= nMode) || nMode == 0) + { + setCompareMode(nMode); + } + } + else + { + throw beans::UnknownPropertyException( + OUString::createFromAscii("Unknown property: ") + PropertyName, + static_cast< script::XInvocation* >(this) + ); + } +} + +uno::Any SAL_CALL ScVbaDictionary::getValue(const OUString& PropertyName) +{ + if (PropertyName.equalsIgnoreAsciiCase(OUString::createFromAscii("Count"))) + { + return uno::makeAny(getCount()); + } + else if (PropertyName.equalsIgnoreAsciiCase(OUString::createFromAscii("CompareMode"))) + { + return uno::makeAny(getCompareMode()); + } + else if (PropertyName.equalsIgnoreAsciiCase(OUString::createFromAscii("Keys"))) + { + return Keys(); + } + else if (PropertyName.equalsIgnoreAsciiCase(OUString::createFromAscii("Items"))) + { + return Items(); + } + return uno::Any(); +} + +sal_Bool SAL_CALL ScVbaDictionary::hasMethod(const OUString& Name) +{ + return (Name.equalsIgnoreAsciiCase(OUString::createFromAscii("Item")) || + Name.equalsIgnoreAsciiCase(OUString::createFromAscii("Key")) || + Name.equalsIgnoreAsciiCase(OUString::createFromAscii("Add")) || + Name.equalsIgnoreAsciiCase(OUString::createFromAscii("Exists")) || + Name.equalsIgnoreAsciiCase(OUString::createFromAscii("Keys")) || + Name.equalsIgnoreAsciiCase(OUString::createFromAscii("Items")) || + Name.equalsIgnoreAsciiCase(OUString::createFromAscii("Remove")) || + Name.equalsIgnoreAsciiCase(OUString::createFromAscii("RemoveAll"))); +} + +sal_Bool SAL_CALL ScVbaDictionary::hasProperty(const OUString& Name) +{ + return (Name.equalsIgnoreAsciiCase(OUString::createFromAscii("Count")) || + Name.equalsIgnoreAsciiCase(OUString::createFromAscii("CompareMode")) || + Name.equalsIgnoreAsciiCase(OUString::createFromAscii("Keys")) || + Name.equalsIgnoreAsciiCase(OUString::createFromAscii("Items"))); +} + +uno::Reference< beans::XIntrospectionAccess > SAL_CALL ScVbaDictionary::getIntrospection() +{ + return uno::Reference< beans::XIntrospectionAccess >(); +} + +uno::Any ScVbaDictionary::Keys() +{ + uno::Sequence< uno::Any > aKeys(maEntries.size()); + for (sal_Int32 i = 0; i < static_cast(maEntries.size()); ++i) + { + aKeys[i] = maEntries[i].aKey; + } + uno::Any aResult; + aResult <<= aKeys; + return aResult; +} + +uno::Any ScVbaDictionary::Items() +{ + uno::Sequence< uno::Any > aItems(maEntries.size()); + for (sal_Int32 i = 0; i < static_cast(maEntries.size()); ++i) + { + aItems[i] = maEntries[i].aItem; + } + uno::Any aResult; + aResult <<= aItems; + return aResult; +} + +void ScVbaDictionary::Remove(const uno::Any& Key) +{ + sal_Int32 nIndex = findKeyIndex(Key); + if (nIndex < 0) + { + throw script::BasicErrorException( + OUString::createFromAscii("Key not found"), + uno::Reference< uno::XInterface >(), + 32811, + OUString(RTL_CONSTASCII_USTRINGPARAM("Scripting.Dictionary")) + ); + } + maEntries.erase(maEntries.begin() + nIndex); +} + +void ScVbaDictionary::RemoveAll() +{ + maEntries.clear(); +} + +sal_Int32 ScVbaDictionary::getCount() +{ + return static_cast(maEntries.size()); +} + +void SAL_CALL ScVbaDictionary::setCount(sal_Int32 /*nCount*/) +{ +} + +sal_Int32 ScVbaDictionary::getCompareMode() +{ + return mnCompareMode; +} + +void ScVbaDictionary::setCompareMode(sal_Int32 CompareMode) +{ + mnCompareMode = CompareMode; +} + +OUString SAL_CALL ScVbaDictionary::getDefaultMethodName() +{ + return OUString(RTL_CONSTASCII_USTRINGPARAM("Item")); +} + +uno::Reference< beans::XPropertySetInfo > SAL_CALL ScVbaDictionary::getPropertySetInfo() +{ + return uno::Reference< beans::XPropertySetInfo >(); +} + +void SAL_CALL ScVbaDictionary::setPropertyValue(const OUString& PropertyName, const uno::Any& Value) +{ + setValue(PropertyName, Value); +} + +uno::Any SAL_CALL ScVbaDictionary::getPropertyValue(const OUString& PropertyName) +{ + return getValue(PropertyName); +} + +void SAL_CALL ScVbaDictionary::addPropertyChangeListener(const OUString& PropertyName, + const uno::Reference< beans::XPropertyChangeListener >& xListener) +{ + (void)PropertyName; + (void)xListener; +} + +void SAL_CALL ScVbaDictionary::removePropertyChangeListener(const OUString& PropertyName, + const uno::Reference< beans::XPropertyChangeListener >& xListener) +{ + (void)PropertyName; + (void)xListener; +} + +void SAL_CALL ScVbaDictionary::addVetoableChangeListener(const OUString& PropertyName, + const uno::Reference< beans::XVetoableChangeListener >& xListener) +{ + (void)PropertyName; + (void)xListener; +} + +void SAL_CALL ScVbaDictionary::removeVetoableChangeListener(const OUString& PropertyName, + const uno::Reference< beans::XVetoableChangeListener >& xListener) +{ + (void)PropertyName; + (void)xListener; +} + +sal_Int32 ScVbaDictionary::getCreator() +{ + return 0; +} + +uno::Reference< ooo::vba::XHelperInterface > ScVbaDictionary::getParent() +{ + return uno::Reference< ooo::vba::XHelperInterface >(); +} + +uno::Any ScVbaDictionary::Application() +{ + return uno::Any(); +} + +namespace scripting +{ +namespace sdecl = comphelper::service_decl; +sdecl::vba_service_class_ > serviceImpl; +extern sdecl::ServiceDecl const serviceDecl( + serviceImpl, + "ScVbaDictionary", + "ooo.vba.scripting.Dictionary" ); +} diff --git a/main/sc/source/ui/vba/vbadictionary.hxx b/main/sc/source/ui/vba/vbadictionary.hxx new file mode 100644 index 00000000000..30b34d64b78 --- /dev/null +++ b/main/sc/source/ui/vba/vbadictionary.hxx @@ -0,0 +1,129 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + + +#ifndef SC_VBA_DICTIONARY_HXX +#define SC_VBA_DICTIONARY_HXX + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace com::sun; +using namespace com::sun::star; +using namespace ooo::vba; +using namespace ooo::vba::scripting; +using namespace rtl; + +typedef ::cppu::WeakImplHelper3< + scripting::XDictionary, + script::XInvocation, + beans::XPropertySet > ScVbaDictionary_BASE; + +class ScVbaDictionary : public ScVbaDictionary_BASE +{ +private: + struct KeyEntry + { + uno::Any aKey; + uno::Any aItem; + bool bIsObjectKey; + bool bIsItemObject; + }; + + std::vector< KeyEntry > maEntries; + sal_Int32 mnCompareMode; + + static bool isEqualKeys(const uno::Any& aKey1, const uno::Any& aKey2, bool bCaseSensitive); + static bool isObjectKey(const uno::Any& aKey); + sal_Int32 findKeyIndex(const uno::Any& aKey); + static OUString formatKey(const uno::Any& aKey); + bool keysEqual(const OUString& aKey1, const OUString& aKey2) const; + uno::Any getItem(const uno::Any& Key); + void setItem(const uno::Any& Key, const uno::Any& Item); + +public: + explicit ScVbaDictionary(const uno::Reference< uno::XComponentContext >& xContext); + virtual ~ScVbaDictionary() {} + + // XDictionary + virtual void SAL_CALL Add(const uno::Any& Key, const uno::Any& Item); + virtual sal_Bool SAL_CALL Exists(const uno::Any& Key); + virtual uno::Any SAL_CALL Items(); + virtual uno::Any SAL_CALL Keys(); + virtual void SAL_CALL Remove(const uno::Any& Key); + virtual void SAL_CALL RemoveAll(); + virtual uno::Any SAL_CALL Item(const uno::Any& Key); + virtual sal_Int32 SAL_CALL getCount(); + virtual void SAL_CALL setCount(sal_Int32 /*nCount*/); + virtual sal_Int32 SAL_CALL getCompareMode(); + virtual void SAL_CALL setCompareMode(sal_Int32 CompareMode); + + // XDefaultMethod + virtual OUString SAL_CALL getDefaultMethodName(); + + // XInvocation + virtual uno::Reference< beans::XIntrospectionAccess > SAL_CALL getIntrospection(); + virtual uno::Any SAL_CALL invoke( + const OUString& FunctionName, + const uno::Sequence< uno::Any >& Params, + uno::Sequence< sal_Int16 >& OutParamIndex, + uno::Sequence< uno::Any >& OutParam); + virtual void SAL_CALL setValue(const OUString& PropertyName, const uno::Any& Value); + virtual uno::Any SAL_CALL getValue(const OUString& PropertyName); + virtual sal_Bool SAL_CALL hasMethod(const OUString& Name); + virtual sal_Bool SAL_CALL hasProperty(const OUString& Name); + + // XPropertySet (for UNO introspection) + virtual uno::Reference< beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(); + virtual void SAL_CALL setPropertyValue(const OUString& PropertyName, const uno::Any& Value); + virtual uno::Any SAL_CALL getPropertyValue(const OUString& PropertyName); + virtual void SAL_CALL addPropertyChangeListener(const OUString& PropertyName, + const uno::Reference< beans::XPropertyChangeListener >& xListener); + virtual void SAL_CALL removePropertyChangeListener(const OUString& PropertyName, + const uno::Reference< beans::XPropertyChangeListener >& xListener); + virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, + const uno::Reference< beans::XVetoableChangeListener >& xListener); + virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, + const uno::Reference< beans::XVetoableChangeListener >& xListener); + + // XHelperInterface + virtual sal_Int32 SAL_CALL getCreator(); + virtual uno::Reference< ooo::vba::XHelperInterface > SAL_CALL getParent(); + virtual uno::Any SAL_CALL Application(); +}; + +#endif // SC_VBA_DICTIONARY_HXX diff --git a/main/sc/source/ui/vba/vbafiledialog.cxx b/main/sc/source/ui/vba/vbafiledialog.cxx new file mode 100644 index 00000000000..122c5819f9d --- /dev/null +++ b/main/sc/source/ui/vba/vbafiledialog.cxx @@ -0,0 +1,261 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "vbafiledialog.hxx" +#include "helperdecl.hxx" +#include "comphelper/processfactory.hxx" +#include +#include +#include +#include +#include +#include +#include "tools/urlobj.hxx" +#include + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + + +ScVbaFileDialog::ScVbaFileDialog( const css::uno::Reference< ooo::vba::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel >& xModel ) +: ScVbaFileDialog_BASE( xParent, xContext ), m_xModel( xModel ) +{ + m_nDialogType = 3; + m_bAllowMultiSelect = sal_True; + m_pSelectedItems = new VbaFileDialogSelectedItems(xParent, xContext, + uno::Reference< container::XIndexAccess >( + static_cast< container::XIndexAccess* >( &m_FileDialogSelectedObj ), + UNO_QUERY )); +} + +ScVbaFileDialog::ScVbaFileDialog( const css::uno::Sequence< css::uno::Any >& /*args*/, + const css::uno::Reference< css::uno::XComponentContext >& xContext ) +: ScVbaFileDialog_BASE( xContext ), m_xModel(), m_pSelectedItems(NULL) +{ + m_nDialogType = 3; + m_bAllowMultiSelect = sal_True; +} + +ScVbaFileDialog::~ScVbaFileDialog() +{ + if (m_pSelectedItems != NULL) + { + delete m_pSelectedItems; + } +} + +rtl::OUString& +ScVbaFileDialog::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFileDialog") ); + return sImplName; +} + +css::uno::Sequence +ScVbaFileDialog::getServiceNames() +{ + static Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.FileDialog" ) ); + } + return aServiceNames; +} + +sal_Int32 SAL_CALL +ScVbaFileDialog::getMsoFileDialogType() throw ( css::uno::RuntimeException ) +{ + return m_nDialogType; +} + +void SAL_CALL +ScVbaFileDialog::setMsoFileDialogType( sal_Int32 nType ) throw ( css::uno::RuntimeException ) +{ + m_nDialogType = nType; +} + +rtl::OUString SAL_CALL +ScVbaFileDialog::getTitle() throw ( css::uno::RuntimeException ) +{ + return m_sTitle; +} + +void SAL_CALL +ScVbaFileDialog::setTitle( const rtl::OUString& rTitle ) throw ( css::uno::RuntimeException ) +{ + m_sTitle = rTitle; +} + +sal_Bool SAL_CALL +ScVbaFileDialog::getAllowMultiSelect() throw ( css::uno::RuntimeException ) +{ + return m_bAllowMultiSelect; +} + +void SAL_CALL +ScVbaFileDialog::setAllowMultiSelect( sal_Bool bAllow ) throw ( css::uno::RuntimeException ) +{ + m_bAllowMultiSelect = bAllow; +} + +css::uno::Reference< ooo::vba::XFileDialogSelectedItems > SAL_CALL +ScVbaFileDialog::getSelectedItems() throw ( css::uno::RuntimeException ) +{ + return css::uno::Reference< ooo::vba::XFileDialogSelectedItems >( m_pSelectedItems ); +} + +sal_Int32 SAL_CALL +ScVbaFileDialog::Show() throw ( css::uno::RuntimeException ) +{ + // Returns an Integer indicating if user pressed "Open" button(-1) or "Cancel" button(0). + sal_Int32 nResult = -1; + try + { + m_sSelectedItems.realloc(0); + + const ::rtl::OUString sServiceName = ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.FilePicker" ); + + Reference< lang::XMultiServiceFactory > xMSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY ); + // Map MsoFileDialogType to appropriate AOO picker template. + // msoFileDialogOpen = 1, msoFileDialogSaveAs = 2, + // msoFileDialogFilePicker = 3 (default), msoFileDialogFolderPicker = 4 + // Note: AOO's current FilePicker API does not expose a dedicated folder + // picker template; we fall back to FILEOPEN_SIMPLE for that case. + sal_Int16 nTemplateDesc = ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE; + switch ( m_nDialogType ) + { + case 1: // msoFileDialogOpen + nTemplateDesc = ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE; + break; + case 2: // msoFileDialogSaveAs + nTemplateDesc = ui::dialogs::TemplateDescription::FILESAVE_SIMPLE; + break; + case 3: // msoFileDialogFilePicker + nTemplateDesc = ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE; + break; + case 4: // msoFileDialogFolderPicker - fall back to FILEOPEN_SIMPLE + default: + nTemplateDesc = ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE; + break; + } + Sequence< uno::Any > aDialogType( 1 ); + aDialogType[0] <<= nTemplateDesc; + Reference< ui::dialogs::XFilePicker > xFilePicker( xMSF->createInstanceWithArguments( sServiceName, aDialogType ), UNO_QUERY ); + Reference< ui::dialogs::XFilePicker2 > xFilePicker2( xFilePicker, UNO_QUERY ); + Reference< ui::dialogs::XFilterManager > xFilterManager( xFilePicker, UNO_QUERY ); + if ( xFilePicker.is() ) + { + // Apply the title if one was set (XFilePicker inherits + // XExecutableDialog which provides setTitle) + if ( m_sTitle.getLength() > 0 ) + { + uno::Reference< ui::dialogs::XExecutableDialog > xExecDialog( xFilePicker, UNO_QUERY ); + if ( xExecDialog.is() ) + xExecDialog->setTitle( m_sTitle ); + } + xFilePicker->setMultiSelectionMode( m_bAllowMultiSelect ); + // Only when there is no any filter in the msoFileDialogFilePicker dialog, then we need to add the All File Filter. + if ( xFilterManager.is() && xFilterManager->getCurrentFilter().equalsAscii("") ) + { + xFilterManager->appendFilter( rtl::OUString::createFromAscii( "All Files" ), rtl::OUString::createFromAscii( "*.*" ) ); + } + if ( xFilePicker->execute() ) + { + sal_Bool bUseXFilePicker2 = sal_False; + Reference< lang::XServiceInfo > xServiceInfo( xFilePicker, UNO_QUERY ); + if (xServiceInfo.is()) + { + rtl::OUString sImplName = xServiceInfo->getImplementationName(); + if (sImplName.equalsAscii("com.sun.star.comp.fpicker.VistaFileDialog") || + sImplName.equalsAscii("com.sun.star.ui.dialogs.SalGtkFilePicker")) + { + bUseXFilePicker2 = sal_True; + } + } + if ( bUseXFilePicker2 && xFilePicker2.is() ) + { + // On Linux, XFilePicker->getFiles() always return one selected file although we select + // more than one file, also on Vista XFilePicker->getFiles() does not work well too, + // so we call XFilePicker2->getSelectedFiles() to get selected files. + m_sSelectedItems = xFilePicker2->getSelectedFiles(); + } + else + { + // If only one file is selected, the first entry of the sequence contains the complete path/filename in + // URL format. If multiple files are selected, the first entry of the sequence contains the path in URL + // format, and the other entries contains the names of the selected files without path information. + Sequence< rtl::OUString > aSelectedFiles = xFilePicker->getFiles(); + sal_Int32 iFileCount = aSelectedFiles.getLength(); + if ( iFileCount > 1 ) + { + m_sSelectedItems.realloc( iFileCount - 1 ); + INetURLObject aPath( aSelectedFiles[0] ); + aPath.setFinalSlash(); + for ( sal_Int32 i = 1; i < iFileCount; i++ ) + { + if ( aSelectedFiles[i].indexOf ('/') > 0 || aSelectedFiles[i].indexOf ('\\') > 0 ) + { + m_sSelectedItems[i - 1] = aSelectedFiles[i]; + } + else + { + if ( i == 1 ) + aPath.Append( aSelectedFiles[i] ); + else + aPath.setName( aSelectedFiles[i] ); + m_sSelectedItems[i - 1] = aPath.GetMainURL(INetURLObject::NO_DECODE); + } + } + } + else if ( iFileCount == 1 ) + { + m_sSelectedItems = aSelectedFiles; + } + } + + sal_Int32 iFileCount = m_sSelectedItems.getLength(); + rtl::OUString aTemp; + for ( sal_Int32 i = 0; i < iFileCount; i++ ) + { + INetURLObject aObj( m_sSelectedItems[i] ); + if ( aObj.GetProtocol() == INET_PROT_FILE ) + { + aTemp = aObj.PathToFileName(); + m_sSelectedItems[i] = aTemp.getLength() > 0 ? aTemp : m_sSelectedItems[i]; + } + } + } + else + { + nResult = 0; + } + } + + m_FileDialogSelectedObj.SetSelectedFile(m_sSelectedItems); + } + catch( const uno::Exception& ) + { + return 0; + } + + return nResult; +} diff --git a/main/sc/source/ui/vba/vbafiledialog.hxx b/main/sc/source/ui/vba/vbafiledialog.hxx new file mode 100644 index 00000000000..e727dad17d2 --- /dev/null +++ b/main/sc/source/ui/vba/vbafiledialog.hxx @@ -0,0 +1,92 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SC_VBA_FILEDIALOG_HXX +#define SC_VBA_FILEDIALOG_HXX + +#include +#include +#include +#include +#include +#include "vbafiledialogselecteditems.hxx" + +typedef InheritedHelperInterfaceImpl1< ooo::vba::XFileDialog > ScVbaFileDialog_BASE; + +class ScVbaFileDialog : public ScVbaFileDialog_BASE +{ +public: + // MS Excel VBA: Constructs FileDialog with parent, context, and model. + // Status: implemented + ScVbaFileDialog( const css::uno::Reference< ooo::vba::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::frame::XModel >& xModel ); + // MS Excel VBA: Factory constructor for service instantiation. + // Status: implemented + ScVbaFileDialog( const css::uno::Sequence< css::uno::Any >& args, + const css::uno::Reference< css::uno::XComponentContext >& xContext ); + // MS Excel VBA: Destructor. + // Status: implemented + virtual ~ScVbaFileDialog(); + + // XHelperInterface + // MS Excel VBA: Returns the implementation name for UNO service identification. + // Status: implemented - returns "ScVbaFileDialog" + virtual rtl::OUString& getServiceImplName(); + // MS Excel VBA: Returns the service names this implementation supports. + // Status: implemented - returns "ooo.vba.excel.FileDialog" + virtual css::uno::Sequence getServiceNames(); + + // XFileDialog + // MS Excel VBA: Returns the dialog type (msoFileDialogFilePicker, etc.). + // Status: implemented - returns internal dialog type (default 3 = file picker) + virtual sal_Int32 SAL_CALL getMsoFileDialogType() throw ( css::uno::RuntimeException ); + // MS Excel VBA: Sets the dialog type. + // Status: implemented + virtual void SAL_CALL setMsoFileDialogType( sal_Int32 nType ) throw ( css::uno::RuntimeException ); + // MS Excel VBA: Returns the dialog title. + // Status: implemented + virtual rtl::OUString SAL_CALL getTitle() throw ( css::uno::RuntimeException ); + // MS Excel VBA: Sets the dialog title. + // Status: implemented + virtual void SAL_CALL setTitle( const rtl::OUString& rTitle ) throw ( css::uno::RuntimeException ); + // MS Excel VBA: Gets/sets whether multiple file selection is enabled. + // Status: implemented + virtual sal_Bool SAL_CALL getAllowMultiSelect() throw ( css::uno::RuntimeException ); + virtual void SAL_CALL setAllowMultiSelect( sal_Bool bAllow ) throw ( css::uno::RuntimeException ); + // MS Excel VBA: Returns the selected items in the dialog. + // Status: implemented - returns SelectedItems collection + virtual css::uno::Reference< ooo::vba::XFileDialogSelectedItems > SAL_CALL getSelectedItems() throw ( css::uno::RuntimeException ); + // MS Excel VBA: Displays the file dialog and returns user's selection status. + // Status: implemented - wraps UNO FilePicker service + virtual sal_Int32 SAL_CALL Show() throw ( css::uno::RuntimeException ); + +private: + css::uno::Reference< css::frame::XModel > m_xModel; + sal_Int32 m_nDialogType; + rtl::OUString m_sTitle; + sal_Bool m_bAllowMultiSelect; + css::uno::Sequence< rtl::OUString > m_sSelectedItems; + VbaFileDialogSelectedItems *m_pSelectedItems; + VbaFileDialogSelectedObj m_FileDialogSelectedObj; +}; + +#endif diff --git a/main/sc/source/ui/vba/vbafiledialogselecteditems.cxx b/main/sc/source/ui/vba/vbafiledialogselecteditems.cxx new file mode 100644 index 00000000000..2d52bd2dbfd --- /dev/null +++ b/main/sc/source/ui/vba/vbafiledialogselecteditems.cxx @@ -0,0 +1,145 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "vbafiledialogselecteditems.hxx" + +using namespace ::com::sun::star; + +VbaFileDialogSelectedItems::VbaFileDialogSelectedItems( + const css::uno::Reference< ooo::vba::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ) + : FileDialogSelectedItems_BASE( xParent, xContext, xIndexAccess ) +{ +} + + +rtl::OUString& VbaFileDialogSelectedItems::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaFileDialogSelectedItems") ); + return sImplName; +} + +css::uno::Sequence< rtl::OUString > VbaFileDialogSelectedItems::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.FileDialogSelectedItems" ) ); + } + return aServiceNames; +} + +css::uno::Any VbaFileDialogSelectedItems::createCollectionObject( const css::uno::Any& aSource ) +{ + css::uno::Any aRet; + aRet = aSource; + return aRet; +} + + +css::uno::Type SAL_CALL +VbaFileDialogSelectedItems::getElementType() throw (css::uno::RuntimeException) +{ + return ooo::vba::XFileDialogSelectedItems::static_type(0); +} + +css::uno::Reference< css::container::XEnumeration > SAL_CALL +VbaFileDialogSelectedItems::createEnumeration() throw (css::uno::RuntimeException) +{ + css::uno::Reference< css::container::XEnumeration > xEnumRet( m_xIndexAccess, css::uno::UNO_QUERY ); + return xEnumRet; +} + + +// VbaFileDialogSelectedObj +//////////////////////////////////////////////////////////////////////////// + +VbaFileDialogSelectedObj::VbaFileDialogSelectedObj() +{ + m_nIndex = 0; +} + + +sal_Bool +VbaFileDialogSelectedObj::SetSelectedFile( css::uno::Sequence< rtl::OUString > &sFList ) +{ + m_sFileList = sFList; + return sal_True; +} + +sal_Int32 SAL_CALL +VbaFileDialogSelectedObj::getCount() throw ( css::uno::RuntimeException ) +{ + sal_Int32 nListCnt = m_sFileList.getLength(); + return nListCnt; +} + +css::uno::Any SAL_CALL VbaFileDialogSelectedObj::getByIndex( sal_Int32 nIndex ) + throw ( css::lang::IndexOutOfBoundsException, + css::lang::WrappedTargetException, + css::uno::RuntimeException ) +{ + if ( nIndex < 0 || nIndex >= getCount() ) + { + throw css::lang::IndexOutOfBoundsException(); + } + + return uno::makeAny( m_sFileList[nIndex] ); +} + +css::uno::Type SAL_CALL +VbaFileDialogSelectedObj::getElementType() + throw ( css::uno::RuntimeException ) +{ + return getCppuType( (uno::Reference< com::sun::star::container::XIndexAccess >*)0 ); +} + +sal_Bool SAL_CALL +VbaFileDialogSelectedObj::hasElements() + throw ( css::uno::RuntimeException ) +{ + return ( getCount() != 0 ); +} + +sal_Bool SAL_CALL +VbaFileDialogSelectedObj::hasMoreElements() + throw ( css::uno::RuntimeException ) +{ + if ( getCount() > m_nIndex ) + { + return sal_True; + } + return sal_False; +} + +css::uno::Any SAL_CALL +VbaFileDialogSelectedObj::nextElement() + throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) +{ + if ( !hasMoreElements() ) + { + throw container::NoSuchElementException(); + } + + return uno::makeAny( m_sFileList[m_nIndex++] ); +} diff --git a/main/sc/source/ui/vba/vbafiledialogselecteditems.hxx b/main/sc/source/ui/vba/vbafiledialogselecteditems.hxx new file mode 100644 index 00000000000..f18bdf64e3e --- /dev/null +++ b/main/sc/source/ui/vba/vbafiledialogselecteditems.hxx @@ -0,0 +1,81 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SC_VBA_FILEDIALOGSELECTEDITEMS_HXX +#define SC_VBA_FILEDIALOGSELECTEDITEMS_HXX + +#include +#include +#include +#include + +typedef CollTestImplHelper< ooo::vba::XFileDialogSelectedItems > FileDialogSelectedItems_BASE; + +class VbaFileDialogSelectedItems : public FileDialogSelectedItems_BASE +{ +public: + VbaFileDialogSelectedItems( const css::uno::Reference< ooo::vba::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ); + + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + +protected: + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence< rtl::OUString > getServiceNames(); +}; + + +class VbaFileDialogSelectedObj : public cppu::WeakImplHelper2< css::container::XIndexAccess, css::container::XEnumeration > +{ +public: + VbaFileDialogSelectedObj(); + sal_Bool SetSelectedFile( css::uno::Sequence< rtl::OUString > &sFList ); + // XIndexAccess + virtual sal_Int32 SAL_CALL getCount() throw ( css::uno::RuntimeException ); + + virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) + throw ( css::lang::IndexOutOfBoundsException, + css::lang::WrappedTargetException, + css::uno::RuntimeException ); + + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() + throw ( css::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL hasElements() throw ( css::uno::RuntimeException ); + + // XEnumeration + virtual sal_Bool SAL_CALL hasMoreElements() throw ( css::uno::RuntimeException ); + virtual css::uno::Any SAL_CALL nextElement() + throw ( css::container::NoSuchElementException, + css::lang::WrappedTargetException, + css::uno::RuntimeException ); + +protected: +private: + css::uno::Sequence< rtl::OUString > m_sFileList; + sal_Int32 m_nIndex; +}; + +#endif diff --git a/main/sc/source/ui/vba/vbafilesearch.cxx b/main/sc/source/ui/vba/vbafilesearch.cxx new file mode 100644 index 00000000000..a00e659c477 --- /dev/null +++ b/main/sc/source/ui/vba/vbafilesearch.cxx @@ -0,0 +1,298 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "vbafilesearch.hxx" +#include "helperdecl.hxx" +#include "vbaapplication.hxx" +#include "vbafoundfiles.hxx" +#include "helperdecl.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace ::ooo::vba; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::ucb; +using namespace ::com::sun::star::lang; +using namespace comphelper; + +static Reference< XSimpleFileAccess3 > getFileAccess( void ) +{ + static Reference< XSimpleFileAccess3 > xSFI; + if( !xSFI.is() ) + { + Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory(); + if( xSMgr.is() ) + { + xSFI = Reference< XSimpleFileAccess3 >( xSMgr->createInstance + ( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY ); + } + } + return xSFI; +} + +ScVbaFileSearch::ScVbaFileSearch( ScVbaApplication* pApp, const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) + : ScVbaFileSearchImpl_BASE( xParent, xContext ), m_pApplication( pApp ) +{ + NewSearch(); +} + +ScVbaFileSearch::ScVbaFileSearch( const css::uno::Sequence< css::uno::Any >& /*args*/, const css::uno::Reference< css::uno::XComponentContext >& xContext ) + : ScVbaFileSearchImpl_BASE( xContext ), m_pApplication( NULL ) +{ + NewSearch(); +} + +ScVbaFileSearch::~ScVbaFileSearch() +{ +} + +::rtl::OUString SAL_CALL ScVbaFileSearch::getFileName() throw (css::uno::RuntimeException) +{ + return m_sFileName; +} + +void SAL_CALL ScVbaFileSearch::setFileName( const ::rtl::OUString& _fileName ) throw (css::uno::RuntimeException) +{ + m_sFileName = _fileName; +} + +::rtl::OUString SAL_CALL ScVbaFileSearch::getLookIn() throw (css::uno::RuntimeException) +{ + return m_sLookIn; +} + +void SAL_CALL ScVbaFileSearch::setLookIn( const ::rtl::OUString& _lookIn ) throw (css::uno::RuntimeException) +{ + m_sLookIn = _lookIn; +} + +sal_Bool SAL_CALL ScVbaFileSearch::getSearchSubFolders() throw (css::uno::RuntimeException) +{ + return m_bSearchSubFolders; +} + +void SAL_CALL ScVbaFileSearch::setSearchSubFolders( sal_Bool _searchSubFolders ) throw (css::uno::RuntimeException) +{ + m_bSearchSubFolders = _searchSubFolders; +} + +sal_Bool SAL_CALL ScVbaFileSearch::getMatchTextExactly() throw (css::uno::RuntimeException) +{ + return m_bMatchTextExactly; +} + +void SAL_CALL ScVbaFileSearch::setMatchTextExactly( sal_Bool _matchTextExactly ) throw (css::uno::RuntimeException) +{ + m_bMatchTextExactly = _matchTextExactly; +} + +static bool IsWildCard( const ::rtl::OUString& fileName ) +{ + static sal_Char cWild1 = '*'; + static sal_Char cWild2 = '?'; + + return ( ( fileName.indexOf( cWild1 ) >= 0 ) + || ( fileName.indexOf( cWild2 ) >= 0 ) ); +} + +static void SearchWildCard( const WildCard& wildCard, const ::rtl::OUString& aDir, bool bSearchSubFolders, css::uno::Sequence< rtl::OUString >& aSearchedFiles ) +{ + Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); + Sequence< rtl::OUString > aDirSeq; + try + { + if ( xSFI.is() ) + { + aDirSeq = xSFI->getFolderContents( aDir, bSearchSubFolders ); + } + } + catch( css::uno::Exception& ) + { + } + sal_Int32 nLength = aDirSeq.getLength(); + for ( sal_Int32 i = 0; i < nLength; i++ ) + { + rtl::OUString aURLStr = aDirSeq[i]; + if ( xSFI->isFolder( aURLStr ) ) + { + if ( bSearchSubFolders ) + { + SearchWildCard( wildCard, aURLStr, true, aSearchedFiles ); + } + } + else + { + INetURLObject aFileURL( aURLStr ); + rtl::OUString aFileName = aFileURL.GetLastName( INetURLObject::DECODE_UNAMBIGUOUS ); + if ( wildCard.Matches( aFileName.toAsciiLowerCase() ) ) + { + sal_Int32 nLength = aSearchedFiles.getLength(); + aSearchedFiles.realloc( nLength + 1 ); + rtl::OUString sSystemPath; + ::osl::File::getSystemPathFromFileURL( aURLStr, sSystemPath ); + aSearchedFiles[nLength] = sSystemPath; + } + } + } +} + +static void SearchExact( const ::rtl::OUString& aFileName, const ::rtl::OUString& aDir, bool bSearchSubFolders, css::uno::Sequence< rtl::OUString >& aSearchedFiles ) +{ + Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); + Sequence< rtl::OUString > aDirSeq; + try + { + if ( xSFI.is() ) + { + aDirSeq = xSFI->getFolderContents( aDir, bSearchSubFolders ); + } + } + catch( css::uno::Exception& ) + { + } + sal_Int32 nLength = aDirSeq.getLength(); + for ( sal_Int32 i = 0; i < nLength; i++ ) + { + rtl::OUString aURLStr = aDirSeq[i]; + if ( xSFI->isFolder( aURLStr ) ) + { + if ( bSearchSubFolders ) + { + SearchExact( aFileName, aURLStr, true, aSearchedFiles ); + } + } + else + { + INetURLObject aFileURL( aURLStr ); + rtl::OUString aName = aFileURL.GetLastName( INetURLObject::DECODE_UNAMBIGUOUS ); + if ( aName.toAsciiLowerCase() == aFileName ) + { + sal_Int32 nLength = aSearchedFiles.getLength(); + aSearchedFiles.realloc( nLength + 1 ); + rtl::OUString sSystemPath; + ::osl::File::getSystemPathFromFileURL( aURLStr, sSystemPath ); + aSearchedFiles[nLength] = sSystemPath; + } + } + } +} + +sal_Int32 SAL_CALL ScVbaFileSearch::Execute() throw (css::uno::RuntimeException) +{ + m_aSearchedFiles.realloc(0); + Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); + if ( !xSFI.is() || !xSFI->isFolder( m_sLookIn ) ) + { + return 0; + } + + if ( m_sFileName == ::rtl::OUString::createFromAscii( "" ) ) + { + return 0; + } + + ::rtl::OUString aTempFileName = m_sFileName.toAsciiLowerCase(); + + if ( m_bMatchTextExactly ) + { + // When MatchTextExactly is True, only match files whose name exactly + // matches the FileName property (case-insensitive). Wildcards are NOT + // honored in this mode — they are treated as literal characters. + SearchExact( aTempFileName, m_sLookIn, m_bSearchSubFolders, m_aSearchedFiles ); + } + else + { + if ( IsWildCard( aTempFileName ) ) + { + bool bEndWithAsterisk = aTempFileName.endsWithAsciiL("*", 1); + bool bStartWithAsterisk = (aTempFileName.indexOf(::rtl::OUString::createFromAscii("*")) == 0); + if ( !bEndWithAsterisk && !bStartWithAsterisk ) + { + aTempFileName = ::rtl::OUString::createFromAscii("*") + aTempFileName + ::rtl::OUString::createFromAscii("*"); + } + } + else + { + aTempFileName = ::rtl::OUString::createFromAscii("*") + aTempFileName + ::rtl::OUString::createFromAscii("*"); + } + WildCard wildCard( aTempFileName ); + SearchWildCard( wildCard, m_sLookIn, m_bSearchSubFolders, m_aSearchedFiles ); + } + + return m_aSearchedFiles.getLength(); +} + +// 2009-11-5 set ScVbaApplication::getDefaultFilePath() as the InitPath for FileSearch +::rtl::OUString ScVbaFileSearch::getInitPath() throw ( com::sun::star::uno::RuntimeException ) +{ + String aPath; + + if (m_pApplication != NULL) + { + aPath = m_pApplication->getDefaultFilePath(); + } + + return aPath; +} + +void SAL_CALL ScVbaFileSearch::NewSearch() throw (css::uno::RuntimeException) +{ + m_sFileName = ::rtl::OUString::createFromAscii( "" ); + m_sLookIn = getInitPath(); + m_bSearchSubFolders = false; + m_bMatchTextExactly = false; + m_aSearchedFiles.realloc(0); +} + +Reference< XFoundFiles > SAL_CALL ScVbaFileSearch::getFoundFiles() throw (css::uno::RuntimeException) +{ + VbaFoundFilesEnum* pEnum = new VbaFoundFilesEnum(m_aSearchedFiles); + css::uno::Reference< css::container::XIndexAccess > xIndexAccess( + static_cast(pEnum) ); + css::uno::Reference< ov::XFoundFiles > xFoundFiles = new VbaFoundFiles( + mxParent, mxContext, xIndexAccess ); + return xFoundFiles; +} + +rtl::OUString& ScVbaFileSearch::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaFileSearch") ); + return sImplName; +} + +css::uno::Sequence< rtl::OUString > ScVbaFileSearch::getServiceNames() +{ + static css::uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.FileSearch") ); + } + return aServiceNames; +} diff --git a/main/sc/source/ui/vba/vbafilesearch.hxx b/main/sc/source/ui/vba/vbafilesearch.hxx new file mode 100644 index 00000000000..86aba3d916e --- /dev/null +++ b/main/sc/source/ui/vba/vbafilesearch.hxx @@ -0,0 +1,100 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SC_VBA_FILESEARCH_HXX +#define SC_VBA_FILESEARCH_HXX + +#include +#include +#include +#include + +namespace css = ::com::sun::star; + +typedef InheritedHelperInterfaceImpl1< ooo::vba::XFileSearch > ScVbaFileSearchImpl_BASE; + +class ScVbaApplication; + +// MS Excel VBA: Object used to search for files on the filesystem. +// Status: implemented - wraps sc/search results into FoundFiles collection +class ScVbaFileSearch : public ScVbaFileSearchImpl_BASE +{ +private: + rtl::OUString m_sFileName; + rtl::OUString m_sLookIn; + sal_Bool m_bSearchSubFolders; + sal_Bool m_bMatchTextExactly; + ScVbaApplication* m_pApplication; + css::uno::Sequence< rtl::OUString > m_aSearchedFiles; + + // MS Excel VBA: Returns the default search directory path. + // Status: implemented - falls back to Application.DefaultFilePath + ::rtl::OUString getInitPath() throw (css::uno::RuntimeException); + +public: + // MS Excel VBA: Constructs FileSearch with application, parent, and context. + // Status: implemented + ScVbaFileSearch( ScVbaApplication* pApp, const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ); + // MS Excel VBA: Factory constructor for service instantiation. + // Status: implemented + ScVbaFileSearch( const css::uno::Sequence< css::uno::Any >& /*args*/, const css::uno::Reference< css::uno::XComponentContext >& xContext ); + // MS Excel VBA: Destructor. + // Status: implemented + virtual ~ScVbaFileSearch(); + + // Attributes + // MS Excel VBA: Gets/sets the file name criteria for the search. + // Status: implemented + virtual ::rtl::OUString SAL_CALL getFileName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFileName( const ::rtl::OUString& _fileName ) throw (css::uno::RuntimeException); + // MS Excel VBA: Gets/sets the folder path to search in. + // Status: implemented + virtual ::rtl::OUString SAL_CALL getLookIn() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLookIn( const ::rtl::OUString& _lookIn ) throw (css::uno::RuntimeException); + // MS Excel VBA: Gets/sets whether to search subfolders. + // Status: implemented + virtual sal_Bool SAL_CALL getSearchSubFolders() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSearchSubFolders( sal_Bool _searchSubFolders ) throw (css::uno::RuntimeException); + // MS Excel VBA: Gets/sets whether to match file text exactly. + // Status: implemented + virtual sal_Bool SAL_CALL getMatchTextExactly() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMatchTextExactly( sal_Bool _matchTextExactly ) throw (css::uno::RuntimeException); + // MS Excel VBA: Returns FoundFiles collection with all matching files. + // Status: implemented - returns VbaFoundFiles enum + virtual css::uno::Reference< ::ooo::vba::XFoundFiles > SAL_CALL getFoundFiles() throw (css::uno::RuntimeException); + + // MS Excel VBA: Executes the file search and returns the number of results. + // Status: implemented - delegates to SearchFiles BASIC function + virtual sal_Int32 SAL_CALL Execute() throw (css::uno::RuntimeException); + // MS Excel VBA: Clears all search criteria and results. + // Status: implemented + virtual void SAL_CALL NewSearch() throw (css::uno::RuntimeException); + + // XHelperInterface + // MS Excel VBA: Returns the implementation name for UNO service identification. + // Status: implemented - returns "ScVbaFileSearch" + virtual rtl::OUString& getServiceImplName(); + // MS Excel VBA: Returns the service names this implementation supports. + // Status: implemented - returns "ooo.vba.excel.FileSearch" + virtual css::uno::Sequence< rtl::OUString > getServiceNames(); +}; + +#endif diff --git a/main/sc/source/ui/vba/vbaformatcondition.cxx b/main/sc/source/ui/vba/vbaformatcondition.cxx index 1d619deda91..d7ee4135d06 100644 --- a/main/sc/source/ui/vba/vbaformatcondition.cxx +++ b/main/sc/source/ui/vba/vbaformatcondition.cxx @@ -21,8 +21,10 @@ #include "vbaformatcondition.hxx" +#include "helperdecl.hxx" #include "vbaformatconditions.hxx" #include +#include "helperdecl.hxx" using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -35,6 +37,10 @@ lcl_getScVbaFormatConditionsPtr( const uno::Reference< excel::XFormatConditions DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); return pFormatConditions; } +ScVbaFormatCondition::ScVbaFormatCondition( const uno::Sequence< uno::Any >& /*args*/, const uno::Reference< uno::XComponentContext >& xContext ) : ScVbaFormatCondition_BASE( xContext ) +{ +} + ScVbaFormatCondition::ScVbaFormatCondition( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< sheet::XSheetConditionalEntry >& _xSheetConditionalEntry, const uno::Reference< excel::XStyle >& _xStyle, const uno::Reference< excel::XFormatConditions >& _xFormatConditions, const uno::Reference< css::beans::XPropertySet >& _xPropertySet ) : ScVbaFormatCondition_BASE( xParent, xContext, uno::Reference< sheet::XSheetCondition >( _xSheetConditionalEntry, css::uno::UNO_QUERY_THROW ) ), moFormatConditions( _xFormatConditions ), mxStyle( _xStyle ), mxParentRangePropertySet( _xPropertySet ) { mxSheetConditionalEntries = lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getSheetConditionalEntries(); @@ -113,7 +119,7 @@ ScVbaFormatCondition::setFormula1( const uno::Any& _aFormula1) void ScVbaFormatCondition::setFormula2( const uno::Any& _aFormula2) { - ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getA1Formula(_aFormula2)) ); + ScVbaFormatCondition_BASE::setFormula2( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getA1Formula(_aFormula2)) ); } ::sal_Int32 SAL_CALL @@ -139,6 +145,18 @@ ScVbaFormatCondition::Operator( ) return ScVbaFormatCondition_BASE::Operator( sal_True ); } +rtl::OUString SAL_CALL +ScVbaFormatCondition::Formula1() +{ + return mxSheetCondition->getFormula1(); +} + +rtl::OUString SAL_CALL +ScVbaFormatCondition::Formula2() +{ + return mxSheetCondition->getFormula2(); +} + void ScVbaFormatCondition::notifyRange() { @@ -168,5 +186,5 @@ ScVbaFormatCondition::getServiceNames() aServiceNames.realloc( 1 ); aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.FormatCondition" ) ); } - return aServiceNames; + return aServiceNames; } diff --git a/main/sc/source/ui/vba/vbaformatcondition.hxx b/main/sc/source/ui/vba/vbaformatcondition.hxx index 2ea2f636508..fd892f7df6f 100644 --- a/main/sc/source/ui/vba/vbaformatcondition.hxx +++ b/main/sc/source/ui/vba/vbaformatcondition.hxx @@ -32,35 +32,76 @@ #include #include "vbacondition.hxx" +// MS Excel VBA: A condition that can be checked for a conditional formatting rule. +// Status: implemented - wraps UNO XSheetConditionalEntry typedef ScVbaCondition< ov::excel::XFormatCondition > ScVbaFormatCondition_BASE; class ScVbaFormatCondition : public ScVbaFormatCondition_BASE { protected: - rtl::OUString msStyleName; - css::uno::Reference< css::sheet::XSheetConditionalEntry > mxSheetConditionalEntry; - css::uno::Reference< css::sheet::XSheetConditionalEntries > mxSheetConditionalEntries; - css::uno::Reference< ov::excel::XFormatConditions> moFormatConditions; - css::uno::Reference< ov::excel::XStyle > mxStyle; - css::uno::Reference< css::beans::XPropertySet > mxParentRangePropertySet; + rtl::OUString msStyleName; + css::uno::Reference< css::sheet::XSheetConditionalEntry > mxSheetConditionalEntry; + css::uno::Reference< css::sheet::XSheetConditionalEntries > mxSheetConditionalEntries; + css::uno::Reference< ov::excel::XFormatConditions> moFormatConditions; + css::uno::Reference< ov::excel::XStyle > mxStyle; + css::uno::Reference< css::beans::XPropertySet > mxParentRangePropertySet; public: - ScVbaFormatCondition( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::sheet::XSheetConditionalEntry >& _xSheetConditionalEntry, const css::uno::Reference< ov::excel::XStyle >&, const css::uno::Reference< ov::excel::XFormatConditions >& _xFormatConditions, const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet ); + // MS Excel VBA: Constructs a FormatCondition from its parts (parent, context, condition, style, collection, range props). + // Status: implemented + ScVbaFormatCondition( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::sheet::XSheetConditionalEntry >& _xSheetConditionalEntry, const css::uno::Reference< ov::excel::XStyle >&, const css::uno::Reference< ov::excel::XFormatConditions >& _xFormatConditions, const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet ); + // MS Excel VBA: Factory constructor for service instantiation. + // Status: implemented + ScVbaFormatCondition( const css::uno::Sequence< css::uno::Any >& /*args*/, const css::uno::Reference< css::uno::XComponentContext >& xContext ); - void notifyRange(); - static css::sheet::ConditionOperator retrieveAPIType(sal_Int32 _nVBAType, const css::uno::Reference< css::sheet::XSheetCondition >& _xSheetCondition ); + // MS Excel VBA: Notifies the parent range that a condition changed. + // Status: implemented + void notifyRange(); + // MS Excel VBA: Maps a VBA condition type to UNO ConditionOperator. + // Status: implemented + static css::sheet::ConditionOperator retrieveAPIType(sal_Int32 _nVBAType, const css::uno::Reference< css::sheet::XSheetCondition >& _xSheetCondition ); - //Methods - virtual void SAL_CALL Delete( ); - virtual void SAL_CALL Modify( ::sal_Int32 Type, const css::uno::Any& Operator, const css::uno::Any& Formula1, const css::uno::Any& Formula2 ); - virtual ::sal_Int32 SAL_CALL Type( ); - virtual ::sal_Int32 Operator( sal_Bool ); - virtual ::sal_Int32 SAL_CALL Operator( ); - virtual void setFormula1( const css::uno::Any& _aFormula1); - virtual void setFormula2( const css::uno::Any& _aFormula2); - virtual css::uno::Reference< ::ooo::vba::excel::XInterior > SAL_CALL Interior( ); - virtual css::uno::Any SAL_CALL Borders( const css::uno::Any& Index ); - virtual css::uno::Reference< ::ooo::vba::excel::XFont > SAL_CALL Font( ); - // XHelperInterface - virtual rtl::OUString& getServiceImplName(); - virtual css::uno::Sequence getServiceNames(); + // MS Excel VBA: Methods - FormatCondition actions + // MS Excel VBA: Deletes the formatting condition and its associated XStyle. + // Status: implemented + virtual void SAL_CALL Delete( ); + // MS Excel VBA: Modifies an existing conditional formatting rule's type and parameters. + // Status: implemented - updates Type, Operator, Formula1, Formula2 + virtual void SAL_CALL Modify( ::sal_Int32 Type, const css::uno::Any& Operator, const css::uno::Any& Formula1, const css::uno::Any& Formula2 ); + // MS Excel VBA: Returns the condition type (xlCellValue or xlExpression). + // Status: implemented + virtual ::sal_Int32 SAL_CALL Type( ); + // MS Excel VBA: Returns the comparison operator type for the condition. + // Status: implemented - non-const overload for internal use + virtual ::sal_Int32 Operator( sal_Bool ); + // MS Excel VBA: Returns the comparison operator type for the condition. + // Status: implemented + virtual ::sal_Int32 SAL_CALL Operator( ); + // MS Excel VBA: Returns the first formula (or value) for the condition. + // Status: implemented + virtual rtl::OUString SAL_CALL Formula1( ); + // MS Excel VBA: Returns the second formula (or value) for the condition. + // Status: implemented + virtual rtl::OUString SAL_CALL Formula2( ); + // MS Excel VBA: Sets the first formula (or value) for the condition. + // Status: implemented + virtual void setFormula1( const css::uno::Any& _aFormula1); + // MS Excel VBA: Sets the second formula (or value) for the condition. + // Status: implemented + virtual void setFormula2( const css::uno::Any& _aFormula2); + // MS Excel VBA: Returns the Interior object (fill color, pattern) for the condition. + // Status: implemented + virtual css::uno::Reference< ::ooo::vba::excel::XInterior > SAL_CALL Interior( ); + // MS Excel VBA: Returns the Borders collection for the condition. + // Status: implemented + virtual css::uno::Any SAL_CALL Borders( const css::uno::Any& Index ); + // MS Excel VBA: Returns the Font object for the condition's text. + // Status: implemented + virtual css::uno::Reference< ::ooo::vba::excel::XFont > SAL_CALL Font( ); + // XHelperInterface + // MS Excel VBA: Returns the implementation name for UNO service identification. + // Status: implemented - returns "ScVbaFormatCondition" + virtual rtl::OUString& getServiceImplName(); + // MS Excel VBA: Returns the service names this implementation supports. + // Status: implemented - returns "ooo.vba.excel.FormatCondition" + virtual css::uno::Sequence getServiceNames(); }; #endif diff --git a/main/sc/source/ui/vba/vbaformatconditions.cxx b/main/sc/source/ui/vba/vbaformatconditions.cxx index 135bf72fca7..21e2f8e60a4 100644 --- a/main/sc/source/ui/vba/vbaformatconditions.cxx +++ b/main/sc/source/ui/vba/vbaformatconditions.cxx @@ -27,9 +27,11 @@ #include #include "vbaformatconditions.hxx" #include "vbaformatcondition.hxx" +#include "helperdecl.hxx" #include "vbaworkbook.hxx" #include "vbastyles.hxx" #include "vbaglobals.hxx" +#include "helperdecl.hxx" using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -41,9 +43,13 @@ static rtl::OUString FORMULA2( RTL_CONSTASCII_USTRINGPARAM("Formula2") ); static rtl::OUString STYLENAME( RTL_CONSTASCII_USTRINGPARAM("StyleName") ); static rtl::OUString sStyleNamePrefix( RTL_CONSTASCII_USTRINGPARAM("Excel_CondFormat") ); +ScVbaFormatConditions::ScVbaFormatConditions( const css::uno::Sequence< css::uno::Any >& /*args*/, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : ScVbaFormatConditions_BASE( css::uno::Reference< XHelperInterface >(), xContext, css::uno::Reference< container::XIndexAccess >() ) +{ +} + ScVbaFormatConditions::ScVbaFormatConditions( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< sheet::XSheetConditionalEntries >& _xSheetConditionalEntries, const uno::Reference< frame::XModel >& /*xModel*/ ) : ScVbaFormatConditions_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( _xSheetConditionalEntries, uno::UNO_QUERY_THROW ) ), mxSheetConditionalEntries( _xSheetConditionalEntries ) { - mxRangeParent.set( xParent, uno::UNO_QUERY_THROW ); + mxRangeParent.set( xParent, uno::UNO_QUERY_THROW ); uno::Reference< excel::XApplication> xApp( Application(), uno::UNO_QUERY_THROW ); mxStyles.set( xApp->getThisWorkbook()->Styles( uno::Any() ), uno::UNO_QUERY_THROW ); uno::Reference< sheet::XCellRangeAddressable > xCellRange( mxRangeParent->getCellRange(), uno::UNO_QUERY_THROW ); @@ -292,5 +298,5 @@ ScVbaFormatConditions::getServiceNames() aServiceNames.realloc( 1 ); aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.FormatConditions" ) ); } - return aServiceNames; + return aServiceNames; } diff --git a/main/sc/source/ui/vba/vbaformatconditions.hxx b/main/sc/source/ui/vba/vbaformatconditions.hxx index 9de338100ba..5e5c42e79ed 100644 --- a/main/sc/source/ui/vba/vbaformatconditions.hxx +++ b/main/sc/source/ui/vba/vbaformatconditions.hxx @@ -31,31 +31,64 @@ #include typedef CollTestImplHelper< ov::excel::XFormatConditions > ScVbaFormatConditions_BASE; +// MS Excel VBA: Collection of FormatCondition objects for a range of cells. +// Status: implemented - wraps UNO XSheetConditionalEntries class ScVbaFormatConditions: public ScVbaFormatConditions_BASE { - css::table::CellAddress maCellAddress; - css::uno::Reference< css::sheet::XSheetConditionalEntries > mxSheetConditionalEntries; - css::uno::Reference< ov::excel::XStyles > mxStyles; - css::uno::Reference< ov::excel::XRange > mxRangeParent; - css::uno::Reference< css::beans::XPropertySet > mxParentRangePropertySet; + css::table::CellAddress maCellAddress; + css::uno::Reference< css::sheet::XSheetConditionalEntries > mxSheetConditionalEntries; + css::uno::Reference< ov::excel::XStyles > mxStyles; + css::uno::Reference< ov::excel::XRange > mxRangeParent; + css::uno::Reference< css::beans::XPropertySet > mxParentRangePropertySet; public: - ScVbaFormatConditions( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::sheet::XSheetConditionalEntries >&, const css::uno::Reference< css::frame::XModel >& ); - void notifyRange(); - virtual css::uno::Reference< ov::excel::XFormatCondition > Add( ::sal_Int32 Type, const css::uno::Any& Operator, const css::uno::Any& Formula1, const css::uno::Any& Formula2, const css::uno::Reference< ov::excel::XStyle >& _xCalcStyle ); - rtl::OUString getA1Formula(const css::uno::Any& _aFormula); - rtl::OUString getStyleName(); - void removeFormatCondition( const rtl::OUString& _sStyleName, sal_Bool _bRemoveStyle); - css::uno::Reference< css::sheet::XSheetConditionalEntries > getSheetConditionalEntries() { return mxSheetConditionalEntries; } - // XFormatConditions - virtual void SAL_CALL Delete( ); - virtual css::uno::Reference< ov::excel::XFormatCondition > SAL_CALL Add( ::sal_Int32 Type, const css::uno::Any& Operator, const css::uno::Any& Formula1, const css::uno::Any& Formula2 ); - // XEnumerationAccess - virtual css::uno::Type SAL_CALL getElementType(); - virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration(); - virtual css::uno::Any createCollectionObject(const css::uno::Any&); - // XHelperInterface - virtual rtl::OUString& getServiceImplName(); - virtual css::uno::Sequence getServiceNames(); + // MS Excel VBA: Constructs FormatConditions with parent, context, conditional entries, and model. + // Status: implemented + ScVbaFormatConditions( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::sheet::XSheetConditionalEntries >&, const css::uno::Reference< css::frame::XModel >& ); + // MS Excel VBA: Factory constructor for service instantiation. + // Status: implemented + ScVbaFormatConditions( const css::uno::Sequence< css::uno::Any >& /*args*/, const css::uno::Reference< css::uno::XComponentContext >& xContext ); + // MS Excel VBA: Notifies the parent range that conditions changed. + // Status: implemented + void notifyRange(); + // MS Excel VBA: Adds a new FormatCondition to the collection with style. + // Status: implemented - creates with Type, Operator, Formula1, Formula2, and XlStyle + virtual css::uno::Reference< ov::excel::XFormatCondition > Add( ::sal_Int32 Type, const css::uno::Any& Operator, const css::uno::Any& Formula1, const css::uno::Any& Formula2, const css::uno::Reference< ov::excel::XStyle >& _xCalcStyle ); + // MS Excel VBA: Converts a VBA formula reference to A1 notation. + // Status: implemented + rtl::OUString getA1Formula(const css::uno::Any& _aFormula); + // MS Excel VBA: Returns the style name for this collection. + // Status: implemented + rtl::OUString getStyleName(); + // MS Excel VBA: Removes a format condition by style name. + // Status: implemented + void removeFormatCondition( const rtl::OUString& _sStyleName, sal_Bool _bRemoveStyle); + // MS Excel VBA: Returns the underlying conditional entries container. + // Status: implemented + css::uno::Reference< css::sheet::XSheetConditionalEntries > getSheetConditionalEntries() { return mxSheetConditionalEntries; } + // XFormatConditions + // MS Excel VBA: Deletes all conditional formatting conditions in this collection. + // Status: implemented + virtual void SAL_CALL Delete( ); + // MS Excel VBA: Adds a new FormatCondition to the collection. + // Status: implemented - Type, Operator, Formula1, Formula2 map to UNO condition + virtual css::uno::Reference< ov::excel::XFormatCondition > SAL_CALL Add( ::sal_Int32 Type, const css::uno::Any& Operator, const css::uno::Any& Formula1, const css::uno::Any& Formula2 ); + // XEnumerationAccess + // MS Excel VBA: Returns the type of objects in this collection. + // Status: implemented + virtual css::uno::Type SAL_CALL getElementType(); + // MS Excel VBA: Creates an enumeration for iterating the collection. + // Status: implemented + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration(); + // MS Excel VBA: Creates a new FormatCondition object from a source Any. + // Status: implemented + virtual css::uno::Any createCollectionObject(const css::uno::Any&); + // XHelperInterface + // MS Excel VBA: Returns the implementation name for UNO service identification. + // Status: implemented - returns "ScVbaFormatConditions" + virtual rtl::OUString& getServiceImplName(); + // MS Excel VBA: Returns the service names this implementation supports. + // Status: implemented - returns "ooo.vba.excel.FormatConditions" + virtual css::uno::Sequence getServiceNames(); }; #endif //SC_VBA_AXES_HXX diff --git a/main/sc/source/ui/vba/vbafoundfiles.cxx b/main/sc/source/ui/vba/vbafoundfiles.cxx new file mode 100644 index 00000000000..271e355fd2c --- /dev/null +++ b/main/sc/source/ui/vba/vbafoundfiles.cxx @@ -0,0 +1,158 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "vbafoundfiles.hxx" +#include "helperdecl.hxx" + +///////////////////////////////VbaFoundFilesEnum////////////////////////////////////////// +VbaFoundFilesEnum::VbaFoundFilesEnum() : m_nIndex(0) +{ + +} + +VbaFoundFilesEnum::VbaFoundFilesEnum( css::uno::Sequence& sFileList ) : m_nIndex(0), m_sFileList(sFileList) +{ + +} + +VbaFoundFilesEnum::~VbaFoundFilesEnum() +{ + +} + +void VbaFoundFilesEnum::SetFileList( css::uno::Sequence& sFileList ) +{ + m_nIndex = 0; + m_sFileList = sFileList; +} + +sal_Int32 SAL_CALL VbaFoundFilesEnum::getCount() throw ( css::uno::RuntimeException ) +{ + return m_sFileList.getLength(); +} + +css::uno::Any SAL_CALL VbaFoundFilesEnum::getByIndex( sal_Int32 nIndex ) + throw ( css::lang::IndexOutOfBoundsException, css::lang::WrappedTargetException, css::uno::RuntimeException ) +{ + if ( nIndex < 0 || nIndex >= getCount() ) + { + throw css::lang::IndexOutOfBoundsException(); + } + + return css::uno::makeAny( m_sFileList[nIndex] ); +} + +css::uno::Type SAL_CALL VbaFoundFilesEnum::getElementType() throw ( css::uno::RuntimeException ) +{ + return getCppuType( (css::uno::Reference< css::container::XIndexAccess >*)0 ); +} + +sal_Bool SAL_CALL VbaFoundFilesEnum::hasElements() throw ( css::uno::RuntimeException ) +{ + return ( getCount() != 0 ); +} + +sal_Bool SAL_CALL VbaFoundFilesEnum::hasMoreElements() throw ( css::uno::RuntimeException ) +{ + if ( getCount() > m_nIndex ) + { + return sal_True; + } + return sal_False; +} + +css::uno::Any SAL_CALL VbaFoundFilesEnum::nextElement() throw ( css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException ) +{ + if ( !hasMoreElements() ) + { + throw css::container::NoSuchElementException(); + } + + return css::uno::makeAny( m_sFileList[m_nIndex++] ); +} + +///////////////////////////////VbaFoundFiles////////////////////////////////////////// + +VbaFoundFiles::VbaFoundFiles( const css::uno::Sequence< css::uno::Any >& /*args*/, + const css::uno::Reference< css::uno::XComponentContext >& xContext ) + : VbaFoundFilesImpl_BASE( css::uno::Reference< ov::XHelperInterface >(), + xContext, + css::uno::Reference< css::container::XIndexAccess >() ) +{ + +} + +VbaFoundFiles::VbaFoundFiles( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess + ) : VbaFoundFilesImpl_BASE( xParent, xContext, xIndexAccess ) +{ + +} + +VbaFoundFiles::~VbaFoundFiles() +{ + +} + +css::uno::Reference< css::container::XEnumeration > VbaFoundFiles::createEnumeration() throw ( css::uno::RuntimeException ) +{ + css::uno::Reference< css::container::XEnumeration > xEnumRet( m_xIndexAccess, css::uno::UNO_QUERY ); + return xEnumRet; +} + +css::uno::Any VbaFoundFiles::createCollectionObject( const css::uno::Any& aSource ) +{ + return aSource; +} + +rtl::OUString SAL_CALL VbaFoundFiles::File( sal_Int32 nIndex ) + throw ( css::uno::RuntimeException ) +{ + if ( nIndex < 1 ) + throw css::lang::IndexOutOfBoundsException(); + sal_Int32 nCount = m_xIndexAccess->getCount(); + if ( nIndex > nCount ) + throw css::lang::IndexOutOfBoundsException(); + return m_xIndexAccess->getByIndex( nIndex - 1 ).get< rtl::OUString >(); +} + +css::uno::Type VbaFoundFiles::getElementType() throw ( css::uno::RuntimeException ) +{ + return ov::XFoundFiles::static_type(0); +} + +rtl::OUString& VbaFoundFiles::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaFoundFiles") ); + return sImplName; +} + +css::uno::Sequence< rtl::OUString > VbaFoundFiles::getServiceNames() +{ + static css::uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.FoundFiles") ); + } + return aServiceNames; +} diff --git a/main/sc/source/ui/vba/vbafoundfiles.hxx b/main/sc/source/ui/vba/vbafoundfiles.hxx new file mode 100644 index 00000000000..b3495dd4736 --- /dev/null +++ b/main/sc/source/ui/vba/vbafoundfiles.hxx @@ -0,0 +1,106 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SC_VBA_FOUNDFILES_HXX +#define SC_VBA_FOUNDFILES_HXX + +#include +#include +#include +#include + +namespace css = ::com::sun::star; + +typedef CollTestImplHelper< ooo::vba::XFoundFiles > VbaFoundFilesImpl_BASE; + +class VbaFoundFilesEnum : public cppu::WeakImplHelper2< css::container::XIndexAccess, css::container::XEnumeration > +{ +private: + css::uno::Sequence< rtl::OUString > m_sFileList; + sal_Int32 m_nIndex; + +public: + VbaFoundFilesEnum(); + VbaFoundFilesEnum( css::uno::Sequence< rtl::OUString >& sFileList ); + ~VbaFoundFilesEnum(); + + void SetFileList( css::uno::Sequence< rtl::OUString >& sFileList ); + + // XIndexAccess + virtual sal_Int32 SAL_CALL getCount() throw ( css::uno::RuntimeException ); + virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) throw ( css::lang::IndexOutOfBoundsException, css::lang::WrappedTargetException, css::uno::RuntimeException ); + + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() throw ( css::uno::RuntimeException ); + virtual sal_Bool SAL_CALL hasElements() throw ( css::uno::RuntimeException ); + + // XEnumeration + virtual sal_Bool SAL_CALL hasMoreElements() throw ( css::uno::RuntimeException ); + virtual css::uno::Any SAL_CALL nextElement() throw ( css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException ); +}; + +// MS Excel VBA: Collection of file paths returned by FileSearch.Execute. +// Status: implemented - wraps a sequence of OUString file paths +class VbaFoundFiles : public VbaFoundFilesImpl_BASE +{ +private: + +public: + // MS Excel VBA: Constructs FoundFiles with parent, context, and file list. + // Status: implemented + VbaFoundFiles( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ); + // MS Excel VBA: Factory constructor for service instantiation. + // Status: implemented + VbaFoundFiles( const css::uno::Sequence< css::uno::Any >& args, + const css::uno::Reference< css::uno::XComponentContext >& xContext ); + // MS Excel VBA: Destructor. + // Status: implemented + virtual ~VbaFoundFiles(); + + // MS Excel VBA: Creates a collection object from a source Any. + // Status: implemented + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + + // XFoundFiles + // MS Excel VBA: Returns the file path at the specified index (1-based). + // Status: implemented - validates index and throws IndexOutOfBoundsException if out of range + virtual rtl::OUString SAL_CALL File( sal_Int32 nIndex ) throw ( css::uno::RuntimeException ); + + // XEnumerationAccess + // MS Excel VBA: Returns the type of objects in this collection. + // Status: implemented - returns XFoundFiles + virtual css::uno::Type SAL_CALL getElementType() throw ( css::uno::RuntimeException ); + // MS Excel VBA: Creates an enumeration for iterating the collection. + // Status: implemented + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw ( css::uno::RuntimeException ); + + // XHelperInterface + // MS Excel VBA: Returns the implementation name for UNO service identification. + // Status: implemented - returns "VbaFoundFiles" + virtual rtl::OUString& getServiceImplName(); + // MS Excel VBA: Returns the service names this implementation supports. + // Status: implemented - returns "ooo.vba.excel.FoundFiles" + virtual css::uno::Sequence< rtl::OUString > getServiceNames(); +}; + +#endif diff --git a/main/sc/source/ui/vba/vbaname.cxx b/main/sc/source/ui/vba/vbaname.cxx index e31ba067a34..0bbe8f30f0f 100644 --- a/main/sc/source/ui/vba/vbaname.cxx +++ b/main/sc/source/ui/vba/vbaname.cxx @@ -64,11 +64,9 @@ ScVbaName::getWorkSheet() ::rtl::OUString ScVbaName::getName() { - String sName; - sName += UniString( getWorkSheet()->getName()); - sName += String::CreateFromAscii("!"); - sName += UniString ( mxNamedRange->getName() ); - return ::rtl::OUString( sName ); + // In VBA, workbook-level names return just the name without sheet prefix + // AOO stores all names at document level, so return the raw name + return mxNamedRange->getName(); } void @@ -228,8 +226,13 @@ ScVbaName::setRefersToR1C1Local( const ::rtl::OUString & rRefersTo ) css::uno::Reference< ov::excel::XRange > ScVbaName::getRefersToRange() { - uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName( - mxContext, mxNamedRange->getName(), excel::getDocShell( mxModel ), formula::FormulaGrammar::CONV_XL_R1C1 ); + // #i129350: use getValue() (returns "=Sheet1!$A$1:$A$3") instead of + // getName() (returns just the name of the named range) + ::rtl::OUString sRefersTo = getValue(); + if ( sRefersTo.getLength() > 0 && sRefersTo[0] == '=' ) + sRefersTo = sRefersTo.copy(1); + uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName( + mxContext, sRefersTo, excel::getDocShell( mxModel ), formula::FormulaGrammar::CONV_XL_A1 ); return xRange; } diff --git a/main/sc/source/ui/vba/vbanames.cxx b/main/sc/source/ui/vba/vbanames.cxx index 4a402b704a5..9c5ae5dc8e2 100644 --- a/main/sc/source/ui/vba/vbanames.cxx +++ b/main/sc/source/ui/vba/vbanames.cxx @@ -127,6 +127,30 @@ ScVbaNames::Add( const css::uno::Any& Name , RefersToR1C1 >>= xRange; if ( RefersToR1C1Local.hasValue() ) RefersToR1C1Local >>= xRange; + + // #i129350: VBA Names.Add can pass RefersTo as a string address (e.g. "=Sheet1!$A$1:$A$3") + // The >>= above only extracts XRange for interface types, not strings + if ( !xRange.is() && RefersTo.hasValue() ) + { + rtl::OUString sRefersTo; + RefersTo >>= sRefersTo; + if ( sRefersTo.getLength() > 0 ) + { + // Strip leading '=' if present (VBA RefersTo format: "=Address") + if ( sRefersTo[0] == '=' ) + sRefersTo = sRefersTo.copy(1); + try + { + xRange = ScVbaRange::getRangeObjectForName( + mxContext, sRefersTo, excel::getDocShell( mxModel ), + formula::FormulaGrammar::CONV_XL_A1 ); + } + catch( ... ) + { + xRange.clear(); + } + } + } } if ( xRange.is() ) diff --git a/main/sc/source/ui/vba/vbaquerytable.cxx b/main/sc/source/ui/vba/vbaquerytable.cxx new file mode 100644 index 00000000000..82459740173 --- /dev/null +++ b/main/sc/source/ui/vba/vbaquerytable.cxx @@ -0,0 +1,145 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include "vbaquerytable.hxx" +#include "helperdecl.hxx" +#include "document.hxx" +#include "docsh.hxx" +#include "address.hxx" +#include +#include +#include +#include "arealink.hxx" +#include "vbarange.hxx" + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +ScVbaQueryTable::ScVbaQueryTable( const css::uno::Sequence< css::uno::Any >& /*args*/, + const css::uno::Reference< css::uno::XComponentContext >& xContext ) +: ScVbaQueryTableImpl_BASE( xContext ), + m_pDocument( NULL ), + m_pParent( NULL ) +{ +} + +ScVbaQueryTable::ScVbaQueryTable( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + ScDocument* pDocument, + ScVbaRange* pParent + ) +: ScVbaQueryTableImpl_BASE( xParent, xContext ), + m_pDocument( pDocument ), + m_pParent( pParent ) +{ +} + +ScVbaQueryTable::~ScVbaQueryTable() +{ +} + +sal_Bool SAL_CALL +ScVbaQueryTable::Refresh( const css::uno::Any& aBackgroundQuery ) throw ( css::uno::RuntimeException ) +{ + if ( !m_pParent || !m_pDocument ) + return sal_False; + + // Get parent Info + sal_Int32 nRow = m_pParent->getRow(); + sal_Int32 nClm = m_pParent->getColumn(); + sal_Int16 nTab = m_pParent->getWorksheet()->getIndex() - 1; // The vba index begins from 1. + ScAddress crrRngAddr( nClm, nRow, nTab ); + + // Get link info + sfx2::LinkManager* pLinkMng = m_pDocument->GetLinkManager(); + const sfx2::SvBaseLinks& rLinks = pLinkMng->GetLinks(); + sal_uInt16 nCount = rLinks.Count(); + + bool bBackground = false; + if ( aBackgroundQuery.hasValue() ) + aBackgroundQuery >>= bBackground; + + bool bFoundLink = false; + for ( sal_uInt16 i = 0; i < nCount; ++i ) + { + sfx2::SvBaseLink* pBase = *rLinks[i]; + if ( pBase->ISA( ScAreaLink ) ) + { + ScAreaLink* pAreaLink = static_cast< ScAreaLink* >( pBase ); + const ScRange& destRange = pAreaLink->GetDestArea(); + if ( destRange.In( crrRngAddr ) ) + { + pBase->Update(); + bFoundLink = true; + } + } + } + + return bFoundLink ? sal_True : sal_False; +} + +void SAL_CALL +ScVbaQueryTable::Delete() throw ( css::uno::RuntimeException ) +{ + if ( !m_pParent || !m_pDocument ) + return; + + sal_Int32 nRow = m_pParent->getRow(); + sal_Int32 nClm = m_pParent->getColumn(); + sal_Int16 nTab = m_pParent->getWorksheet()->getIndex() - 1; + ScAddress crrRngAddr( nClm, nRow, nTab ); + + sfx2::LinkManager* pLinkMng = m_pDocument->GetLinkManager(); + const sfx2::SvBaseLinks& rLinks = pLinkMng->GetLinks(); + sal_uInt16 nCount = rLinks.Count(); + + for ( sal_uInt16 i = 0; i < nCount; ++i ) + { + sfx2::SvBaseLink* pBase = *rLinks[i]; + if ( pBase->ISA( ScAreaLink ) ) + { + ScAreaLink* pAreaLink = static_cast< ScAreaLink* >( pBase ); + const ScRange& destRange = pAreaLink->GetDestArea(); + if ( destRange.In( crrRngAddr ) ) + { + pLinkMng->Remove( pBase ); + break; + } + } + } +} + +rtl::OUString& ScVbaQueryTable::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaQueryTable") ); + return sImplName; +} + +css::uno::Sequence< rtl::OUString > ScVbaQueryTable::getServiceNames() +{ + static css::uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.QueryTable") ); + } + return aServiceNames; +} diff --git a/main/sc/source/ui/vba/vbaquerytable.hxx b/main/sc/source/ui/vba/vbaquerytable.hxx new file mode 100644 index 00000000000..51e54a4bcfc --- /dev/null +++ b/main/sc/source/ui/vba/vbaquerytable.hxx @@ -0,0 +1,80 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef SC_VBA_QUERYTABLE_HXX +#define SC_VBA_QUERYTABLE_HXX + +#include +#include + +namespace css = ::com::sun::star; + +// MS Excel VBA: Represents a worksheet table built from data returned from an external data source. +// Status: partial - only Refresh and Delete implemented; CommandText, Connection, Destination, etc. missing +typedef InheritedHelperInterfaceImpl1< ooo::vba::excel::XQueryTable > ScVbaQueryTableImpl_BASE; + +class ScDocument; +#include +class ScVbaRange; + +class ScVbaQueryTable : public ScVbaQueryTableImpl_BASE +{ +private: + ScDocument* m_pDocument; + ScVbaRange* m_pParent; +public: + // MS Excel VBA: Constructs QueryTable with parent, context, document, and range. + // Status: implemented + ScVbaQueryTable( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + ScDocument* pDocument = NULL, + ScVbaRange* pParent = NULL ); + // MS Excel VBA: Factory constructor for service instantiation. + // Status: implemented + ScVbaQueryTable( const css::uno::Sequence< css::uno::Any >& /*args*/, + const css::uno::Reference< css::uno::XComponentContext >& xContext ); + // MS Excel VBA: Destructor. + // Status: implemented + virtual ~ScVbaQueryTable(); + + // MS Excel VBA: Methods - QueryTable actions + // MS Excel VBA: Reloads the query table from the external data source. + // Status: implemented - delegates to area link update + virtual sal_Bool SAL_CALL Refresh( const css::uno::Any& aBackgroundQuery ) + throw ( css::uno::RuntimeException ); + // MS Excel VBA: Deletes the query table and removes it from the worksheet. + // Status: implemented - calls LinkManager::Remove() + virtual void SAL_CALL Delete() throw ( css::uno::RuntimeException ); + + // Missing properties (per MS Excel VBA reference): + // CommandText, CommandType, Connection, Destination, RefreshOnFileOpen, + // RefreshPeriod, RefreshStyle, SaveData, SavePassword, TextFile*, Web* + + // XHelperInterface + // MS Excel VBA: Returns the implementation name for UNO service identification. + // Status: implemented - returns "ScVbaQueryTable" + virtual rtl::OUString& getServiceImplName(); + // MS Excel VBA: Returns the service names this implementation supports. + // Status: implemented - returns "ooo.vba.excel.QueryTable" + virtual css::uno::Sequence< rtl::OUString > getServiceNames(); +}; + +#endif diff --git a/main/sc/source/ui/vba/vbarange.cxx b/main/sc/source/ui/vba/vbarange.cxx index 33726b2cb5e..1cfcca298e8 100644 --- a/main/sc/source/ui/vba/vbarange.cxx +++ b/main/sc/source/ui/vba/vbarange.cxx @@ -146,6 +146,8 @@ #include "vbaworksheet.hxx" #include "vbavalidation.hxx" #include "vbahyperlinks.hxx" +#include "vbaquerytable.hxx" +#include "vbaformatconditions.hxx" #include "tabvwsh.hxx" #include "rangelst.hxx" @@ -181,16 +183,22 @@ const double fExtraWidth = 182.0 / 256.0; // * 1 point = 1/72 inch = 20 twips // * 1 inch = 72 points = 1440 twips // * 1 cm = 567 twips +// MS Excel VBA: Internal helper - converts HMM to points. +// Status: internal helper double lcl_hmmToPoints( double nVal ) { return ( (double)((nVal /1000 ) * 567 ) / 20 ); } static const sal_Int16 supportedIndexTable[] = { excel::XlBordersIndex::xlEdgeLeft, excel::XlBordersIndex::xlEdgeTop, excel::XlBordersIndex::xlEdgeBottom, excel::XlBordersIndex::xlEdgeRight, excel::XlBordersIndex::xlDiagonalDown, excel::XlBordersIndex::xlDiagonalUp, excel::XlBordersIndex::xlInsideVertical, excel::XlBordersIndex::xlInsideHorizontal }; +// MS Excel VBA: Internal helper - converts points to twips. +// Status: internal helper sal_uInt16 lcl_pointsToTwips( double nVal ) { nVal = nVal * static_cast(20); short nTwips = static_cast(nVal); return nTwips; } +// MS Excel VBA: Internal helper - converts twips to points. +// Status: internal helper double lcl_TwipsToPoints( sal_uInt16 nVal ) { double nPoints = nVal; @@ -208,6 +216,8 @@ double lcl_Round2DecPlaces( double nVal ) return nVal; } +// MS Excel VBA: Internal helper - creates a Range object from any. +// Status: internal helper uno::Any lcl_makeRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Any aAny, bool bIsRows, bool bIsColumns ) { uno::Reference< table::XCellRange > xCellRange( aAny, uno::UNO_QUERY_THROW ); @@ -243,6 +253,8 @@ uno::Reference< excel::XRange > lcl_makeXRangeFromSheetCellRanges( const uno::Re return xRange; } +// MS Excel VBA: Internal helper - gets the ScCellRangesBase interface. +// Status: internal helper ScCellRangesBase* ScVbaRange::getCellRangesBase() { if( mxRanges.is() ) @@ -252,16 +264,22 @@ ScCellRangesBase* ScVbaRange::getCellRangesBase() throw uno::RuntimeException( rtl::OUString::createFromAscii("General Error creating range - Unknown" ), uno::Reference< uno::XInterface >() ); } +// MS Excel VBA: Internal helper - gets the ScCellRangeObj implementation. +// Status: internal helper ScCellRangeObj* ScVbaRange::getCellRangeObj() { return dynamic_cast< ScCellRangeObj* >( getCellRangesBase() ); } +// MS Excel VBA: Internal helper - gets the ScCellRangesObj implementation. +// Status: internal helper ScCellRangesObj* ScVbaRange::getCellRangesObj() { return dynamic_cast< ScCellRangesObj* >( getCellRangesBase() ); } +// MS Excel VBA: Internal helper - gets the current data set. +// Status: internal helper SfxItemSet* ScVbaRange::getCurrentDataSet( ) { SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() ); @@ -270,6 +288,8 @@ SfxItemSet* ScVbaRange::getCurrentDataSet( ) return pDataSet; } +// MS Excel VBA: Internal helper - fires a Worksheet_Change event for this range. +// Status: internal helper void ScVbaRange::fireChangeEvent() { if( ScVbaApplication::getDocumentEventsEnabled() ) @@ -290,6 +310,8 @@ void ScVbaRange::fireChangeEvent() } } +// MS Excel VBA: Internal enumeration class for single range. +// Status: internal helper class SingleRangeEnumeration : public EnumerationHelper_BASE { uno::Reference< XHelperInterface > m_xParent; @@ -300,6 +322,8 @@ class SingleRangeEnumeration : public EnumerationHelper_BASE SingleRangeEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange ) : m_xParent( xParent ), m_xRange( xRange ), mxContext( xContext ), bHasMore( true ) { } virtual ::sal_Bool SAL_CALL hasMoreElements( ) { return bHasMore; } +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual uno::Any SAL_CALL nextElement( ) { if ( !bHasMore ) @@ -313,6 +337,8 @@ class SingleRangeEnumeration : public EnumerationHelper_BASE // just one item typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > SingleRange_BASE; +// MS Excel VBA: Internal index access class for single range. +// Status: internal helper class SingleRangeIndexAccess : public SingleRange_BASE { private: @@ -324,6 +350,8 @@ class SingleRangeIndexAccess : public SingleRange_BASE SingleRangeIndexAccess( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange ):mxParent( xParent ), m_xRange( xRange ), mxContext( xContext ) {} // XIndexAccess virtual ::sal_Int32 SAL_CALL getCount() { return 1; } +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) { if ( Index != 0 ) @@ -341,6 +369,8 @@ class SingleRangeIndexAccess : public SingleRange_BASE +// MS Excel VBA: Internal enumeration class for range collections. +// Status: internal helper class RangesEnumerationImpl : public EnumerationHelperImpl { bool mbIsRows; @@ -348,6 +378,8 @@ class RangesEnumerationImpl : public EnumerationHelperImpl public: RangesEnumerationImpl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, bool bIsRows, bool bIsColumns ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), mbIsRows( bIsRows ), mbIsColumns( bIsColumns ) {} +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual uno::Any SAL_CALL nextElement( ) { return lcl_makeRange( m_xParent, m_xContext, m_xEnumeration->nextElement(), mbIsRows, mbIsColumns ); @@ -355,6 +387,8 @@ class RangesEnumerationImpl : public EnumerationHelperImpl }; +// MS Excel VBA: Internal class representing the Areas collection of a range. +// Status: internal helper class ScVbaRangeAreas : public ScVbaCollectionBaseImpl { bool mbIsRows; @@ -363,11 +397,15 @@ class ScVbaRangeAreas : public ScVbaCollectionBaseImpl ScVbaRangeAreas( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess, bool bIsRows, bool bIsColumns ) : ScVbaCollectionBaseImpl( xParent, xContext, xIndexAccess ), mbIsRows( bIsRows ), mbIsColumns( bIsColumns ) {} // XEnumerationAccess +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration(); // XElementAccess virtual uno::Type SAL_CALL getElementType(){ return excel::XRange::static_type(0); } +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual uno::Any createCollectionObject( const uno::Any& aSource ); virtual rtl::OUString& getServiceImplName() { static rtl::OUString sDummy; return sDummy; } @@ -440,6 +478,8 @@ getDocumentFromRange( const uno::Reference< table::XCellRange >& xRange ) ScDocument* +// MS Excel VBA: Gets the underlying ScDocument for this range. +// Status: implemented ScVbaRange::getScDocument() { if ( mxRanges.is() ) @@ -452,6 +492,8 @@ ScVbaRange::getScDocument() } ScDocShell* +// MS Excel VBA: Gets the underlying ScDocShell for this range. +// Status: implemented ScVbaRange::getScDocShell() { if ( mxRanges.is() ) @@ -463,12 +505,16 @@ ScVbaRange::getScDocShell() return getDocShellFromRange( mxRange ); } +// MS Excel VBA: Returns the ScVbaRange implementation object for a VBA Range object. +// Status: implemented /*static*/ ScVbaRange* ScVbaRange::getImplementation( const uno::Reference< excel::XRange >& rxRange ) { // FIXME: always save to use dynamic_cast? Or better to (implement and) use XTunnel? return dynamic_cast< ScVbaRange* >( rxRange.get() ); } +// MS Excel VBA: Gets the underlying model object. +// Status: implemented uno::Reference< frame::XModel > ScVbaRange::getUnoModel() { if( ScDocShell* pDocShell = getScDocShell() ) @@ -483,6 +529,8 @@ uno::Reference< frame::XModel > ScVbaRange::getUnoModel() throw uno::RuntimeException(); } +// MS Excel VBA: Gets the ScRangeList for this range. +// Status: implemented const ScRangeList& ScVbaRange::getScRangeList() { if( ScCellRangesBase* pScRangesBase = getCellRangesBase() ) @@ -498,6 +546,8 @@ const ScRangeList& ScVbaRange::getScRangeList() } +// MS Excel VBA: Internal helper class for number format operations. +// Status: internal helper class NumFormatHelper { uno::Reference< util::XNumberFormatsSupplier > mxSupplier; @@ -604,6 +654,8 @@ class NumFormatHelper }; +// MS Excel VBA: Internal struct representing a cell position. +// Status: internal helper struct CellPos { CellPos():m_nRow(-1), m_nCol(-1), m_nArea(0) {}; @@ -621,6 +673,8 @@ typedef ::std::vector< CellPos > vCellPos; // to handle rows and columns ( but I do this separately for now // and.. this class only handles singe areas ( does it have to handle // multi area ranges?? ) +// MS Excel VBA: Internal enumeration class for columns/rows. +// Status: internal helper class ColumnsRowEnumeration: public CellsEnumeration_BASE { uno::Reference< uno::XComponentContext > mxContext; @@ -635,6 +689,8 @@ class ColumnsRowEnumeration: public CellsEnumeration_BASE virtual ::sal_Bool SAL_CALL hasMoreElements(){ return mCurElem < mMaxElems; } +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual uno::Any SAL_CALL nextElement() { if ( !hasMoreElements() ) @@ -644,6 +700,8 @@ class ColumnsRowEnumeration: public CellsEnumeration_BASE } }; +// MS Excel VBA: Internal enumeration class for cells. +// Status: internal helper class CellsEnumeration : public CellsEnumeration_BASE { uno::WeakReference< XHelperInterface > mxParent; @@ -685,6 +743,8 @@ class CellsEnumeration : public CellsEnumeration_BASE } virtual ::sal_Bool SAL_CALL hasMoreElements(){ return m_it != m_CellPositions.end(); } +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual uno::Any SAL_CALL nextElement() { if ( !hasMoreElements() ) @@ -699,6 +759,8 @@ class CellsEnumeration : public CellsEnumeration_BASE }; +// MS Excel VBA: Internal - property name constants for range cell properties. +// Status: internal helper const static ::rtl::OUString ISVISIBLE( RTL_CONSTASCII_USTRINGPARAM( "IsVisible")); const static ::rtl::OUString WIDTH( RTL_CONSTASCII_USTRINGPARAM( "Width")); const static ::rtl::OUString HEIGHT( RTL_CONSTASCII_USTRINGPARAM( "Height")); @@ -716,6 +778,8 @@ const static rtl::OUString STR_ERRORMESSAGE_NOCELLSWEREFOUND( RTL_CONSTASCII_UST const static rtl::OUString STR_ERRORMESSAGE_APPLIESTOROWCOLUMNSONLY( RTL_CONSTASCII_USTRINGPARAM("Property only applicable for Columns and Rows") ); const static rtl::OUString CELLSTYLE( RTL_CONSTASCII_USTRINGPARAM("CellStyle") ); +// MS Excel VBA: Internal helper class for setting cell values. +// Status: internal helper class CellValueSetter : public ValueSetter { protected: @@ -723,7 +787,11 @@ class CellValueSetter : public ValueSetter uno::TypeClass mTypeClass; public: CellValueSetter( const uno::Any& aValue ); +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual bool processValue( const uno::Any& aValue, const uno::Reference< table::XCell >& xCell ); +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell ); }; @@ -803,6 +871,8 @@ CellValueSetter::processValue( const uno::Any& aValue, const uno::Reference< tab } +// MS Excel VBA: Internal helper class for getting cell values. +// Status: internal helper class CellValueGetter : public ValueGetter { protected: @@ -810,7 +880,11 @@ class CellValueGetter : public ValueGetter uno::TypeClass mTypeClass; public: CellValueGetter() {} +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell ); +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual void processValue( sal_Int32 x, sal_Int32 y, const uno::Any& aValue ); const uno::Any& getValue() const { return maValue; } @@ -821,6 +895,8 @@ CellValueGetter::processValue( sal_Int32 /*x*/, sal_Int32 /*y*/, const uno::Any { maValue = aValue; } +// MS Excel VBA: Internal - visits a cell node to get its value. +// Status: internal helper void CellValueGetter::visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell ) { uno::Any aValue; @@ -872,6 +948,78 @@ void CellValueGetter::visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< processValue( x,y,aValue ); } +// MS Excel VBA: Internal helper class for getting cell values without date coercion (Value2). +// Status: internal helper +class CellValueGetter2 : public ValueGetter +{ +protected: + uno::Any maValue; +public: + CellValueGetter2() {} + virtual void visitNode( sal_Int32 x, sal_Int32 y, const css::uno::Reference< table::XCell >& xCell ); + virtual void processValue( sal_Int32 x, sal_Int32 y, const css::uno::Any& aValue ); + const uno::Any& getValue() const { return maValue; } + +}; + +void +CellValueGetter2::processValue( sal_Int32 /*x*/, sal_Int32 /*y*/, const css::uno::Any& aValue ) +{ + maValue = aValue; +} + +void CellValueGetter2::visitNode( sal_Int32 x, sal_Int32 y, const css::uno::Reference< table::XCell >& xCell ) +{ + uno::Any aValue; + table::CellContentType eType = xCell->getType(); + if( eType == table::CellContentType_VALUE || eType == table::CellContentType_FORMULA ) + { + if ( eType == table::CellContentType_FORMULA ) + { + + rtl::OUString sFormula = xCell->getFormula(); + if ( sFormula.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("=TRUE()") ) ) ) + aValue <<= sal_True; + else if ( sFormula.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("=FALSE()") ) ) ) + aValue <<= sal_False; + else + { + uno::Reference< beans::XPropertySet > xProp( xCell, uno::UNO_QUERY_THROW ); + + table::CellContentType eFormulaType = table::CellContentType_VALUE; + xProp->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FormulaResultType" ) ) ) >>= eFormulaType; + + if ( eFormulaType == table::CellContentType_TEXT ) + { + uno::Reference< text::XTextRange > xTextRange(xCell, ::uno::UNO_QUERY_THROW); + aValue <<= xTextRange->getString(); + } + else + { + aValue <<= xCell->getValue(); + } + } + } + else + { + uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW ); + NumFormatHelper cellFormat( xRange ); + if ( cellFormat.isBooleanType() ) + aValue = uno::makeAny( ( xCell->getValue() != 0.0 ) ); + else + { + aValue <<= xCell->getValue(); + } + } + } + if( eType == table::CellContentType_TEXT ) + { + uno::Reference< text::XTextRange > xTextRange(xCell, ::uno::UNO_QUERY_THROW); + aValue <<= xTextRange->getString(); + } + processValue( x,y,aValue ); +} +// Status: internal helper class CellFormulaValueSetter : public CellValueSetter { private: @@ -921,6 +1069,8 @@ class CellFormulaValueSetter : public CellValueSetter }; +// MS Excel VBA: Internal helper - gets formula values from cells. +// Status: internal helper class CellFormulaValueGetter : public CellValueGetter { private: @@ -928,6 +1078,8 @@ class CellFormulaValueGetter : public CellValueGetter formula::FormulaGrammar::Grammar m_eGrammar; public: CellFormulaValueGetter(ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ) : CellValueGetter( ), m_pDoc( pDoc ), m_eGrammar( eGram ) {} +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell ) { uno::Any aValue; @@ -957,11 +1109,15 @@ class CellFormulaValueGetter : public CellValueGetter }; +// MS Excel VBA: Internal helper class for 2D array value retrieval. +// Status: internal helper class Dim2ArrayValueGetter : public ArrayVisitor { protected: uno::Any maValue; ValueGetter& mValueGetter; +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual void processValue( sal_Int32 x, sal_Int32 y, const uno::Any& aValue ) { uno::Sequence< uno::Sequence< uno::Any > >& aMatrix = *( uno::Sequence< uno::Sequence< uno::Any > >* )( maValue.getValue() ); @@ -989,6 +1145,8 @@ class Dim2ArrayValueGetter : public ArrayVisitor const static rtl::OUString sNA = rtl::OUString::createFromAscii("#N/A"); +// MS Excel VBA: Internal helper class for 1D array value setting. +// Status: internal helper class Dim1ArrayValueSetter : public ArrayVisitor { uno::Sequence< uno::Any > aMatrix; @@ -1000,6 +1158,8 @@ class Dim1ArrayValueSetter : public ArrayVisitor aValue >>= aMatrix; nColCount = aMatrix.getLength(); } +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual void visitNode( sal_Int32 /*x*/, sal_Int32 y, const uno::Reference< table::XCell >& xCell ) { if ( y < nColCount ) @@ -1011,6 +1171,8 @@ class Dim1ArrayValueSetter : public ArrayVisitor +// MS Excel VBA: Internal helper - 2D array value setting. +// Status: internal helper class Dim2ArrayValueSetter : public ArrayVisitor { uno::Sequence< uno::Sequence< uno::Any > > aMatrix; @@ -1025,6 +1187,8 @@ class Dim2ArrayValueSetter : public ArrayVisitor nColCount = aMatrix[0].getLength(); } +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell ) { if ( x < nRowCount && y < nColCount ) @@ -1035,45 +1199,63 @@ class Dim2ArrayValueSetter : public ArrayVisitor } }; +// MS Excel VBA: Internal helper class for range processing. +// Status: internal helper class RangeProcessor { public: +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual void process( const uno::Reference< excel::XRange >& xRange ) = 0; }; +// MS Excel VBA: Internal helper class for range value processing. +// Status: internal helper class RangeValueProcessor : public RangeProcessor { const uno::Any& m_aVal; public: RangeValueProcessor( const uno::Any& rVal ):m_aVal( rVal ) {} +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual void process( const uno::Reference< excel::XRange >& xRange ) { xRange->setValue( m_aVal ); } }; +// MS Excel VBA: Internal helper class for range formula processing. +// Status: internal helper class RangeFormulaProcessor : public RangeProcessor { const uno::Any& m_aVal; public: RangeFormulaProcessor( const uno::Any& rVal ):m_aVal( rVal ) {} +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual void process( const uno::Reference< excel::XRange >& xRange ) { xRange->setFormula( m_aVal ); } }; +// MS Excel VBA: Internal - processes range cell counts. +// Status: internal helper class RangeCountProcessor : public RangeProcessor { sal_Int32 nCount; public: RangeCountProcessor():nCount(0){} +// MS Excel VBA: Internal helper - number format interface method. +// Status: internal helper virtual void process( const uno::Reference< excel::XRange >& xRange ) { nCount = nCount + xRange->getCount(); } sal_Int32 value() { return nCount; } }; +// MS Excel VBA: Internal - visits range areas for processing. +// Status: internal helper class AreasVisitor { private: @@ -1095,6 +1277,8 @@ class AreasVisitor } }; +// MS Excel VBA: Internal helper class for range operations. +// Status: internal helper class RangeHelper { uno::Reference< table::XCellRange > m_xCellRange; @@ -1353,6 +1537,8 @@ util::TriState lclGetMergedState( const uno::Reference< table::XCellRange >& rxC // ---------------------------------------------------------------------------- css::uno::Reference< excel::XRange > +// MS Excel VBA: Creates a Range object from a range name string. +// Status: implemented ScVbaRange::getRangeObjectForName( const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sRangeName, ScDocShell* pDocSh, formula::FormulaGrammar::AddressConvention eConv ) @@ -1422,6 +1608,8 @@ void lcl_NotifyRangeChanges( const uno::Reference< frame::XModel >& xModel, ScCe } } +// MS Excel VBA: Constructor taking arguments sequence (for UNO create). +// Status: implemented ScVbaRange::ScVbaRange( uno::Sequence< uno::Any> const & args, uno::Reference< uno::XComponentContext> const & xContext ) : ScVbaRange_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext, getXSomethingFromArgs< beans::XPropertySet >( args, 1, false ), getModelFromXIf( getXSomethingFromArgs< uno::XInterface >( args, 1 ) ), true ), mbIsRows( sal_False ), mbIsColumns( sal_False ) { @@ -1439,6 +1627,8 @@ ScVbaRange::ScVbaRange( uno::Sequence< uno::Any> const & args, m_Areas = new ScVbaRangeAreas( mxParent, mxContext, xIndex, mbIsRows, mbIsColumns ); } +// MS Excel VBA: Constructor from a cell range. +// Status: implemented ScVbaRange::ScVbaRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange, sal_Bool bIsRows, sal_Bool bIsColumns ) : ScVbaRange_BASE( xParent, xContext, uno::Reference< beans::XPropertySet >( xRange, uno::UNO_QUERY_THROW ), getModelFromRange( xRange), true ), mxRange( xRange ), mbIsRows( bIsRows ), @@ -1454,6 +1644,8 @@ ScVbaRange::ScVbaRange( const uno::Reference< XHelperInterface >& xParent, const } +// MS Excel VBA: Constructor from a cell range container. +// Status: implemented ScVbaRange::ScVbaRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges, sal_Bool bIsRows, sal_Bool bIsColumns ) : ScVbaRange_BASE( xParent, xContext, uno::Reference< beans::XPropertySet >( xRanges, uno::UNO_QUERY_THROW ), getModelFromXIf( uno::Reference< uno::XInterface >( xRanges, uno::UNO_QUERY_THROW ) ), true ), mxRanges( xRanges ),mbIsRows( bIsRows ), mbIsColumns( bIsColumns ) @@ -1463,21 +1655,29 @@ ScVbaRange::ScVbaRange( const uno::Reference< XHelperInterface >& xParent, const } +// MS Excel VBA: Destructor. +// Status: implemented ScVbaRange::~ScVbaRange() { } +// MS Excel VBA: Internal helper - gets or creates the Borders collection. +// Status: internal helper uno::Reference< XCollection >& ScVbaRange::getBorders() { if ( !m_Borders.is() ) { uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW ); +// MS Excel VBA: Internal helper - sets up borders for a range. +// Status: internal helper m_Borders = lcl_setupBorders( this, mxContext, uno::Reference< table::XCellRange >( xRange->getCellRange(), uno::UNO_QUERY_THROW ) ); } return m_Borders; } void +// MS Excel VBA: Internal helper - visits all cells in an array for processing. +// Status: internal helper ScVbaRange::visitArray( ArrayVisitor& visitor ) { table::CellRangeAddress aRangeAddr = lclGetRangeAddress( mxRange ); @@ -1497,6 +1697,8 @@ ScVbaRange::visitArray( ArrayVisitor& visitor ) uno::Any +// MS Excel VBA: Internal helper - gets values using a ValueGetter. +// Status: internal helper ScVbaRange::getValue( ValueGetter& valueGetter) { uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW ); @@ -1514,6 +1716,8 @@ ScVbaRange::getValue( ValueGetter& valueGetter) return uno::makeAny( script::ArrayWrapper( sal_False, arrayGetter.getValue() ) ); } +// MS Excel VBA: Gets the value of the range as a Variant. +// Status: implemented uno::Any SAL_CALL ScVbaRange::getValue() { @@ -1532,8 +1736,27 @@ ScVbaRange::getValue() } +// MS Excel VBA: Gets the value of the range without date coercion (Value2 property). +// Value2 differs from Value in that date values are returned as raw doubles +// rather than as oleautomation::Date objects, and error values are not wrapped. +// Status: implemented +uno::Any SAL_CALL +ScVbaRange::getValue2() +{ + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW ); + return xRange->getValue(); + } + + CellValueGetter2 valueGetter; + return getValue( valueGetter ); +} + void +// MS Excel VBA: Internal helper - sets values using a ValueSetter. +// Status: internal helper ScVbaRange::setValue( const uno::Any& aValue, ValueSetter& valueSetter, bool bFireEvent ) { uno::TypeClass aClass = aValue.getValueTypeClass(); @@ -1572,6 +1795,8 @@ ScVbaRange::setValue( const uno::Any& aValue, ValueSetter& valueSetter, bool bFi if( bFireEvent ) fireChangeEvent(); } +// MS Excel VBA: Sets the value of the range. +// Status: implemented void SAL_CALL ScVbaRange::setValue( const uno::Any &aValue ) { @@ -1589,6 +1814,25 @@ ScVbaRange::setValue( const uno::Any &aValue ) lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() ); } +// MS Excel VBA: Sets the value of the range without date coercion (Value2 property). +// Status: implemented +void SAL_CALL +ScVbaRange::setValue2( const uno::Any& aValue ) +{ + if ( m_Areas->getCount() > 1 ) + { + AreasVisitor aVisitor( m_Areas ); + RangeValueProcessor valueProcessor( aValue ); + aVisitor.visit( valueProcessor ); + return; + } + CellValueSetter valueSetter( aValue ); + setValue( aValue, valueSetter, true ); + lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() ); +} + +// MS Excel VBA: Clears the entire range. +// Status: implemented void SAL_CALL ScVbaRange::Clear() { @@ -1601,6 +1845,8 @@ ScVbaRange::Clear() //helper ClearContent void +// MS Excel VBA: Internal helper - clears contents with specified flags. +// Status: internal helper ScVbaRange::ClearContents( sal_Int32 nFlags, bool bFireEvent ) { // #TODO code within the test below "if ( m_Areas.... " can be removed @@ -1628,12 +1874,16 @@ ScVbaRange::ClearContents( sal_Int32 nFlags, bool bFireEvent ) if( bFireEvent ) fireChangeEvent(); } +// MS Excel VBA: Clears all comments in the range. +// Status: implemented void SAL_CALL ScVbaRange::ClearComments() { ClearContents( sheet::CellFlags::ANNOTATION, false ); } +// MS Excel VBA: Clears the contents of the range. +// Status: implemented void SAL_CALL ScVbaRange::ClearContents() { @@ -1642,6 +1892,8 @@ ScVbaRange::ClearContents() ClearContents( nFlags, true ); } +// MS Excel VBA: Clears the formatting of the range. +// Status: implemented void SAL_CALL ScVbaRange::ClearFormats() { @@ -1654,6 +1906,8 @@ ScVbaRange::ClearFormats() } void +// MS Excel VBA: Internal helper - sets formula values in cells. +// Status: internal helper ScVbaRange::setFormulaValue( const uno::Any& rFormula, formula::FormulaGrammar::Grammar eGram, bool bFireEvent ) { // If this is a multiple selection apply setFormula over all areas @@ -1671,6 +1925,8 @@ ScVbaRange::setFormulaValue( const uno::Any& rFormula, formula::FormulaGrammar:: } uno::Any +// MS Excel VBA: Internal helper - gets formula values from cells. +// Status: internal helper ScVbaRange::getFormulaValue( formula::FormulaGrammar::Grammar eGram ) { // #TODO code within the test below "if ( m_Areas.... " can be removed @@ -1688,6 +1944,8 @@ ScVbaRange::getFormulaValue( formula::FormulaGrammar::Grammar eGram ) } void +// MS Excel VBA: Sets the formula of the range. +// Status: implemented ScVbaRange::setFormula(const uno::Any &rFormula ) { // #FIXME converting "=$a$1" e.g. CONV_XL_A1 -> CONV_OOO // results in "=$a$1:a1", temporalily disable conversion @@ -1695,24 +1953,48 @@ ScVbaRange::setFormula(const uno::Any &rFormula ) } uno::Any +// MS Excel VBA: Gets the formula in R1C1 notation. +// Status: implemented ScVbaRange::getFormulaR1C1() { return getFormulaValue( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 ); } void +// MS Excel VBA: Sets the formula in R1C1 notation. +// Status: implemented ScVbaRange::setFormulaR1C1(const uno::Any& rFormula ) { setFormulaValue( rFormula,formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true ); } uno::Any +// MS Excel VBA: Gets the formula of the range. +// Status: implemented ScVbaRange::getFormula() { return getFormulaValue( formula::FormulaGrammar::GRAM_NATIVE_XL_A1 ); } +uno::Any +// MS Excel VBA: Gets the formula using Formula2 syntax (array-enabled). +// Status: implemented - delegates to getFormulaValue with GRAM_NATIVE_XL_A1 +ScVbaRange::getFormula2() +{ + return getFormulaValue( formula::FormulaGrammar::GRAM_NATIVE_XL_A1 ); +} + +void +// MS Excel VBA: Sets the formula using Formula2 syntax (array-enabled). +// Status: implemented - delegates to setFormulaValue with GRAM_NATIVE_XL_A1 +ScVbaRange::setFormula2( const css::uno::Any& rFormula ) +{ + setFormulaValue( rFormula, formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true ); +} + sal_Int32 +// MS Excel VBA: Gets the number of cells in the range. +// Status: implemented ScVbaRange::getCount() { // If this is a multiple selection apply setValue over all areas @@ -1737,6 +2019,8 @@ ScVbaRange::getCount() } sal_Int32 +// MS Excel VBA: Gets the row number of the first cell. +// Status: implemented ScVbaRange::getRow() { // #TODO code within the test below "if ( m_Areas.... " can be removed @@ -1753,6 +2037,8 @@ ScVbaRange::getRow() } sal_Int32 +// MS Excel VBA: Gets the column number of the first cell. +// Status: implemented ScVbaRange::getColumn() { // #TODO code within the test below "if ( m_Areas.... " can be removed @@ -1769,6 +2055,8 @@ ScVbaRange::getColumn() } uno::Any +// MS Excel VBA: Checks if the range contains any formulas. +// Status: implemented ScVbaRange::HasFormula() { if ( m_Areas->getCount() > 1 ) @@ -1809,6 +2097,8 @@ ScVbaRange::HasFormula() return uno::makeAny( sal_True ); } void +// MS Excel VBA: Internal helper - fills cells with a series of values. +// Status: internal helper ScVbaRange::fillSeries( sheet::FillDirection nFillDirection, sheet::FillMode nFillMode, sheet::FillDateMode nFillDateMode, double fStep, double fEndValue ) { if ( m_Areas->getCount() > 1 ) @@ -1833,6 +2123,8 @@ ScVbaRange::fillSeries( sheet::FillDirection nFillDirection, sheet::FillMode nFi } void +// MS Excel VBA: Fills left from the source range. +// Status: implemented ScVbaRange::FillLeft() { fillSeries(sheet::FillDirection_TO_LEFT, @@ -1840,6 +2132,8 @@ ScVbaRange::FillLeft() } void +// MS Excel VBA: Fills right from the source range. +// Status: implemented ScVbaRange::FillRight() { fillSeries(sheet::FillDirection_TO_RIGHT, @@ -1847,6 +2141,8 @@ ScVbaRange::FillRight() } void +// MS Excel VBA: Fills up from the source range. +// Status: implemented ScVbaRange::FillUp() { fillSeries(sheet::FillDirection_TO_TOP, @@ -1854,6 +2150,8 @@ ScVbaRange::FillUp() } void +// MS Excel VBA: Fills down from the source range. +// Status: implemented ScVbaRange::FillDown() { fillSeries(sheet::FillDirection_TO_BOTTOM, @@ -1861,6 +2159,8 @@ ScVbaRange::FillDown() } ::rtl::OUString +// MS Excel VBA: Gets the text content of the range. +// Status: implemented ScVbaRange::getText() { // #TODO code within the test below "if ( m_Areas.... " can be removed @@ -1877,6 +2177,8 @@ ScVbaRange::getText() } uno::Reference< excel::XRange > +// MS Excel VBA: Returns a range offset from the current range by row and column. +// Status: implemented ScVbaRange::Offset( const ::uno::Any &nRowOff, const uno::Any &nColOff ) { SCROW nRowOffset = 0; @@ -1913,6 +2215,8 @@ ScVbaRange::Offset( const ::uno::Any &nRowOff, const uno::Any &nColOff ) } uno::Reference< excel::XRange > +// MS Excel VBA: Returns the current region (data area) around the range. +// Status: implemented ScVbaRange::CurrentRegion() { // #TODO code within the test below "if ( m_Areas.... " can be removed @@ -1934,6 +2238,8 @@ ScVbaRange::CurrentRegion() } uno::Reference< excel::XRange > +// MS Excel VBA: Returns the current array for the range. +// Status: implemented ScVbaRange::CurrentArray() { // #TODO code within the test below "if ( m_Areas.... " can be removed @@ -1954,6 +2260,8 @@ ScVbaRange::CurrentArray() } uno::Any +// MS Excel VBA: Gets the formula as an array. +// Status: implemented ScVbaRange::getFormulaArray() { // #TODO code within the test below "if ( m_Areas.... " can be removed @@ -1974,6 +2282,8 @@ ScVbaRange::getFormulaArray() } void +// MS Excel VBA: Sets the formula as an array. +// Status: implemented ScVbaRange::setFormulaArray(const uno::Any& rFormula) { // #TODO code within the test below "if ( m_Areas.... " can be removed @@ -1992,6 +2302,8 @@ ScVbaRange::setFormulaArray(const uno::Any& rFormula) } ::rtl::OUString +// MS Excel VBA: Returns a Characters object for the range. +// Status: implemented ScVbaRange::Characters(const uno::Any& Start, const uno::Any& Length) { // #TODO code within the test below "if ( m_Areas.... " can be removed @@ -2018,6 +2330,8 @@ ScVbaRange::Characters(const uno::Any& Start, const uno::Any& Length) } ::rtl::OUString +// MS Excel VBA: Returns the address of the range. +// Status: implemented ScVbaRange::Address( const uno::Any& RowAbsolute, const uno::Any& ColumnAbsolute, const uno::Any& ReferenceStyle, const uno::Any& External, const uno::Any& RelativeTo ) { if ( m_Areas->getCount() > 1 ) @@ -2095,6 +2409,8 @@ ScVbaRange::Address( const uno::Any& RowAbsolute, const uno::Any& ColumnAbsolut } uno::Reference < excel::XFont > +// MS Excel VBA: Returns the Font object for the range. +// Status: implemented ScVbaRange::Font() { uno::Reference< beans::XPropertySet > xProps(mxRange, ::uno::UNO_QUERY ); @@ -2119,6 +2435,8 @@ ScVbaRange::Font() } uno::Reference< excel::XRange > +// MS Excel VBA: Returns a cell or cells from the range. +// Status: implemented ScVbaRange::Cells( const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) { // #TODO code within the test below "if ( m_Areas.... " can be removed @@ -2133,11 +2451,50 @@ ScVbaRange::Cells( const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) // Performance: Use a common helper method for ScVbaRange::Cells and ScVbaWorksheet::Cells, // instead of creating a new ScVbaRange object in often-called ScVbaWorksheet::Cells - return CellsHelper( mxParent, mxContext, mxRange, nRowIndex, nColumnIndex ); + return CellsHelper( mxParent, mxContext, mxRange, nRowIndex, nColumnIndex ); +} + +uno::Reference< ooo::vba::excel::XQueryTable > +// MS Excel VBA: Returns the QueryTable for the range. +// Status: stubbed - not fully implemented in Calc +ScVbaRange::getQueryTable() +{ + // Return an instance of the QueryTable associated with this range + // The ScVbaQueryTable constructor takes parent, context, document, and range pointer + ScDocument* pDocument = getScDocument(); + uno::Reference< ooo::vba::excel::XQueryTable > xQueryTable( + new ScVbaQueryTable( mxParent, mxContext, pDocument, this ) ); + return xQueryTable; +} + +uno::Reference< ooo::vba::excel::XFormatConditions > +// MS Excel VBA: Returns the FormatConditions collection. +// Status: stubbed - not fully implemented in Calc +ScVbaRange::getFormatConditions() +{ + uno::Reference< beans::XPropertySet > xProps( mxRange, uno::UNO_QUERY_THROW ); + uno::Reference< css::sheet::XSheetConditionalEntries > xEntries; + try + { + xEntries.set( + xProps->getPropertyValue( + rtl::OUString::createFromAscii( "ConditionalFormat" ) ), + uno::UNO_QUERY ); + } + catch ( uno::Exception& ) + { + // Property may not be set on this range; proceed with empty entries + } + uno::Reference< frame::XModel > xModel( getUnoModel() ); + uno::Reference< ooo::vba::excel::XFormatConditions > xFormatConditions( + new ScVbaFormatConditions( mxParent, mxContext, xEntries, xModel ) ); + return xFormatConditions; } // static uno::Reference< excel::XRange > +// MS Excel VBA: Creates a Range object from row and column indices. +// Status: implemented ScVbaRange::CellsHelper( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< css::table::XCellRange >& xRange, @@ -2202,6 +2559,8 @@ ScVbaRange::CellsHelper( const uno::Reference< ov::XHelperInterface >& xParent, } void +// MS Excel VBA: Selects the range. +// Status: implemented ScVbaRange::Select() { ScCellRangesBase* pUnoRangesBase = getCellRangesBase(); @@ -2252,6 +2611,8 @@ void setCursor( const SCCOL& nCol, const SCROW& nRow, const uno::Reference< fra } void +// MS Excel VBA: Activates the range. +// Status: implemented ScVbaRange::Activate() { // get first cell of current range @@ -2312,6 +2673,8 @@ ScVbaRange::Activate() } uno::Reference< excel::XRange > +// MS Excel VBA: Returns a row or rows from the range. +// Status: implemented ScVbaRange::Rows(const uno::Any& aIndex ) { SCROW nStartRow = 0; @@ -2358,6 +2721,8 @@ ScVbaRange::Rows(const uno::Any& aIndex ) return new ScVbaRange( mxParent, mxContext, mxRange, true ); } +// MS Excel VBA: Returns a column or columns from the range. +// Status: implemented uno::Reference< excel::XRange > ScVbaRange::Columns(const uno::Any& aIndex ) { @@ -2402,6 +2767,8 @@ ScVbaRange::Columns(const uno::Any& aIndex ) } void +// MS Excel VBA: Sets whether cells are merged in the range. +// Status: implemented ScVbaRange::setMergeCells( const uno::Any& aIsMerged ) { bool bMerge = extractBoolFromAny( aIsMerged ); @@ -2436,6 +2803,8 @@ ScVbaRange::setMergeCells( const uno::Any& aIsMerged ) } uno::Any +// MS Excel VBA: Gets whether cells are merged in the range. +// Status: implemented ScVbaRange::getMergeCells() { if( mxRanges.is() ) @@ -2465,6 +2834,8 @@ ScVbaRange::getMergeCells() } void +// MS Excel VBA: Copies the range to the clipboard or destination. +// Status: implemented ScVbaRange::Copy(const ::uno::Any& Destination) { if ( m_Areas->getCount() > 1 ) @@ -2493,6 +2864,8 @@ ScVbaRange::Copy(const ::uno::Any& Destination) } void +// MS Excel VBA: Cuts the range to the clipboard or destination. +// Status: implemented ScVbaRange::Cut(const ::uno::Any& Destination) { if ( m_Areas->getCount() > 1 ) @@ -2518,6 +2891,8 @@ ScVbaRange::Cut(const ::uno::Any& Destination) } void +// MS Excel VBA: Sets the number format for the range. +// Status: implemented ScVbaRange::setNumberFormat( const uno::Any& aFormat ) { rtl::OUString sFormat; @@ -2537,6 +2912,8 @@ ScVbaRange::setNumberFormat( const uno::Any& aFormat ) } uno::Any +// MS Excel VBA: Gets the number format for the range. +// Status: implemented ScVbaRange::getNumberFormat() { @@ -2566,6 +2943,8 @@ ScVbaRange::getNumberFormat() } uno::Reference< excel::XRange > +// MS Excel VBA: Resizes the range to specified rows and columns. +// Status: implemented ScVbaRange::Resize( const uno::Any &RowSize, const uno::Any &ColumnSize ) { long nRowSize = 0, nColumnSize = 0; @@ -2590,6 +2969,8 @@ ScVbaRange::Resize( const uno::Any &RowSize, const uno::Any &ColumnSize ) } void +// MS Excel VBA: Sets whether text is wrapped in the range. +// Status: implemented ScVbaRange::setWrapText( const uno::Any& aIsWrapped ) { if ( m_Areas->getCount() > 1 ) @@ -2610,6 +2991,8 @@ ScVbaRange::setWrapText( const uno::Any& aIsWrapped ) } uno::Any +// MS Excel VBA: Gets whether text is wrapped in the range. +// Status: implemented ScVbaRange::getWrapText() { if ( m_Areas->getCount() > 1 ) @@ -2638,16 +3021,22 @@ ScVbaRange::getWrapText() return aValue; } +// MS Excel VBA: Returns the Interior (fill/background) object for the range. +// Status: implemented uno::Reference< excel::XInterior > ScVbaRange::Interior( ) { uno::Reference< beans::XPropertySet > xProps( mxRange, uno::UNO_QUERY_THROW ); return new ScVbaInterior ( this, mxContext, xProps, getScDocument() ); } uno::Reference< excel::XRange > +// MS Excel VBA: Returns a subrange within the range. +// Status: implemented ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2 ) { return Range( Cell1, Cell2, false ); } +// MS Excel VBA: Returns a subrange within the range with forced input range. +// Status: implemented uno::Reference< excel::XRange > ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2, bool bForceUseInpuRangeTab ) @@ -2752,6 +3141,8 @@ ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2, bool bForceUseI // Allow access to underlying openoffice uno api ( useful for debugging // with openoffice basic ) +// MS Excel VBA: Gets the cell range object. +// Status: implemented uno::Any SAL_CALL ScVbaRange::getCellRange( ) { uno::Any aAny; @@ -2822,6 +3213,8 @@ getPasteFormulaBits( sal_Int32 Operation) return nFormulaBits; } +// MS Excel VBA: Pastes from clipboard with specified paste options. +// Status: implemented void SAL_CALL ScVbaRange::PasteSpecial( const uno::Any& Paste, const uno::Any& Operation, const uno::Any& SkipBlanks, const uno::Any& Transpose ) { @@ -2850,7 +3243,11 @@ ScVbaRange::PasteSpecial( const uno::Any& Paste, const uno::Any& Operation, cons if ( Transpose.hasValue() ) Transpose >>= bTranspose; +// MS Excel VBA: Internal helper - converts paste type to flags. +// Status: internal helper sal_uInt16 nFlags = getPasteFlags(nPaste); +// MS Excel VBA: Internal helper - converts operation to formula bits. +// Status: internal helper sal_uInt16 nFormulaBits = getPasteFormulaBits(nOperation); excel::implnPasteSpecial(pShell->GetModel(), nFlags,nFormulaBits,bSkipBlanks,bTranspose); // restore selection @@ -2858,6 +3255,8 @@ ScVbaRange::PasteSpecial( const uno::Any& Paste, const uno::Any& Operation, cons } uno::Reference< excel::XRange > +// MS Excel VBA: Internal helper - gets the entire column or row of the range. +// Status: internal helper ScVbaRange::getEntireColumnOrRow( bool bColumn ) { ScCellRangesBase* pUnoRangesBase = getCellRangesBase(); @@ -2887,18 +3286,24 @@ ScVbaRange::getEntireColumnOrRow( bool bColumn ) return new ScVbaRange( mxParent, mxContext, xRange, !bColumn, bColumn ); } +// MS Excel VBA: Returns the entire row(s) of the range. +// Status: implemented uno::Reference< excel::XRange > SAL_CALL ScVbaRange::getEntireRow() { return getEntireColumnOrRow(false); } +// MS Excel VBA: Returns the entire column(s) of the range. +// Status: implemented uno::Reference< excel::XRange > SAL_CALL ScVbaRange::getEntireColumn() { return getEntireColumnOrRow(); } +// MS Excel VBA: Adds a comment to the range. +// Status: implemented uno::Reference< excel::XComment > SAL_CALL ScVbaRange::AddComment( const uno::Any& Text ) { @@ -2923,6 +3328,8 @@ ScVbaRange::AddComment( const uno::Any& Text ) return new ScVbaComment( this, mxContext, getUnoModel(), mxRange ); } +// MS Excel VBA: Gets or sets the comment for the range. +// Status: implemented uno::Reference< excel::XComment > SAL_CALL ScVbaRange::getComment() { @@ -2947,6 +3354,8 @@ getRowOrColumnProps( const uno::Reference< table::XCellRange >& xCellRange, bool return xProps; } +// MS Excel VBA: Gets whether the range is hidden. +// Status: implemented uno::Any SAL_CALL ScVbaRange::getHidden() { @@ -2971,6 +3380,8 @@ ScVbaRange::getHidden() return uno::makeAny( !bIsVisible ); } +// MS Excel VBA: Sets whether the range is hidden. +// Status: implemented void SAL_CALL ScVbaRange::setHidden( const uno::Any& _hidden ) { @@ -2988,6 +3399,8 @@ ScVbaRange::setHidden( const uno::Any& _hidden ) bool bHidden = extractBoolFromAny( _hidden ); try { +// MS Excel VBA: Internal helper - gets properties for rows or columns. +// Status: internal helper uno::Reference< beans::XPropertySet > xProps = getRowOrColumnProps( mxRange, mbIsRows ); xProps->setPropertyValue( ISVISIBLE, uno::Any( !bHidden ) ); } @@ -2997,6 +3410,8 @@ ScVbaRange::setHidden( const uno::Any& _hidden ) } } +// MS Excel VBA: Replaces values matching What with Replacement. +// Status: implemented ::sal_Bool SAL_CALL ScVbaRange::Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replacement, const uno::Any& LookAt, const uno::Any& SearchOrder, const uno::Any& MatchCase, const uno::Any& MatchByte, const uno::Any& SearchFormat, const uno::Any& ReplaceFormat ) { @@ -3084,12 +3499,16 @@ ScVbaRange::Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replace // Fire the range change event. ScCellRangesBase* pScCellRangesBase = ScCellRangesBase::getImplementation( xIndexAccess ); // i108874 - the original convert method will fail in SUSE +// MS Excel VBA: Internal helper - notifies of range changes. +// Status: internal helper lcl_NotifyRangeChanges( getScDocShell()->GetModel(), pScCellRangesBase ); } } return sal_True; // always } +// MS Excel VBA: Finds a value matching the search criteria. +// Status: implemented uno::Reference< excel::XRange > SAL_CALL ScVbaRange::Find( const uno::Any& What, const uno::Any& After, const uno::Any& LookIn, const uno::Any& LookAt, const uno::Any& SearchOrder, const uno::Any& SearchDirection, const uno::Any& MatchCase, const uno::Any& /*MatchByte*/, const uno::Any& /*SearchFormat*/ ) { @@ -3327,6 +3746,8 @@ void updateTableSortField( const uno::Reference< table::XCellRange >& xParentRan } +// MS Excel VBA: Sorts the range by specified keys. +// Status: implemented void SAL_CALL ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any& Key2, const uno::Any& /*Type*/, const uno::Any& Order2, const uno::Any& Key3, const uno::Any& Order3, const uno::Any& Header, const uno::Any& OrderCustom, const uno::Any& MatchCase, const uno::Any& Orientation, const uno::Any& SortMethod, const uno::Any& DataOption1, const uno::Any& DataOption2, const uno::Any& DataOption3 ) { @@ -3520,6 +3941,8 @@ ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any& } +// MS Excel VBA: Returns the last cell in the specified direction. +// Status: implemented uno::Reference< excel::XRange > SAL_CALL ScVbaRange::End( ::sal_Int32 Direction ) { @@ -3546,6 +3969,8 @@ ScVbaRange::End( ::sal_Int32 Direction ) // position current cell upper left of this range Cells( uno::makeAny( (sal_Int32) 1 ), uno::makeAny( (sal_Int32) 1 ) )->Select(); +// MS Excel VBA: Internal helper - gets XModel from a cell range. +// Status: internal helper uno::Reference< frame::XModel > xModel = getModelFromRange( mxRange ); SfxViewFrame* pViewFrame = excel::getViewFrame( xModel ); @@ -3602,6 +4027,8 @@ ScVbaRange::End( ::sal_Int32 Direction ) } bool +// MS Excel VBA: Checks if this range is a single cell. +// Status: implemented ScVbaRange::isSingleCellRange() { uno::Reference< sheet::XCellRangeAddressable > xAddressable( mxRange, uno::UNO_QUERY ); @@ -3613,6 +4040,8 @@ ScVbaRange::isSingleCellRange() return false; } +// MS Excel VBA: Returns a Characters object for a substring. +// Status: implemented uno::Reference< excel::XCharacters > SAL_CALL ScVbaRange::characters( const uno::Any& Start, const uno::Any& Length ) { @@ -3627,6 +4056,8 @@ ScVbaRange::characters( const uno::Any& Start, const uno::Any& Length ) return new ScVbaCharacters( this, mxContext, aPalette, xSimple, Start, Length ); } +// MS Excel VBA: Deletes the range with specified shift. +// Status: implemented void SAL_CALL ScVbaRange::Delete( const uno::Any& Shift ) { @@ -3675,6 +4106,8 @@ ScVbaRange::Delete( const uno::Any& Shift ) } //XElementAccess +// MS Excel VBA: Checks if the range has elements. +// Status: implemented sal_Bool SAL_CALL ScVbaRange::hasElements() { @@ -3687,6 +4120,8 @@ ScVbaRange::hasElements() } // XEnumerationAccess +// MS Excel VBA: Creates an enumeration over cells in the range. +// Status: implemented uno::Reference< container::XEnumeration > SAL_CALL ScVbaRange::createEnumeration() { @@ -3705,6 +4140,8 @@ ScVbaRange::createEnumeration() return new CellsEnumeration( mxParent, mxContext, m_Areas ); } +// MS Excel VBA: Returns the default method name (XDefaultMethod). +// Status: implemented ::rtl::OUString SAL_CALL ScVbaRange::getDefaultMethodName( ) { @@ -3715,6 +4152,8 @@ ScVbaRange::getDefaultMethodName( ) // returns calc internal col. width ( in points ) double +// MS Excel VBA: Internal helper - calculates column width for a cell range address. +// Status: internal helper ScVbaRange::getCalcColWidth( const table::CellRangeAddress& rAddress) { ScDocument* pDoc = getScDocument(); @@ -3725,6 +4164,8 @@ ScVbaRange::getCalcColWidth( const table::CellRangeAddress& rAddress) } double +// MS Excel VBA: Internal helper - calculates row height for a cell range address. +// Status: internal helper ScVbaRange::getCalcRowHeight( const table::CellRangeAddress& rAddress ) { ScDocument* pDoc = getDocumentFromRange( mxRange ); @@ -3735,6 +4176,8 @@ ScVbaRange::getCalcRowHeight( const table::CellRangeAddress& rAddress ) } // return Char Width in points +// MS Excel VBA: Internal helper - gets the default character width. +// Status: internal helper double getDefaultCharWidth( ScDocShell* pDocShell ) { ScDocument* pDoc = pDocShell->GetDocument(); @@ -3747,6 +4190,8 @@ double getDefaultCharWidth( ScDocShell* pDocShell ) return lcl_hmmToPoints( nCharWidth ); } +// MS Excel VBA: Gets the column width of the range. +// Status: implemented uno::Any SAL_CALL ScVbaRange::getColumnWidth() { @@ -3785,6 +4230,8 @@ ScVbaRange::getColumnWidth() return uno::makeAny( nColWidth ); } +// MS Excel VBA: Sets the column width of the range. +// Status: implemented void SAL_CALL ScVbaRange::setColumnWidth( const uno::Any& _columnwidth ) { @@ -3821,6 +4268,8 @@ ScVbaRange::setColumnWidth( const uno::Any& _columnwidth ) } } +// MS Excel VBA: Gets the width of the range. +// Status: implemented uno::Any SAL_CALL ScVbaRange::getWidth() { @@ -3842,6 +4291,8 @@ ScVbaRange::getWidth() return uno::makeAny( nWidth ); } +// MS Excel VBA: Returns the Areas collection of the range. +// Status: implemented uno::Any SAL_CALL ScVbaRange::Areas( const uno::Any& item) { @@ -3851,6 +4302,8 @@ ScVbaRange::Areas( const uno::Any& item) } uno::Reference< excel::XRange > +// MS Excel VBA: Internal helper - gets a sub-range by index. +// Status: internal helper ScVbaRange::getArea( sal_Int32 nIndex ) { if ( !m_Areas.is() ) @@ -3860,6 +4313,8 @@ ScVbaRange::getArea( sal_Int32 nIndex ) } uno::Any +// MS Excel VBA: Returns a Border object or Border collection. +// Status: implemented ScVbaRange::Borders( const uno::Any& item ) { if ( !item.hasValue() ) @@ -3867,6 +4322,8 @@ ScVbaRange::Borders( const uno::Any& item ) return getBorders()->Item( item, uno::Any() ); } +// MS Excel VBA: Sets border around the range. +// Status: implemented uno::Any SAL_CALL ScVbaRange::BorderAround( const css::uno::Any& LineStyle, const css::uno::Any& Weight, const css::uno::Any& ColorIndex, const css::uno::Any& Color ) @@ -3914,6 +4371,8 @@ ScVbaRange::BorderAround( const css::uno::Any& LineStyle, const css::uno::Any& W return uno::makeAny( sal_True ); } +// MS Excel VBA: Gets the row height of the range. +// Status: implemented uno::Any SAL_CALL ScVbaRange::getRowHeight() { @@ -3953,6 +4412,8 @@ ScVbaRange::getRowHeight() return uno::makeAny( nHeight ); } +// MS Excel VBA: Sets the row height of the range. +// Status: implemented void SAL_CALL ScVbaRange::setRowHeight( const uno::Any& _rowheight) { @@ -3983,6 +4444,8 @@ ScVbaRange::setRowHeight( const uno::Any& _rowheight) nTwips, sal_True, sal_True ); } +// MS Excel VBA: Gets/sets the page break for the range. +// Status: implemented uno::Any SAL_CALL ScVbaRange::getPageBreak() { @@ -4019,6 +4482,8 @@ ScVbaRange::getPageBreak() return uno::makeAny( nPageBreak ); } +// MS Excel VBA: Sets the page break for the range. +// Status: implemented void SAL_CALL ScVbaRange::setPageBreak( const uno::Any& _pagebreak) { @@ -4050,6 +4515,8 @@ ScVbaRange::setPageBreak( const uno::Any& _pagebreak) } } +// MS Excel VBA: Gets the height of the range. +// Status: implemented uno::Any SAL_CALL ScVbaRange::getHeight() { @@ -4072,6 +4539,8 @@ ScVbaRange::getHeight() } awt::Point +// MS Excel VBA: Internal helper - gets the position of the range. +// Status: internal helper ScVbaRange::getPosition() { awt::Point aPoint; @@ -4083,6 +4552,8 @@ ScVbaRange::getPosition() xProps->getPropertyValue(POSITION) >>= aPoint; return aPoint; } +// MS Excel VBA: Gets the left position of the range. +// Status: implemented uno::Any SAL_CALL ScVbaRange::getLeft() { @@ -4094,6 +4565,8 @@ ScVbaRange::getLeft() } +// MS Excel VBA: Gets the top position of the range. +// Status: implemented uno::Any SAL_CALL ScVbaRange::getTop() { @@ -4105,6 +4578,8 @@ ScVbaRange::getTop() } uno::Reference< excel::XWorksheet > +// MS Excel VBA: Returns the parent worksheet. +// Status: implemented ScVbaRange::getWorksheet() { // #TODO #FIXME parent should always be set up ( currently that's not @@ -4130,6 +4605,8 @@ ScVbaRange::getWorksheet() // #TODO remove this ugly application processing // Process an application Range request e.g. 'Range("a1,b2,a4:b6") uno::Reference< excel::XRange > +// MS Excel VBA: Static helper - creates a Range object from cell references. +// Status: internal helper ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xContext, const css::uno::Any &Cell1, const css::uno::Any &Cell2 ) { // Although the documentation seems clear that Range without a @@ -4262,6 +4739,8 @@ void lcl_SelectAll( ScDocShell* pDocShell, ScQueryParam& aParam ) ScQueryParam lcl_GetQueryParam( ScDocShell* pDocShell, sal_Int16 nSheet ) { +// MS Excel VBA: Internal helper - gets DB data. +// Status: internal helper ScDBData* pDBData = lcl_GetDBData_Impl( pDocShell, nSheet ); ScQueryParam aParam; if (pDBData) @@ -4296,6 +4775,8 @@ void lcl_SetAllQueryForField( ScDocShell* pDocShell, SCCOLROW nField, sal_Int16 { ScQueryParam aParam = lcl_GetQueryParam( pDocShell, nSheet ); lcl_SetAllQueryForField( aParam, nField ); +// MS Excel VBA: Internal helper - selects all rows matching criteria. +// Status: internal helper lcl_SelectAll( pDocShell, aParam ); } @@ -4387,6 +4868,8 @@ void lcl_setTableFieldsFromCriteria( rtl::OUString& sCriteria1, uno::Reference< rFilterField.StringValue = sCriteria1; } +// MS Excel VBA: Filters the range using AutoFilter criteria. +// Status: implemented void SAL_CALL ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const uno::Any& Operator, const uno::Any& Criteria2, const uno::Any& VisibleDropDown ) { @@ -4397,6 +4880,8 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const ScDocShell* pShell = getScDocShell(); sal_Bool bHasAuto = sal_False; rtl::OUString sAutofiltRangeName; +// MS Excel VBA: Internal helper - gets the auto filter range. +// Status: internal helper uno::Reference< sheet::XDatabaseRange > xDataBaseRange = lcl_GetAutoFiltRange( pShell, nSheet, sAutofiltRangeName ); if ( xDataBaseRange.is() ) bHasAuto = true; @@ -4444,6 +4929,8 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const } } +// MS Excel VBA: Internal helper - gets all database ranges. +// Status: internal helper uno::Reference< sheet::XDatabaseRanges > xDBRanges = lcl_GetDataBaseRanges( pShell ); if ( xDBRanges.is() ) { @@ -4578,6 +5065,8 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const if ( sCriteria2.getLength() > 0 ) { uno::Reference< beans::XPropertySet > xProps; +// MS Excel VBA: Internal helper - sets table fields from filter criteria. +// Status: internal helper lcl_setTableFieldsFromCriteria( sCriteria2, xProps, sTabFilts[1] ); sTabFilts[1].IsNumeric = sal_False; } @@ -4611,12 +5100,16 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const if ( bHasAuto ) { // find the any field with the query and select all +// MS Excel VBA: Internal helper - gets query parameters. +// Status: internal helper ScQueryParam aParam = lcl_GetQueryParam( pShell, nSheet ); SCSIZE i = 0; for (; i( xHlinks.get() ) ); } +// MS Excel VBA: Gets the data validation for the range. +// Status: implemented css::uno::Reference< excel::XValidation > SAL_CALL ScVbaRange::getValidation() { @@ -4901,6 +5404,8 @@ sal_Unicode lclGetPrefixChar( const uno::Reference< table::XCellRange >& rxRange prefixes for two cells, this function returns 0. */ sal_Unicode cCurrPrefix = 0; +// MS Excel VBA: Internal helper - gets CellRangeAddress from a cell range. +// Status: internal helper table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxRange ); sal_Int32 nEndCol = aRangeAddr.EndColumn - aRangeAddr.StartColumn; sal_Int32 nEndRow = aRangeAddr.EndRow - aRangeAddr.StartRow; @@ -4943,6 +5448,8 @@ inline uno::Any lclGetPrefixVariant( sal_Unicode cPrefixChar ) } // namespace +// MS Excel VBA: Gets the prefix character for the range. +// Status: implemented uno::Any SAL_CALL ScVbaRange::getPrefixCharacter() { /* (1) If Application.TransitionNavigKeys is false, this function returns @@ -4968,6 +5475,8 @@ uno::Any SAL_CALL ScVbaRange::getPrefixCharacter() throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected empty Range object" ) ), uno::Reference< uno::XInterface >() ); } +// MS Excel VBA: Gets the show detail setting for the range. +// Status: implemented uno::Any ScVbaRange::getShowDetail() { // #FIXME, If the specified range is in a PivotTable report @@ -5011,6 +5520,8 @@ uno::Any ScVbaRange::getShowDetail() return aNULL(); } +// MS Excel VBA: Sets the show detail setting for the range. +// Status: implemented void ScVbaRange::setShowDetail(const uno::Any& aShowDetail) { // #FIXME, If the specified range is in a PivotTable report @@ -5046,6 +5557,8 @@ void ScVbaRange::setShowDetail(const uno::Any& aShowDetail) } } +// MS Excel VBA: Returns the MergeArea for the range. +// Status: implemented uno::Reference< excel::XRange > SAL_CALL ScVbaRange::MergeArea() { @@ -5075,6 +5588,8 @@ ScVbaRange::MergeArea() return new ScVbaRange( mxParent, mxContext, mxRange ); } +// MS Excel VBA: Prints the range. +// Status: implemented void SAL_CALL ScVbaRange::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& ActivePrinter, const uno::Any& PrintToFile, const uno::Any& Collate, const uno::Any& PrToFileName ) { @@ -5109,6 +5624,8 @@ ScVbaRange::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any& } } +// MS Excel VBA: Fills the range with a series using AutoFill. +// Status: implemented void SAL_CALL ScVbaRange::AutoFill( const uno::Reference< excel::XRange >& Destination, const uno::Any& Type ) { @@ -5234,6 +5751,8 @@ ScVbaRange::AutoFill( const uno::Reference< excel::XRange >& Destination, const aFunc.FillAuto( aSourceRange, NULL, eDir, eCmd, eDateCmd, nCount, fStep, fEndValue, sal_True, sal_True ); #endif } +// MS Excel VBA: Performs goal seek to find input value for a goal. +// Status: implemented sal_Bool SAL_CALL ScVbaRange::GoalSeek( const uno::Any& Goal, const uno::Reference< excel::XRange >& ChangingCell ) { @@ -5264,12 +5783,16 @@ ScVbaRange::GoalSeek( const uno::Any& Goal, const uno::Reference< excel::XRange return bRes; } +// MS Excel VBA: Calculates the formulas in the range. +// Status: implemented void ScVbaRange::Calculate( ) { getWorksheet()->Calculate(); } +// MS Excel VBA: Returns a subrange at the specified row and column. +// Status: implemented uno::Reference< excel::XRange > SAL_CALL ScVbaRange::Item( const uno::Any& row, const uno::Any& column ) { @@ -5288,6 +5811,8 @@ ScVbaRange::Item( const uno::Any& row, const uno::Any& column ) } void +// MS Excel VBA: Creates an outline for the range. +// Status: stubbed - not fully implemented in Calc ScVbaRange::AutoOutline( ) { // #TODO #FIXME needs to check for summary row/col ( whatever they are ) @@ -5311,6 +5836,8 @@ ScVbaRange::AutoOutline( ) DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); } +// MS Excel VBA: Clears the outline for the range. +// Status: stubbed - not fully implemented in Calc void SAL_CALL ScVbaRange:: ClearOutline( ) { @@ -5331,6 +5858,8 @@ ScVbaRange:: ClearOutline( ) } void +// MS Excel VBA: Internal helper - groups or ungroups the range. +// Status: internal helper ScVbaRange::groupUnGroup( bool bUnGroup ) { if ( m_Areas->getCount() > 1 ) @@ -5347,11 +5876,15 @@ ScVbaRange::groupUnGroup( bool bUnGroup ) xSheetOutline->group( thisAddress, nOrient ); } +// MS Excel VBA: Groups the range. +// Status: stubbed - not fully implemented in Calc void SAL_CALL ScVbaRange::Group( ) { groupUnGroup(); } +// MS Excel VBA: Ungroups the range. +// Status: stubbed - not fully implemented in Calc void SAL_CALL ScVbaRange::Ungroup( ) { @@ -5363,6 +5896,8 @@ void lcl_mergeCellsOfRange( const uno::Reference< table::XCellRange >& xCellRang uno::Reference< util::XMergeable > xMergeable( xCellRange, uno::UNO_QUERY_THROW ); xMergeable->merge(_bMerge); } +// MS Excel VBA: Merges cells in the range. +// Status: implemented void SAL_CALL ScVbaRange::Merge( const uno::Any& Across ) { @@ -5392,6 +5927,8 @@ ScVbaRange::Merge( const uno::Any& Across ) } } +// MS Excel VBA: Unmerges cells in the range. +// Status: implemented void SAL_CALL ScVbaRange::UnMerge( ) { @@ -5405,9 +5942,13 @@ ScVbaRange::UnMerge( ) } return; } +// MS Excel VBA: Internal helper - merges or unmerges cells in a range. +// Status: internal helper lcl_mergeCellsOfRange( mxRange, sal_False); } +// MS Excel VBA: Gets the style of the range. +// Status: implemented uno::Any SAL_CALL ScVbaRange::getStyle() { @@ -5424,6 +5965,8 @@ ScVbaRange::getStyle() uno::Reference< excel::XStyle > xStyle = new ScVbaStyle( this, mxContext, sStyleName, xModel ); return uno::makeAny( xStyle ); } +// MS Excel VBA: Sets the style of the range. +// Status: implemented void SAL_CALL ScVbaRange::setStyle( const uno::Any& _style ) { @@ -5440,6 +5983,8 @@ ScVbaRange::setStyle( const uno::Any& _style ) } uno::Reference< excel::XRange > +// MS Excel VBA: Internal helper - returns previous or next cell. +// Status: internal helper ScVbaRange::PreviousNext( bool bIsPrevious ) { ScMarkData markedRange; @@ -5468,6 +6013,8 @@ ScVbaRange::PreviousNext( bool bIsPrevious ) return new ScVbaRange( mxParent, mxContext, xRange ); } +// MS Excel VBA: Returns the next cell in the range. +// Status: implemented uno::Reference< excel::XRange > SAL_CALL ScVbaRange::Next() { @@ -5479,6 +6026,8 @@ ScVbaRange::Next() return PreviousNext( false ); } +// MS Excel VBA: Returns the previous cell in the range. +// Status: implemented uno::Reference< excel::XRange > SAL_CALL ScVbaRange::Previous() { @@ -5490,6 +6039,8 @@ ScVbaRange::Previous() return PreviousNext( true ); } +// MS Excel VBA: Returns a range of cells with specified type. +// Status: implemented uno::Reference< excel::XRange > SAL_CALL ScVbaRange::SpecialCells( const uno::Any& _oType, const uno::Any& _oValue) { @@ -5599,6 +6150,8 @@ sal_Int32 lcl_getFormulaResultFlags(const uno::Any& aType) } uno::Reference< excel::XRange > +// MS Excel VBA: Internal helper - implementation for SpecialCells method. +// Status: internal helper ScVbaRange::SpecialCellsImpl( sal_Int32 nType, const uno::Any& _oValue) { uno::Reference< excel::XRange > xRange; @@ -5614,6 +6167,8 @@ ScVbaRange::SpecialCellsImpl( sal_Int32 nType, const uno::Any& _oValue) case excel::XlCellType::xlCellTypeAllValidation: case excel::XlCellType::xlCellTypeSameValidation: // Shouldn't get here ( should be filtered out by +// MS Excel VBA: Returns a range of cells with specified type. +// Status: implemented // ScVbaRange::SpecialCells() DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString()); break; @@ -5643,6 +6198,8 @@ ScVbaRange::SpecialCellsImpl( sal_Int32 nType, const uno::Any& _oValue) } if (xLocSheetCellRanges.is()) { +// MS Excel VBA: Internal helper - creates an XRange from sheet cell ranges. +// Status: internal helper xRange = lcl_makeXRangeFromSheetCellRanges( getParent(), mxContext, xLocSheetCellRanges, getScDocShell() ); } } @@ -5653,6 +6210,8 @@ ScVbaRange::SpecialCellsImpl( sal_Int32 nType, const uno::Any& _oValue) return xRange; } +// MS Excel VBA: Removes subtotals from the range. +// Status: stubbed - not fully implemented in Calc void SAL_CALL ScVbaRange::RemoveSubtotal( ) { @@ -5660,6 +6219,8 @@ ScVbaRange::RemoveSubtotal( ) xSub->removeSubTotals(); } +// MS Excel VBA: Creates subtotals in the range. +// Status: stubbed - not fully implemented in Calc void SAL_CALL ScVbaRange::Subtotal( ::sal_Int32 _nGroupBy, ::sal_Int32 _nFunction, const uno::Sequence< ::sal_Int32 >& _nTotalList, const uno::Any& aReplace, const uno::Any& PageBreaks, const uno::Any& /*SummaryBelowData*/ ) { @@ -5732,6 +6293,8 @@ ScVbaRange::Subtotal( ::sal_Int32 _nGroupBy, ::sal_Int32 _nFunction, const uno:: } rtl::OUString& +// MS Excel VBA: Returns the implementation service name for UNO. +// Status: implemented ScVbaRange::getServiceImplName() { static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaRange") ); @@ -5739,6 +6302,8 @@ ScVbaRange::getServiceImplName() } uno::Sequence< rtl::OUString > +// MS Excel VBA: Returns the list of supported service names for UNO. +// Status: implemented ScVbaRange::getServiceNames() { static uno::Sequence< rtl::OUString > aServiceNames; diff --git a/main/sc/source/ui/vba/vbarange.hxx b/main/sc/source/ui/vba/vbarange.hxx index d6590bc3864..d4160d50a40 100644 --- a/main/sc/source/ui/vba/vbarange.hxx +++ b/main/sc/source/ui/vba/vbarange.hxx @@ -27,6 +27,8 @@ #include #include +#include +#include #include #include #include @@ -61,6 +63,8 @@ class ScRangeList; //typedef InheritedHelperInterfaceImpl1< ov::excel::XRange > ScVbaRange_BASE; typedef ScVbaFormat< ov::excel::XRange > ScVbaRange_BASE; +// MS Excel VBA: Internal helper class for visiting array nodes. +// Status: internal helper class ArrayVisitor { public: @@ -68,6 +72,8 @@ public: virtual ~ArrayVisitor(){} }; +// MS Excel VBA: Internal helper class for setting values in an array. +// Status: internal helper class ValueSetter : public ArrayVisitor { public: @@ -76,6 +82,8 @@ public: }; +// MS Excel VBA: Internal helper class for getting values from an array. +// Status: internal helper class ValueGetter : public ArrayVisitor { @@ -86,6 +94,8 @@ public: +// MS Excel VBA: Represents a cell or range of cells in an Excel worksheet. +// Status: implemented - primary Range implementation class ScVbaRange : public ScVbaRange_BASE { css::uno::Reference< ov::XCollection > m_Areas; @@ -96,63 +106,135 @@ class ScVbaRange : public ScVbaRange_BASE sal_Bool mbIsColumns; css::uno::Reference< ov::excel::XValidation > m_xValidation; +// MS Excel VBA: Internal helper - calculates column width for a cell range address. +// Status: internal helper double getCalcColWidth( const css::table::CellRangeAddress& ); +// MS Excel VBA: Internal helper - calculates row height for a cell range address. +// Status: internal helper double getCalcRowHeight( const css::table::CellRangeAddress& ); +// MS Excel VBA: Internal helper - visits all cells in an array for processing. +// Status: internal helper void visitArray( ArrayVisitor& vistor ); +// MS Excel VBA: Internal helper - gets the entire column or row of the range. +// Status: internal helper css::uno::Reference< ov::excel::XRange > getEntireColumnOrRow( bool bColumn = true ); +// MS Excel VBA: Internal helper - fills cells with a series of values. +// Status: internal helper void fillSeries( css::sheet::FillDirection nFillDirection, css::sheet::FillMode nFillMode, css::sheet::FillDateMode nFillDateMode, double fStep, double fEndValue ); +// MS Excel VBA: Internal helper - clears contents with specified flags. +// Status: internal helper void ClearContents( sal_Int32 nFlags, bool bFireEvent ); +// MS Excel VBA: Internal helper - gets values using a ValueGetter. +// Status: internal helper css::uno::Any getValue( ValueGetter& rValueGetter ); +// MS Excel VBA: Internal helper - sets values using a ValueSetter. +// Status: internal helper void setValue( const css::uno::Any& aValue, ValueSetter& setter, bool bFireEvent ); +// MS Excel VBA: Internal helper - gets formula values from cells. +// Status: internal helper css::uno::Any getFormulaValue( formula::FormulaGrammar::Grammar ); +// MS Excel VBA: Internal helper - sets formula values in cells. +// Status: internal helper void setFormulaValue( const css::uno::Any& aValue, formula::FormulaGrammar::Grammar, bool bFireEvent ); +// MS Excel VBA: Internal helper - gets a sub-range by index. +// Status: internal helper css::uno::Reference< ov::excel::XRange > getArea( sal_Int32 nIndex ); + // MS Excel VBA: Internal helper - gets the ScCellRangeObj implementation. + // Status: internal helper ScCellRangeObj* getCellRangeObj( ); +// MS Excel VBA: Internal helper - gets the ScCellRangesObj implementation. +// Status: internal helper ScCellRangesObj* getCellRangesObj(); +// MS Excel VBA: Internal helper - gets or creates the Borders collection. +// Status: internal helper css::uno::Reference< ov::XCollection >& getBorders(); +// MS Excel VBA: Internal helper - groups or ungroups the range. +// Status: internal helper void groupUnGroup( bool bUnGroup = false ); +// MS Excel VBA: Internal helper - returns previous or next cell. +// Status: internal helper css::uno::Reference< ov::excel::XRange > PreviousNext( bool bIsPrevious ); +// MS Excel VBA: Internal helper - implementation for SpecialCells method. +// Status: internal helper css::uno::Reference< ov::excel::XRange > SpecialCellsImpl( sal_Int32 nType, const css::uno::Any& _oValue); +// MS Excel VBA: Internal helper - gets the position of the range. +// Status: internal helper css::awt::Point getPosition(); /** Fires a Worksheet_Change event for this range or range list. */ +// MS Excel VBA: Internal helper - fires a Worksheet_Change event for this range. +// Status: internal helper void fireChangeEvent(); protected: +// MS Excel VBA: Internal helper - gets the ScCellRangesBase interface. +// Status: internal helper virtual ScCellRangesBase* getCellRangesBase(); +// MS Excel VBA: Internal helper - gets the current data set. +// Status: internal helper virtual SfxItemSet* getCurrentDataSet( ); public: +// MS Excel VBA: Constructor from a cell range. +// Status: implemented 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 ); +// MS Excel VBA: Constructor from a cell range. +// Status: implemented 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 ); +// MS Excel VBA: Constructor taking arguments sequence (for UNO create). +// Status: implemented ScVbaRange( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& xContext ); + // MS Excel VBA: Gets the underlying ScDocument for this range. + // Status: implemented ScDocument* getScDocument(); + // MS Excel VBA: Gets the underlying ScDocShell for this range. + // Status: implemented ScDocShell* getScDocShell(); /** Returns the ScVbaRange implementation object for the passed VBA Range object. */ +// MS Excel VBA: Returns the ScVbaRange implementation object for a VBA Range object. +// Status: implemented static ScVbaRange* getImplementation( const css::uno::Reference< ov::excel::XRange >& rxRange ); + // MS Excel VBA: Gets the underlying model object. + // Status: implemented css::uno::Reference< css::frame::XModel > getUnoModel(); +// MS Excel VBA: Static method to get the underlying model from a Range object. +// Status: implemented static css::uno::Reference< css::frame::XModel > getUnoModel( const css::uno::Reference< ov::excel::XRange >& rxRange ); +// MS Excel VBA: Gets the ScRangeList for this range. +// Status: implemented const ScRangeList& getScRangeList(); + // MS Excel VBA: Static method to get the underlying model from a Range object. + // Status: implemented static const ScRangeList& getScRangeList( const css::uno::Reference< ov::excel::XRange >& rxRange ); +// MS Excel VBA: Destructor. +// Status: implemented virtual ~ScVbaRange(); +// MS Excel VBA: Returns this object as XHelperInterface. +// Status: implemented virtual css::uno::Reference< ov::XHelperInterface > thisHelperIface() { return this; } +// MS Excel VBA: Checks if this range is a single cell. +// Status: implemented bool isSingleCellRange(); +// MS Excel VBA: Creates a Range object from a range name string. +// Status: implemented static css::uno::Reference< ov::excel::XRange > getRangeObjectForName( const css::uno::Reference< css::uno::XComponentContext >& xContext, const rtl::OUString& sRangeName, ScDocShell* pDocSh, formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_XL_A1 ); +// MS Excel VBA: Creates a Range object from row and column indices. +// Status: implemented static css::uno::Reference< ov::excel::XRange > CellsHelper( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, @@ -160,118 +242,320 @@ public: const css::uno::Any &nRowIndex, const css::uno::Any &nColumnIndex ); // Attributes +// MS Excel VBA: Gets the value of the range as a Variant. +// Status: implemented virtual css::uno::Any SAL_CALL getValue(); virtual void SAL_CALL setValue( const css::uno::Any& aValue ); + // MS Excel VBA: Gets the value of the range without date coercion. + // Status: implemented + virtual css::uno::Any SAL_CALL getValue2(); + // MS Excel VBA: Sets the value of the range without date coercion. + // Status: implemented + virtual void SAL_CALL setValue2( const css::uno::Any& aValue ); + // MS Excel VBA: Gets the formula of the range. +// Status: implemented virtual css::uno::Any SAL_CALL getFormula(); + // MS Excel VBA: Sets the formula of the range. +// Status: implemented virtual void SAL_CALL setFormula( const css::uno::Any& rFormula ); +// MS Excel VBA: Gets the formula using Formula2 syntax (array-enabled). +// Status: implemented + virtual css::uno::Any SAL_CALL getFormula2(); +// MS Excel VBA: Sets the formula using Formula2 syntax (array-enabled). +// Status: implemented + virtual void SAL_CALL setFormula2( const css::uno::Any& rFormula ); +// MS Excel VBA: Gets the formula as an array. +// Status: implemented virtual css::uno::Any SAL_CALL getFormulaArray(); +// MS Excel VBA: Sets the formula as an array. +// Status: implemented virtual void SAL_CALL setFormulaArray(const css::uno::Any& rFormula); +// MS Excel VBA: Gets the formula in R1C1 notation. +// Status: implemented virtual css::uno::Any SAL_CALL getFormulaR1C1(); +// MS Excel VBA: Sets the formula in R1C1 notation. +// Status: implemented virtual void SAL_CALL setFormulaR1C1( const css::uno::Any &rFormula ); +// MS Excel VBA: Gets the number of cells in the range. +// Status: implemented virtual ::sal_Int32 SAL_CALL getCount(); +// MS Excel VBA: Gets the row number of the first cell. +// Status: implemented virtual ::sal_Int32 SAL_CALL getRow(); +// MS Excel VBA: Gets the column number of the first cell. +// Status: implemented virtual ::sal_Int32 SAL_CALL getColumn(); +// MS Excel VBA: Gets the text content of the range. +// Status: implemented virtual ::rtl::OUString SAL_CALL getText(); +// MS Excel VBA: Uses the base class setNumberFormat method. +// Status: inherited using ScVbaRange_BASE::setNumberFormat; +// MS Excel VBA: Sets the number format for the range. +// Status: implemented virtual void SAL_CALL setNumberFormat( const css::uno::Any& rNumberFormat ); +// MS Excel VBA: Gets the number format for the range. +// Status: implemented virtual css::uno::Any SAL_CALL getNumberFormat(); +// MS Excel VBA: Sets whether cells are merged in the range. +// Status: implemented virtual void SAL_CALL setMergeCells( const css::uno::Any& bMerge ); +// MS Excel VBA: Gets whether cells are merged in the range. +// Status: implemented virtual css::uno::Any SAL_CALL getMergeCells(); +// MS Excel VBA: Sets whether text is wrapped in the range. +// Status: implemented virtual void SAL_CALL setWrapText( const css::uno::Any& bIsWrapped ); +// MS Excel VBA: Gets whether text is wrapped in the range. +// Status: implemented virtual css::uno::Any SAL_CALL getWrapText(); +// MS Excel VBA: Returns the entire row(s) of the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getEntireRow(); +// MS Excel VBA: Returns the entire column(s) of the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getEntireColumn(); +// MS Excel VBA: Gets or sets the comment for the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XComment > SAL_CALL getComment(); +// MS Excel VBA: Gets whether the range is hidden. +// Status: implemented virtual css::uno::Any SAL_CALL getHidden(); +// MS Excel VBA: Sets whether the range is hidden. +// Status: implemented virtual void SAL_CALL setHidden( const css::uno::Any& _hidden ); +// MS Excel VBA: Gets the column width of the range. +// Status: implemented virtual css::uno::Any SAL_CALL getColumnWidth(); +// MS Excel VBA: Sets the column width of the range. +// Status: implemented virtual void SAL_CALL setColumnWidth( const css::uno::Any& _columnwidth ); +// MS Excel VBA: Gets the row height of the range. +// Status: implemented virtual css::uno::Any SAL_CALL getRowHeight(); +// MS Excel VBA: Sets the row height of the range. +// Status: implemented virtual void SAL_CALL setRowHeight( const css::uno::Any& _rowheight ); +// MS Excel VBA: Gets the width of the range. +// Status: implemented virtual css::uno::Any SAL_CALL getWidth(); +// MS Excel VBA: Gets the height of the range. +// Status: implemented virtual css::uno::Any SAL_CALL getHeight(); +// MS Excel VBA: Gets the top position of the range. +// Status: implemented virtual css::uno::Any SAL_CALL getTop(); +// MS Excel VBA: Gets the left position of the range. +// Status: implemented virtual css::uno::Any SAL_CALL getLeft(); +// MS Excel VBA: Returns the parent worksheet. +// Status: implemented virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getWorksheet(); +// MS Excel VBA: Gets/sets the page break for the range. +// Status: implemented virtual css::uno::Any SAL_CALL getPageBreak(); +// MS Excel VBA: Sets the page break for the range. +// Status: implemented virtual void SAL_CALL setPageBreak( const css::uno::Any& _pagebreak ); +// MS Excel VBA: Gets the data validation for the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XValidation > SAL_CALL getValidation(); +// MS Excel VBA: Gets the prefix character for the range. +// Status: implemented virtual css::uno::Any SAL_CALL getPrefixCharacter(); +// MS Excel VBA: Gets the show detail setting for the range. +// Status: implemented virtual css::uno::Any SAL_CALL getShowDetail(); +// MS Excel VBA: Sets the show detail setting for the range. +// Status: implemented virtual void SAL_CALL setShowDetail(const css::uno::Any& aShowDetail); // Methods +// MS Excel VBA: Returns true if the range represents rows. +// Status: implemented - inline sal_Bool IsRows() { return mbIsRows; } +// MS Excel VBA: Returns true if the range represents columns. +// Status: implemented - inline sal_Bool IsColumns() { return mbIsColumns; } +// MS Excel VBA: Adds a comment to the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XComment > SAL_CALL AddComment( const css::uno::Any& Text ); +// MS Excel VBA: Clears the entire range. +// Status: implemented virtual void SAL_CALL Clear(); +// MS Excel VBA: Clears all comments in the range. +// Status: implemented virtual void SAL_CALL ClearComments(); +// MS Excel VBA: Clears the contents of the range. +// Status: implemented virtual void SAL_CALL ClearContents(); +// MS Excel VBA: Clears the formatting of the range. +// Status: implemented virtual void SAL_CALL ClearFormats(); +// MS Excel VBA: Checks if the range contains any formulas. +// Status: implemented virtual css::uno::Any SAL_CALL HasFormula(); +// MS Excel VBA: Fills left from the source range. +// Status: implemented virtual void SAL_CALL FillLeft(); +// MS Excel VBA: Fills right from the source range. +// Status: implemented virtual void SAL_CALL FillRight(); +// MS Excel VBA: Fills up from the source range. +// Status: implemented virtual void SAL_CALL FillUp(); +// MS Excel VBA: Fills down from the source range. +// Status: implemented virtual void SAL_CALL FillDown(); +// MS Excel VBA: Returns a range offset from the current range by row and column. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Offset( const css::uno::Any &nRowOffset, const css::uno::Any &nColOffset ); +// MS Excel VBA: Returns the current region (data area) around the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL CurrentRegion(); +// MS Excel VBA: Returns the current array for the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL CurrentArray(); +// MS Excel VBA: Returns a Characters object for the range. +// Status: implemented virtual ::rtl::OUString SAL_CALL Characters( const css::uno::Any& nIndex, const css::uno::Any& nCount ); +// MS Excel VBA: Returns the address of the range. +// Status: implemented virtual ::rtl::OUString SAL_CALL Address( const css::uno::Any& RowAbsolute, const css::uno::Any& ColumnAbsolute, const css::uno::Any& ReferenceStyle, const css::uno::Any& External, const css::uno::Any& RelativeTo ); +// MS Excel VBA: Returns a cell or cells from the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Cells( const css::uno::Any &nRow, const css::uno::Any &nCol ); +// MS Excel VBA: Selects the range. +// Status: implemented virtual void SAL_CALL Select(); +// MS Excel VBA: Activates the range. +// Status: implemented virtual void SAL_CALL Activate(); +// MS Excel VBA: Returns a row or rows from the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Rows( const css::uno::Any& nIndex ); +// MS Excel VBA: Returns a column or columns from the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Columns( const css::uno::Any &nIndex ); +// MS Excel VBA: Copies the range to the clipboard or destination. +// Status: implemented virtual void SAL_CALL Copy( const css::uno::Any& Destination ); +// MS Excel VBA: Cuts the range to the clipboard or destination. +// Status: implemented virtual void SAL_CALL Cut( const css::uno::Any& Destination ); +// MS Excel VBA: Resizes the range to specified rows and columns. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Resize( const css::uno::Any& RowSize, const css::uno::Any& ColumnSize ); +// MS Excel VBA: Returns the Font object for the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XFont > SAL_CALL Font(); virtual css::uno::Reference< ov::excel::XInterior > SAL_CALL Interior( ) ; +// MS Excel VBA: Returns a subrange within the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Range( const css::uno::Any &Cell1, const css::uno::Any &Cell2 ); virtual css::uno::Reference< ov::excel::XRange > Range( const css::uno::Any &Cell1, const css::uno::Any &Cell2, bool bForceUseInpuRangeTab ); +// MS Excel VBA: Gets the cell range object. +// Status: implemented virtual css::uno::Any SAL_CALL getCellRange( ); static css::uno::Any getCellRange( const css::uno::Reference< ov::excel::XRange >& rxRange ); +// MS Excel VBA: Pastes from clipboard with specified paste options. +// Status: implemented virtual void SAL_CALL PasteSpecial( const css::uno::Any& Paste, const css::uno::Any& Operation, const css::uno::Any& SkipBlanks, const css::uno::Any& Transpose ); +// MS Excel VBA: Replaces values matching What with Replacement. +// Status: implemented virtual ::sal_Bool SAL_CALL Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replacement, const css::uno::Any& LookAt, const css::uno::Any& SearchOrder, const css::uno::Any& MatchCase, const css::uno::Any& MatchByte, const css::uno::Any& SearchFormat, const css::uno::Any& ReplaceFormat ); +// MS Excel VBA: Finds a value matching the search criteria. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Find( const css::uno::Any& What, const css::uno::Any& After, const css::uno::Any& LookIn, const css::uno::Any& LookAt, const css::uno::Any& SearchOrder, const css::uno::Any& SearchDirection, const css::uno::Any& MatchCase, const css::uno::Any& MatchByte, const css::uno::Any& SearchFormat ); +// MS Excel VBA: Sorts the range by specified keys. +// Status: implemented virtual void SAL_CALL Sort( const css::uno::Any& Key1, const css::uno::Any& Order1, const css::uno::Any& Key2, const css::uno::Any& Type, const css::uno::Any& Order2, const css::uno::Any& Key3, const css::uno::Any& Order3, const css::uno::Any& Header, const css::uno::Any& OrderCustom, const css::uno::Any& MatchCase, const css::uno::Any& Orientation, const css::uno::Any& SortMethod, const css::uno::Any& DataOption1, const css::uno::Any& DataOption2, const css::uno::Any& DataOption3 ); +// MS Excel VBA: Returns the last cell in the specified direction. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL End( ::sal_Int32 Direction ); +// MS Excel VBA: Returns a Characters object for a substring. +// Status: implemented virtual css::uno::Reference< ov::excel::XCharacters > SAL_CALL characters( const css::uno::Any& Start, const css::uno::Any& Length ); +// MS Excel VBA: Deletes the range with specified shift. +// Status: implemented virtual void SAL_CALL Delete( const css::uno::Any& Shift ); +// MS Excel VBA: Returns the Areas collection of the range. +// Status: implemented virtual css::uno::Any SAL_CALL Areas( const css::uno::Any& ); +// MS Excel VBA: Returns a Border object or Border collection. +// Status: implemented virtual css::uno::Any SAL_CALL Borders( const css::uno::Any& ); +// MS Excel VBA: Sets border around the range. +// Status: implemented virtual css::uno::Any SAL_CALL BorderAround( const css::uno::Any& LineStyle, const css::uno::Any& Weight, const css::uno::Any& ColorIndex, const css::uno::Any& Color ); +// MS Excel VBA: Splits column data into separate columns. +// Status: stubbed - not fully implemented in Calc virtual void SAL_CALL TextToColumns( const css::uno::Any& Destination, const css::uno::Any& DataType, const css::uno::Any& TextQualifier, const css::uno::Any& ConsecutinveDelimiter, const css::uno::Any& Tab, const css::uno::Any& Semicolon, const css::uno::Any& Comma, const css::uno::Any& Space, const css::uno::Any& Other, const css::uno::Any& OtherChar, const css::uno::Any& FieldInfo, const css::uno::Any& DecimalSeparator, const css::uno::Any& ThousandsSeparator, const css::uno::Any& TrailingMinusNumbers ); +// MS Excel VBA: Returns a Hyperlink by index. +// Status: implemented virtual css::uno::Any SAL_CALL Hyperlinks( const css::uno::Any& aIndex ); +// MS Excel VBA: Filters the range using AutoFilter criteria. +// Status: implemented virtual void SAL_CALL AutoFilter( const css::uno::Any& Field, const css::uno::Any& Criteria1, const css::uno::Any& Operator, const css::uno::Any& Criteria2, const css::uno::Any& VisibleDropDown ); +// MS Excel VBA: Inserts cells with specified shift. +// Status: implemented virtual void SAL_CALL Insert( const css::uno::Any& Shift, const css::uno::Any& CopyOrigin ); +// MS Excel VBA: Automatically fits row height or column width. +// Status: implemented virtual void SAL_CALL Autofit(); +// MS Excel VBA: Prints the range. +// Status: implemented virtual void SAL_CALL PrintOut( const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName ); +// MS Excel VBA: Fills the range with a series using AutoFill. +// Status: implemented virtual void SAL_CALL AutoFill( const css::uno::Reference< ov::excel::XRange >& Destination, const css::uno::Any& Type ) ; void SAL_CALL Calculate( ); virtual void SAL_CALL AutoOutline( ); +// MS Excel VBA: Returns a subrange at the specified row and column. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Item( const ::css::uno::Any& row, const css::uno::Any& column ); virtual void SAL_CALL ClearOutline( ); virtual void SAL_CALL Ungroup( ); virtual void SAL_CALL Group( ); +// MS Excel VBA: Merges cells in the range. +// Status: implemented virtual void SAL_CALL Merge( const css::uno::Any& Across ); virtual void SAL_CALL UnMerge( ); +// MS Excel VBA: Gets the style of the range. +// Status: implemented virtual css::uno::Any SAL_CALL getStyle(); +// MS Excel VBA: Sets the style of the range. +// Status: implemented virtual void SAL_CALL setStyle( const css::uno::Any& _style ); +// MS Excel VBA: Returns the FormatConditions collection. +// Status: stubbed - not fully implemented in Calc + virtual css::uno::Reference< ooo::vba::excel::XFormatConditions > SAL_CALL getFormatConditions(); +// MS Excel VBA: Returns the QueryTable for the range. +// Status: stubbed - not fully implemented in Calc + virtual css::uno::Reference< ooo::vba::excel::XQueryTable > SAL_CALL getQueryTable(); +// MS Excel VBA: Returns the next cell in the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Next(); +// MS Excel VBA: Returns the previous cell in the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Previous(); virtual void SAL_CALL RemoveSubtotal( ); +// MS Excel VBA: Returns the MergeArea for the range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL MergeArea(); +// MS Excel VBA: Creates subtotals in the range. +// Status: stubbed - not fully implemented in Calc virtual void SAL_CALL Subtotal( ::sal_Int32 GroupBy, ::sal_Int32 Function, const css::uno::Sequence< ::sal_Int32 >& TotalList, const css::uno::Any& Replace, const css::uno::Any& PageBreaks, const css::uno::Any& SummaryBelowData ); // XEnumerationAccess +// MS Excel VBA: Creates an enumeration over cells in the range. +// Status: implemented virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration(); // XElementAccess virtual css::uno::Type SAL_CALL getElementType() @@ -279,6 +563,8 @@ public: return ov::excel::XRange::static_type(0); } +// MS Excel VBA: Checks if the range has elements. +// Status: implemented virtual sal_Bool SAL_CALL hasElements(); // XDefaultMethod ::rtl::OUString SAL_CALL getDefaultMethodName( ); @@ -293,11 +579,21 @@ public: // * or a list of address ( multi-area ) // * object should be a lightweight as possible // * we shouldn't need hacks like this below +// MS Excel VBA: Static helper - creates a Range object from cell references. +// Status: internal helper static css::uno::Reference< ov::excel::XRange > ApplicationRange( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Any &Cell1, const css::uno::Any &Cell2 ); +// MS Excel VBA: Performs goal seek to find input value for a goal. +// Status: implemented virtual sal_Bool SAL_CALL GoalSeek( const css::uno::Any& Goal, const css::uno::Reference< ov::excel::XRange >& ChangingCell ); +// MS Excel VBA: Returns a range of cells with specified type. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL SpecialCells( const css::uno::Any& _oType, const css::uno::Any& _oValue); // XHelperInterface +// MS Excel VBA: Returns the implementation service name for UNO. +// Status: implemented virtual rtl::OUString& getServiceImplName(); +// MS Excel VBA: Returns the list of supported service names for UNO. +// Status: implemented virtual css::uno::Sequence getServiceNames(); }; #endif /* SC_VBA_RANGE_HXX */ diff --git a/main/sc/source/ui/vba/vbasheetobject.hxx b/main/sc/source/ui/vba/vbasheetobject.hxx index 44cbeb90565..28f327297f2 100644 --- a/main/sc/source/ui/vba/vbasheetobject.hxx +++ b/main/sc/source/ui/vba/vbasheetobject.hxx @@ -95,18 +95,32 @@ public: const css::uno::Reference< css::drawing::XShape >& rxShape ); // XSheetObject attributes + // MS Excel VBA: Gets/sets the left edge position (points) of the sheet object. + // Status: implemented - reads/writes from shape Position virtual double SAL_CALL getLeft(); virtual void SAL_CALL setLeft( double fLeft ); + // MS Excel VBA: Gets/sets the top edge position (points) of the sheet object. + // Status: implemented virtual double SAL_CALL getTop(); virtual void SAL_CALL setTop( double fTop ); + // MS Excel VBA: Gets/sets the width (points) of the sheet object. + // Status: implemented virtual double SAL_CALL getWidth(); virtual void SAL_CALL setWidth( double fWidth ); + // MS Excel VBA: Gets/sets the height (points) of the sheet object. + // Status: implemented virtual double SAL_CALL getHeight(); virtual void SAL_CALL setHeight( double fHeight ); + // MS Excel VBA: Gets/sets the name of the sheet object. + // Status: implemented - reads from shape Name virtual ::rtl::OUString SAL_CALL getName(); virtual void SAL_CALL setName( const ::rtl::OUString& rName ); + // MS Excel VBA: Gets/sets the placement: 0=free floating, 1=move, 2=move and size. + // Status: implemented - maps to MoveWithCells/SizeWithCells virtual sal_Int32 SAL_CALL getPlacement(); virtual void SAL_CALL setPlacement( sal_Int32 nPlacement ); + // MS Excel VBA: Gets/sets whether the object is printed with the worksheet. + // Status: implemented - maps to PrintMode shape property virtual sal_Bool SAL_CALL getPrintObject(); virtual void SAL_CALL setPrintObject( sal_Bool bPrintObject ); @@ -188,18 +202,30 @@ public: const css::uno::Reference< css::drawing::XControlShape >& rxControlShape ); // XButton attributes + // MS Excel VBA: Gets/sets the button caption text. + // Status: implemented virtual ::rtl::OUString SAL_CALL getCaption(); virtual void SAL_CALL setCaption( const ::rtl::OUString& rCaption ); + // MS Excel VBA: Gets/sets the Font object for the button text. + // Status: implemented virtual css::uno::Reference< ov::excel::XFont > SAL_CALL getFont(); virtual void SAL_CALL setFont( const css::uno::Reference< ov::excel::XFont >& rxFont ); + // MS Excel VBA: Gets/sets the horizontal alignment (xlLeft, xlCenter, xlRight). + // Status: implemented virtual sal_Int32 SAL_CALL getHorizontalAlignment(); virtual void SAL_CALL setHorizontalAlignment( sal_Int32 nAlign ); + // MS Excel VBA: Gets/sets the vertical alignment (xlTop, xlCenter, xlBottom). + // Status: implemented virtual sal_Int32 SAL_CALL getVerticalAlignment(); virtual void SAL_CALL setVerticalAlignment( sal_Int32 nAlign ); + // MS Excel VBA: Gets/sets the text orientation angle (degrees). + // Status: implemented virtual sal_Int32 SAL_CALL getOrientation(); virtual void SAL_CALL setOrientation( sal_Int32 nOrientation ); // XButton methods + // MS Excel VBA: Returns the Characters object for a subset of button text. + // Status: implemented - delegates to ScVbaButtonCharacters css::uno::Reference< ov::excel::XCharacters > SAL_CALL Characters( const css::uno::Any& rStart, const css::uno::Any& rLength ); diff --git a/main/sc/source/ui/vba/vbaworkbook.cxx b/main/sc/source/ui/vba/vbaworkbook.cxx index 45177f2a77e..da3cb59ac68 100644 --- a/main/sc/source/ui/vba/vbaworkbook.cxx +++ b/main/sc/source/ui/vba/vbaworkbook.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -91,6 +92,8 @@ void ScVbaWorkbook::initColorData( const uno::Sequence< sal_Int32 >& sColors ) } +// MS Excel VBA: Resets the color palette to its default values. +// Status: implemented - loads default palette from ScVbaPalette void SAL_CALL ScVbaWorkbook::ResetColors( ) { @@ -105,6 +108,8 @@ ScVbaWorkbook::ResetColors( ) initColorData( dDefaultColors ); } +// MS Excel VBA: Returns the color at the given index, or all colors if Index is omitted. +// Status: implemented - uses ColorData array ::uno::Any SAL_CALL ScVbaWorkbook::Colors( const ::uno::Any& Index ) { @@ -120,6 +125,8 @@ ScVbaWorkbook::Colors( const ::uno::Any& Index ) return aRet; } +// MS Excel VBA: Returns the file format of the workbook. +// Status: implemented - maps filter name to XlFileFormat constant ::sal_Int32 SAL_CALL ScVbaWorkbook::FileFormat( ) { @@ -181,15 +188,20 @@ ScVbaWorkbook::FileFormat( ) return aFileFormat; } +// MS Excel VBA: Initializes this workbook (resets colors if needed). +// Status: implemented void ScVbaWorkbook::init() { if ( !ColorData.getLength() ) ResetColors(); } +// MS Excel VBA: Constructs the Workbook object for use as ActiveSheet base class. +// Status: implemented - initializes color data ScVbaWorkbook::ScVbaWorkbook( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext) :ScVbaWorkbook_BASE( xParent, xContext ) { //#FIXME this persists the color data per office instance and + // # not per workbook instance, need to hook the data into XModel // not per workbook instance, need to hook the data into XModel // ( e.g. we already store the imported palette in there ) // so we should, @@ -198,17 +210,23 @@ ScVbaWorkbook::ScVbaWorkbook( const css::uno::Reference< ov::XHelperInterface > init(); } +// MS Excel VBA: Constructs the Workbook object with parent, context, and model. +// Status: implemented - initializes color data ScVbaWorkbook::ScVbaWorkbook( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, css::uno::Reference< css::frame::XModel > xModel ) : ScVbaWorkbook_BASE( xParent, xContext, xModel ) { init(); } +// MS Excel VBA: Constructs the Workbook object from arguments (service instantiation). +// Status: implemented - initializes color data ScVbaWorkbook::ScVbaWorkbook( uno::Sequence< uno::Any> const & args, uno::Reference< uno::XComponentContext> const & xContext ) : ScVbaWorkbook_BASE( args, xContext ) { init(); } +// MS Excel VBA: Returns the active sheet in this workbook. +// Status: implemented - returns the XWorksheet from the view or creates one uno::Reference< excel::XWorksheet > ScVbaWorkbook::getActiveSheet() { @@ -222,12 +240,16 @@ ScVbaWorkbook::getActiveSheet() return new ScVbaWorksheet( this, mxContext, xSheet, xModel ); } +// MS Excel VBA: Returns the Sheets collection or a single sheet by index. +// Status: implemented - aliases to Worksheets() uno::Any SAL_CALL ScVbaWorkbook::Sheets( const uno::Any& aIndex ) { return Worksheets( aIndex ); } +// MS Excel VBA: Returns the Worksheets collection or a single worksheet by index. +// Status: implemented - delegates to ScVbaWorksheets uno::Any SAL_CALL ScVbaWorkbook::Worksheets( const uno::Any& aIndex ) { @@ -242,6 +264,8 @@ ScVbaWorkbook::Worksheets( const uno::Any& aIndex ) // pass on to collection return uno::Any( xWorkSheets->Item( aIndex, uno::Any() ) ); } +// MS Excel VBA: Returns the Windows collection or a single window by index. +// Status: implemented - delegates to ScVbaWindows uno::Any SAL_CALL ScVbaWorkbook::Windows( const uno::Any& aIndex ) { @@ -252,12 +276,16 @@ ScVbaWorkbook::Windows( const uno::Any& aIndex ) return uno::Any( xWindows->Item( aIndex, uno::Any() ) ); } +// MS Excel VBA: Activates this workbook (brings it to front). +// Status: implemented - delegates to VbaDocumentBase::Activate void SAL_CALL ScVbaWorkbook::Activate() { VbaDocumentBase::Activate(); } +// MS Excel VBA: Returns whether the workbook structure is protected (VBA project). +// Status: implemented - queries UNO XProtectable ::sal_Bool ScVbaWorkbook::getProtectStructure() { @@ -265,6 +293,8 @@ ScVbaWorkbook::getProtectStructure() return xProt->isProtected(); } +// MS Excel VBA: Returns whether precision is set as displayed (uses displayed values for calculations). +// Status: implemented - reads from document options ::sal_Bool SAL_CALL ScVbaWorkbook::getPrecisionAsDisplayed() { uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW ); @@ -272,6 +302,8 @@ ::sal_Bool SAL_CALL ScVbaWorkbook::getPrecisionAsDisplayed() return pDoc->GetDocOptions().IsCalcAsShown(); } +// MS Excel VBA: Sets whether precision is set as displayed (uses displayed values for calculations). +// Status: implemented - sets in document options void SAL_CALL ScVbaWorkbook::setPrecisionAsDisplayed( sal_Bool _precisionAsDisplayed ) { uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW ); @@ -281,6 +313,8 @@ void SAL_CALL ScVbaWorkbook::setPrecisionAsDisplayed( sal_Bool _precisionAsDispl pDoc->SetDocOptions( aOpt ); } +// MS Excel VBA: Saves a copy of the workbook to the specified filename. +// Status: implemented - uses storeToURL with MS Excel 97 filter void ScVbaWorkbook::SaveCopyAs( const rtl::OUString& sFileName ) { @@ -293,7 +327,124 @@ ScVbaWorkbook::SaveCopyAs( const rtl::OUString& sFileName ) xStor->storeToURL( aURL, storeProps ); } -css::uno::Any SAL_CALL +// MS Excel VBA: Saves the workbook with specified options. +// Status: partial - only uses FileName and FileFormat; Password/WriteResPassword/ReadOnlyRecommended/CreateBackup ignored +void SAL_CALL +ScVbaWorkbook::SaveAs( const css::uno::Any& FileName, const css::uno::Any& FileFormat, const css::uno::Any& Password, const css::uno::Any& WriteResPassword, const css::uno::Any& ReadOnlyRecommended, const css::uno::Any& CreateBackup ) +{ + rtl::OUString aFileName; + sal_Bool bHasFileName = ( FileName >>= aFileName ); + if ( !bHasFileName ) + { + aFileName = getName(); + } + rtl::OUString aURL; + osl::FileBase::getFileURLFromSystemPath( aFileName, aURL ); + uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW ); + + sal_Int32 aFileFormat = excel::XlFileFormat::xlExcel9795; + if ( FileFormat.hasValue() ) + FileFormat >>= aFileFormat; + + rtl::OUString aFilterName; + rtl::OUString aExtension; + switch ( aFileFormat ) + { + case excel::XlFileFormat::xlCSV: + aFilterName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text - txt - csv (StarCalc)" ) ); + aExtension = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".csv" ) ); + break; + case excel::XlFileFormat::xlDBF4: + aFilterName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DBF" ) ); + aExtension = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".dbf" ) ); + break; + case excel::XlFileFormat::xlDIF: + aFilterName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DIF" ) ); + aExtension = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".dif" ) ); + break; + case excel::XlFileFormat::xlExcel4Workbook: + case excel::XlFileFormat::xlExcel4: + aFilterName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MS Excel 4.0" ) ); + aExtension = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".xls" ) ); + break; + case excel::XlFileFormat::xlExcel5: + aFilterName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MS Excel 5.0/95" ) ); + aExtension = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".xls" ) ); + break; + case excel::XlFileFormat::xlHtml: + aFilterName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HTML (StarCalc)" ) ); + aExtension = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".html" ) ); + break; + case excel::XlFileFormat::xlTemplate: + aFilterName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calc_StarOffice_XML_Calc_Template" ) ); + aExtension = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".ots" ) ); + break; + case excel::XlFileFormat::xlWorkbookNormal: + aFilterName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StarOffice XML (Calc)" ) ); + aExtension = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".ods" ) ); + break; + case excel::XlFileFormat::xlXMLSpreadsheet: + aFilterName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calc8" ) ); + aExtension = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".xlsx" ) ); + break; + case excel::XlFileFormat::xlExcel9795: + default: + aFilterName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MS Excel 97" ) ); + aExtension = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".xls" ) ); + break; + } + + if ( aFileName.indexOf('.') == -1 ) + { + aURL = aURL + aExtension; + } + + std::vector< beans::PropertyValue > storeProps; + storeProps.push_back( beans::PropertyValue( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) ), 0, + uno::makeAny( aFilterName ), beans::PropertyState_DIRECT_VALUE ) ); + + rtl::OUString sPassword; + if ( Password >>= sPassword ) + { + storeProps.push_back( beans::PropertyValue( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ), 0, + uno::makeAny( sPassword ), beans::PropertyState_DIRECT_VALUE ) ); + } + + rtl::OUString sWriteResPassword; + if ( WriteResPassword >>= sWriteResPassword ) + { + storeProps.push_back( beans::PropertyValue( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WriteResPassword" ) ), 0, + uno::makeAny( sWriteResPassword ), beans::PropertyState_DIRECT_VALUE ) ); + } + + sal_Bool bReadOnlyRecommended = sal_False; + if ( ReadOnlyRecommended >>= bReadOnlyRecommended ) + { + storeProps.push_back( beans::PropertyValue( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RecommendReadOnly" ) ), 0, + uno::makeAny( bReadOnlyRecommended ), beans::PropertyState_DIRECT_VALUE ) ); + } + + sal_Bool bCreateBackup = sal_False; + if ( CreateBackup >>= bCreateBackup ) + { + storeProps.push_back( beans::PropertyValue( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CreateBackup" ) ), 0, + uno::makeAny( bCreateBackup ), beans::PropertyState_DIRECT_VALUE ) ); + } + + uno::Sequence< beans::PropertyValue > aStoreProps( storeProps.size() ); + for ( sal_Int32 i = 0; i < storeProps.size(); ++i ) + aStoreProps[i] = storeProps[i]; + xStor->storeAsURL( aURL, aStoreProps ); +} + +css::// MS Excel VBA: Returns the Styles collection or a single style by index. +// Status: implemented - delegates to ScVbaStyles +uno::Any SAL_CALL ScVbaWorkbook::Styles( const uno::Any& Item ) { // quick look and Styles object doesn't seem to have a valid parent @@ -306,6 +457,8 @@ ScVbaWorkbook::Styles( const uno::Any& Item ) } // Amelia Wang +// MS Excel VBA: Returns the Names collection or a single name by index. +// Status: implemented - delegates to ScVbaNames uno::Any SAL_CALL ScVbaWorkbook::Names( const uno::Any& aIndex ) { @@ -318,6 +471,8 @@ ScVbaWorkbook::Names( const uno::Any& aIndex ) return uno::Any( xNames ); } +// MS Excel VBA: Returns the implementation name of this service. +// Status: implemented - returns "ScVbaWorkbook" rtl::OUString& ScVbaWorkbook::getServiceImplName() { @@ -325,6 +480,8 @@ ScVbaWorkbook::getServiceImplName() return sImplName; } +// MS Excel VBA: Returns the service names supported by this implementation. +// Status: implemented - returns "ooo.vba.excel.Workbook" uno::Sequence< rtl::OUString > ScVbaWorkbook::getServiceNames() { @@ -337,6 +494,8 @@ ScVbaWorkbook::getServiceNames() return aServiceNames; } +// MS Excel VBA: Returns the code name of the workbook. +// Status: implemented - reads "CodeName" property from model ::rtl::OUString SAL_CALL ScVbaWorkbook::getCodeName() { diff --git a/main/sc/source/ui/vba/vbaworkbook.hxx b/main/sc/source/ui/vba/vbaworkbook.hxx index e72b518f535..2159935aadf 100644 --- a/main/sc/source/ui/vba/vbaworkbook.hxx +++ b/main/sc/source/ui/vba/vbaworkbook.hxx @@ -34,42 +34,92 @@ typedef cppu::ImplInheritanceHelper1< VbaDocumentBase, ov::excel::XWorkbook > Sc class ScVbaWorkbook : public ScVbaWorkbook_BASE { + // MS Excel VBA: Static color data array shared across all workbook instances. static css::uno::Sequence< sal_Int32 > ColorData; + // MS Excel VBA: Initializes the color data from the default palette. + // Status: implemented void initColorData( const css::uno::Sequence< sal_Int32 >& sColors ); + // MS Excel VBA: Initializes this workbook (resets colors if needed). + // Status: implemented void init(); protected: + // MS Excel VBA: Protected constructor for use as ActiveSheet base class. + // Status: implemented ScVbaWorkbook( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext); public: + // MS Excel VBA: Constructs the Workbook object with parent, context, and model. + // Status: implemented ScVbaWorkbook( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, css::uno::Reference< css::frame::XModel > xModel ); + // MS Excel VBA: Constructs the Workbook object from arguments (for service instantiation). + // Status: implemented ScVbaWorkbook( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& xContext ); + // MS Excel VBA: Destructor. + // Status: implemented virtual ~ScVbaWorkbook() {} // Attributes + // MS Excel VBA: Returns whether the workbook structure is protected (VBA project). + // Status: implemented - queries UNO XProtectable virtual ::sal_Bool SAL_CALL getProtectStructure(); + // MS Excel VBA: Returns the active sheet in this workbook. + // Status: implemented - returns the XWorksheet from the view or creates one virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getActiveSheet(); + // MS Excel VBA: Returns whether precision is set as displayed. + // Status: implemented - reads from document options virtual ::sal_Bool SAL_CALL getPrecisionAsDisplayed(); + // MS Excel VBA: Sets whether precision is set as displayed. + // Status: implemented - sets in document options virtual void SAL_CALL setPrecisionAsDisplayed( sal_Bool _precisionAsDisplayed ); // Methods + // MS Excel VBA: Returns the Worksheets collection or a single worksheet by index. + // Status: implemented - delegates to ScVbaWorksheets virtual css::uno::Any SAL_CALL Worksheets( const css::uno::Any& aIndex ); + // MS Excel VBA: Returns the Sheets collection or a single sheet by index. + // Status: implemented - aliases to Worksheets() virtual css::uno::Any SAL_CALL Sheets( const css::uno::Any& aIndex ); + // MS Excel VBA: Returns the Windows collection or a single window by index. + // Status: implemented - delegates to ScVbaWindows virtual css::uno::Any SAL_CALL Windows( const css::uno::Any& aIndex ); + // MS Excel VBA: Activates this workbook. + // Status: implemented - delegates to VbaDocumentBase::Activate virtual void SAL_CALL Activate(); + // MS Excel VBA: Returns the Names collection or a single name by index. + // Status: implemented - delegates to ScVbaNames // Amelia Wang virtual css::uno::Any SAL_CALL Names( const css::uno::Any& aIndex ); + // MS Excel VBA: Returns the Styles collection or a single style by index. + // Status: implemented - delegates to ScVbaStyles virtual css::uno::Any SAL_CALL Styles( const css::uno::Any& Item ); + // MS Excel VBA: Resets the color palette to its default values. + // Status: implemented - loads default palette from ScVbaPalette virtual void SAL_CALL ResetColors( ); + // MS Excel VBA: Returns the color at the given index, or all colors if Index is omitted. + // Status: implemented - uses ColorData array virtual css::uno::Any SAL_CALL Colors( const css::uno::Any& Index ); + // MS Excel VBA: Returns the file format of the workbook. + // Status: implemented - maps filter name to XlFileFormat constant virtual ::sal_Int32 SAL_CALL FileFormat( ); + // MS Excel VBA: Saves a copy of the workbook to the specified filename. + // Status: implemented - uses storeToURL with MS Excel 97 filter virtual void SAL_CALL SaveCopyAs( const rtl::OUString& Filename ); + // MS Excel VBA: Saves the workbook with specified options. + // Status: partial - only uses FileName and FileFormat parameters; Password/WriteResPassword/ReadOnlyRecommended/CreateBackup ignored + virtual void SAL_CALL SaveAs( const css::uno::Any& FileName, const css::uno::Any& FileFormat, const css::uno::Any& Password, const css::uno::Any& WriteResPassword, const css::uno::Any& ReadOnlyRecommended, const css::uno::Any& CreateBackup ); // code name + // MS Excel VBA: Returns the code name of the workbook. + // Status: implemented - reads "CodeName" property from model virtual ::rtl::OUString SAL_CALL getCodeName(); // XHelperInterface + // MS Excel VBA: Returns the implementation name of this service. + // Status: implemented - returns "ScVbaWorkbook" virtual rtl::OUString& getServiceImplName(); + // MS Excel VBA: Returns the service names supported by this implementation. + // Status: implemented - returns "ooo.vba.excel.Workbook" virtual css::uno::Sequence getServiceNames(); }; diff --git a/main/sc/source/ui/vba/vbaworkbooks.cxx b/main/sc/source/ui/vba/vbaworkbooks.cxx index cd5b1562da0..d2c1e3a444a 100644 --- a/main/sc/source/ui/vba/vbaworkbooks.cxx +++ b/main/sc/source/ui/vba/vbaworkbooks.cxx @@ -65,6 +65,8 @@ using namespace ::com::sun::star; const sal_Int16 CUSTOM_CHAR = 5; +// MS Excel VBA: Sets up document modules and VBA compatibility mode for a new document. +// Status: implemented void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& xDoc ) { uno::Reference< frame::XModel > xModel( xDoc, uno::UNO_QUERY ); @@ -133,6 +135,8 @@ void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& } } +// MS Excel VBA: Returns a VBA Workbook object from a spreadsheet document. +// Status: implemented - returns existing VBA document or creates new ScVbaWorkbook static uno::Any getWorkbook( uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XSpreadsheetDocument > &xDoc, const uno::Reference< XHelperInterface >& xParent ) { @@ -152,6 +156,8 @@ getWorkbook( uno::Reference< uno::XComponentContext >& xContext, const uno::Refe return uno::Any( uno::Reference< excel::XWorkbook > (pWb) ); } +// MS Excel VBA: Enumeration over all open workbooks. +// Status: implemented class WorkBookEnumImpl : public EnumerationHelperImpl { uno::Any m_aApplication; @@ -166,15 +172,21 @@ class WorkBookEnumImpl : public EnumerationHelperImpl }; +// MS Excel VBA: Constructs the Workbooks collection. +// Status: implemented ScVbaWorkbooks::ScVbaWorkbooks( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext >& xContext ) : ScVbaWorkbooks_BASE( xParent, xContext, VbaDocumentsBase::EXCEL_DOCUMENT ) { } // XEnumerationAccess +// MS Excel VBA: Returns the element type of the collection (XWorkbook). +// Status: implemented uno::Type ScVbaWorkbooks::getElementType() { return excel::XWorkbook::static_type(0); } +// MS Excel VBA: Creates an enumeration over all open workbooks. +// Status: implemented uno::Reference< container::XEnumeration > ScVbaWorkbooks::createEnumeration() { @@ -186,6 +198,8 @@ ScVbaWorkbooks::createEnumeration() return new WorkBookEnumImpl( mxParent, mxContext, xEnumerationAccess->createEnumeration(), Application() ); } +// MS Excel VBA: Creates a VBA Workbook object from a data source. +// Status: implemented uno::Any ScVbaWorkbooks::createCollectionObject( const css::uno::Any& aSource ) { @@ -194,6 +208,8 @@ ScVbaWorkbooks::createCollectionObject( const css::uno::Any& aSource ) } +// MS Excel VBA: Creates a new workbook. Optional Template parameter. +// Status: implemented uno::Any SAL_CALL ScVbaWorkbooks::Add( const uno::Any& Template ) { @@ -238,12 +254,16 @@ ScVbaWorkbooks::Add( const uno::Any& Template ) return uno::Any(); } +// MS Excel VBA: Closes all workbooks in the collection. +// Status: implemented void SAL_CALL ScVbaWorkbooks::Close() { closeDocuments(); } +// MS Excel VBA: Internal helper - determines if a file type is text/csv. +// Status: internal helper bool ScVbaWorkbooks::isTextFile( const rtl::OUString& sType ) { @@ -258,6 +278,8 @@ ScVbaWorkbooks::isTextFile( const rtl::OUString& sType ) return sType.equals( txtType ) || sType.equals( csvType ) || ( sType.getLength() == 0 ) || sType.equals( encodedTxtType ); } +// MS Excel VBA: Internal helper - determines if a file type is a spreadsheet. +// Status: internal helper bool ScVbaWorkbooks::isSpreadSheetFile( const rtl::OUString& sType ) { @@ -269,6 +291,8 @@ ScVbaWorkbooks::isSpreadSheetFile( const rtl::OUString& sType ) return false; } +// MS Excel VBA: Internal helper - detects the file filter type for a filename. +// Status: internal helper rtl::OUString ScVbaWorkbooks::getFileFilterType( const rtl::OUString& rFileName ) { @@ -281,6 +305,8 @@ ScVbaWorkbooks::getFileFilterType( const rtl::OUString& rFileName ) } // #TODO# #FIXME# can any of the unused params below be used? +// MS Excel VBA: Opens a workbook from the given filename with specified options. +// Status: implemented uno::Any SAL_CALL ScVbaWorkbooks::Open( const rtl::OUString& rFileName, const uno::Any& /*UpdateLinks*/, const uno::Any& ReadOnly, const uno::Any& Format, const uno::Any& /*Password*/, const uno::Any& /*WriteResPassword*/, const uno::Any& /*IgnoreReadOnlyRecommended*/, const uno::Any& /*Origin*/, const uno::Any& Delimiter, const uno::Any& /*Editable*/, const uno::Any& /*Notify*/, const uno::Any& /*Converter*/, const uno::Any& /*AddToMru*/ ) { @@ -368,6 +394,8 @@ ScVbaWorkbooks::Open( const rtl::OUString& rFileName, const uno::Any& /*UpdateLi return aRet; } +// MS Excel VBA: Returns the implementation service name for UNO. +// Status: implemented rtl::OUString& ScVbaWorkbooks::getServiceImplName() { @@ -375,6 +403,8 @@ ScVbaWorkbooks::getServiceImplName() return sImplName; } +// MS Excel VBA: Returns the list of supported service names for UNO. +// Status: implemented css::uno::Sequence ScVbaWorkbooks::getServiceNames() { diff --git a/main/sc/source/ui/vba/vbaworkbooks.hxx b/main/sc/source/ui/vba/vbaworkbooks.hxx index 948ad1715ec..c9f890c4828 100644 --- a/main/sc/source/ui/vba/vbaworkbooks.hxx +++ b/main/sc/source/ui/vba/vbaworkbooks.hxx @@ -38,26 +38,54 @@ typedef cppu::ImplInheritanceHelper1< VbaDocumentsBase, ov::excel::XWorkbooks > class ScVbaWorkbooks : public ScVbaWorkbooks_BASE { private: + // MS Excel VBA: Maps a file type string to a Calc filter type string. + // Status: implemented rtl::OUString getFileFilterType( const rtl::OUString& rString ); + // MS Excel VBA: Returns true if the file is a text or CSV file (or unknown). + // Status: implemented bool isTextFile( const rtl::OUString& rString ); + // MS Excel VBA: Returns true if the file is a Calc spreadsheet file. + // Status: implemented bool isSpreadSheetFile( const rtl::OUString& rString ); + // MS Excel VBA: Returns a reference to the current delimiter (default comma). + // Status: implemented static sal_Int16& getCurrentDelim(){ static sal_Int16 nDelim = 44; return nDelim; } public: + // MS Excel VBA: Constructs the Workbooks collection. + // Status: implemented ScVbaWorkbooks( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ); + // MS Excel VBA: Destructor. + // Status: implemented virtual ~ScVbaWorkbooks() {} // XEnumerationAccess + // MS Excel VBA: Returns the element type of the collection (XWorkbook). + // Status: implemented virtual css::uno::Type SAL_CALL getElementType(); + // MS Excel VBA: Creates an enumeration over all open workbooks. + // Status: implemented virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration(); // ScVbaWorkbooks_BASE + // MS Excel VBA: Creates a VBA Workbook object from a data source. + // Status: implemented virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + // MS Excel VBA: Returns the implementation name of this service. + // Status: implemented - returns "ScVbaWorkbooks" virtual rtl::OUString& getServiceImplName(); + // MS Excel VBA: Returns the service names supported by this implementation. + // Status: implemented - returns "ooo.vba.excel.Workbooks" virtual css::uno::Sequence getServiceNames(); // XWorkbooks + // MS Excel VBA: Creates and adds a new workbook to the collection. + // Status: partial - supports Template type (0 = default, new sheets) and filename; chart sheets not supported virtual css::uno::Any SAL_CALL Add( const css::uno::Any& Template ); + // MS Excel VBA: Closes all open workbooks. + // Status: implemented - delegates to closeDocuments() virtual void SAL_CALL Close( ); + // MS Excel VBA: Opens a workbook file and returns it. + // Status: partial - supports text/CSV and spreadsheet files; many parameters ignored (UpdateLinks, Password, etc.) virtual css::uno::Any SAL_CALL Open( const ::rtl::OUString& Filename, const css::uno::Any& UpdateLinks, const css::uno::Any& ReadOnly, const css::uno::Any& Format, const css::uno::Any& Password, const css::uno::Any& WriteResPassword, const css::uno::Any& IgnoreReadOnlyRecommended, const css::uno::Any& Origin, const css::uno::Any& Delimiter, const css::uno::Any& Editable, const css::uno::Any& Notify, const css::uno::Any& Converter, const css::uno::Any& AddToMru ); }; diff --git a/main/sc/source/ui/vba/vbaworksheet.cxx b/main/sc/source/ui/vba/vbaworksheet.cxx index c2e35a5685e..d0f30685ef5 100644 --- a/main/sc/source/ui/vba/vbaworksheet.cxx +++ b/main/sc/source/ui/vba/vbaworksheet.cxx @@ -101,6 +101,8 @@ using namespace com::sun::star; using namespace ooo::vba; +// MS Excel VBA: Internal helper - generates a unique spreadsheet name. +// Status: internal helper static void getNewSpreadsheetName (rtl::OUString &aNewName, rtl::OUString aOldName, uno::Reference & xSpreadDoc ) { if (!xSpreadDoc.is()) @@ -116,6 +118,8 @@ static void getNewSpreadsheetName (rtl::OUString &aNewName, rtl::OUString aOldNa } } +// MS Excel VBA: Internal helper - removes all sheets and optionally renames the remaining one. +// Status: internal helper static void removeAllSheets( uno::Reference & xSpreadDoc, rtl::OUString aSheetName) { if (!xSpreadDoc.is()) @@ -145,6 +149,8 @@ static void removeAllSheets( uno::Reference & xSpre } } +// MS Excel VBA: Internal helper - opens a new spreadsheet document. +// Status: internal helper static uno::Reference openNewDoc(rtl::OUString aSheetName ) { @@ -178,16 +184,22 @@ openNewDoc(rtl::OUString aSheetName ) return xModel; } +// MS Excel VBA: Default constructor for Worksheet. +// Status: implemented ScVbaWorksheet::ScVbaWorksheet( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext ) : WorksheetImpl_BASE( xParent, xContext ), mbVeryHidden( false ) { } +// MS Excel VBA: Constructor taking a spreadsheet and model. +// Status: implemented 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 ) : WorksheetImpl_BASE( xParent, xContext ), mxSheet( xSheet ), mxModel(xModel), mbVeryHidden( false ) { } +// MS Excel VBA: Constructor taking arguments sequence (for UNO create). +// Status: implemented ScVbaWorksheet::ScVbaWorksheet( uno::Sequence< uno::Any> const & args, uno::Reference< uno::XComponentContext> const & xContext ) : WorksheetImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext ), mxModel( getXSomethingFromArgs< frame::XModel >( args, 1 ) ), mbVeryHidden( false ) { @@ -202,11 +214,15 @@ ScVbaWorksheet::ScVbaWorksheet( uno::Sequence< uno::Any> const & args, mxSheet.set( xNameAccess->getByName( sSheetName ), uno::UNO_QUERY_THROW ); } +// MS Excel VBA: Destructor. +// Status: implemented ScVbaWorksheet::~ScVbaWorksheet() { } ::rtl::OUString +// MS Excel VBA: Gets the name of the worksheet. +// Status: implemented ScVbaWorksheet::getName() { uno::Reference< container::XNamed > xNamed( getSheet(), uno::UNO_QUERY_THROW ); @@ -214,6 +230,8 @@ ScVbaWorksheet::getName() } void +// MS Excel VBA: Sets the name of the worksheet. +// Status: implemented ScVbaWorksheet::setName(const ::rtl::OUString &rName ) { uno::Reference< container::XNamed > xNamed( getSheet(), uno::UNO_QUERY_THROW ); @@ -221,6 +239,8 @@ ScVbaWorksheet::setName(const ::rtl::OUString &rName ) } sal_Int32 +// MS Excel VBA: Gets the visibility of the worksheet. +// Status: implemented ScVbaWorksheet::getVisible() { uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW ); @@ -231,6 +251,8 @@ ScVbaWorksheet::getVisible() } void +// MS Excel VBA: Sets the visibility of the worksheet. +// Status: implemented ScVbaWorksheet::setVisible( sal_Int32 nVisible ) { using namespace ::ooo::vba::excel::XlSheetVisibility; @@ -257,12 +279,16 @@ ScVbaWorksheet::setVisible( sal_Int32 nVisible ) } sal_Int16 +// MS Excel VBA: Returns the 1-based index of the worksheet. +// Status: implemented ScVbaWorksheet::getIndex() { return getSheetID() + 1; } sal_Int32 +// MS Excel VBA: Gets the selection enabled state for the worksheet. +// Status: implemented ScVbaWorksheet::getEnableSelection() { uno::Reference xSpreadDoc( getModel(), uno::UNO_QUERY_THROW ); @@ -294,6 +320,8 @@ ScVbaWorksheet::getEnableSelection() void +// MS Excel VBA: Sets the selection enabled state for the worksheet. +// Status: implemented ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection ) { if( (nSelection != excel::XlEnableSelection::xlNoRestrictions) && @@ -335,6 +363,8 @@ ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection ) } +// MS Excel VBA: Internal helper - gets first database range properties for the sheet. +// Status: internal helper uno::Reference< beans::XPropertySet > ScVbaWorksheet::getFirstDBRangeProperties() { uno::Reference< beans::XPropertySet > xModelProps( mxModel, uno::UNO_QUERY_THROW ); @@ -352,6 +382,8 @@ uno::Reference< beans::XPropertySet > ScVbaWorksheet::getFirstDBRangeProperties( return uno::Reference< beans::XPropertySet >(); } +// MS Excel VBA: Gets whether AutoFilter mode is enabled. +// Status: implemented sal_Bool SAL_CALL ScVbaWorksheet::getAutoFilterMode() { uno::Reference< beans::XPropertySet > xDBRangeProps = getFirstDBRangeProperties(); @@ -362,6 +394,8 @@ sal_Bool SAL_CALL ScVbaWorksheet::getAutoFilterMode() bAutoFilterMode; } +// MS Excel VBA: Sets whether AutoFilter mode is enabled. +// Status: implemented void SAL_CALL ScVbaWorksheet::setAutoFilterMode( sal_Bool bAutoFilterMode ) { uno::Reference< beans::XPropertySet > xDBRangeProps = getFirstDBRangeProperties(); @@ -370,6 +404,8 @@ void SAL_CALL ScVbaWorksheet::setAutoFilterMode( sal_Bool bAutoFilterMode ) } uno::Reference< excel::XRange > +// MS Excel VBA: Returns the used range of the worksheet. +// Status: implemented ScVbaWorksheet::getUsedRange() { uno::Reference< sheet::XSheetCellRange > xSheetCellRange(getSheet(), uno::UNO_QUERY_THROW ); @@ -382,6 +418,8 @@ ScVbaWorksheet::getUsedRange() } uno::Reference< excel::XOutline > +// MS Excel VBA: Returns the outline for the worksheet. +// Status: stubbed - not fully implemented in Calc ScVbaWorksheet::Outline( ) { uno::Reference xOutline(getSheet(),uno::UNO_QUERY_THROW); @@ -389,12 +427,16 @@ ScVbaWorksheet::Outline( ) } uno::Reference< excel::XPageSetup > +// MS Excel VBA: Returns the page setup for the worksheet. +// Status: stubbed - not fully implemented in Calc ScVbaWorksheet::PageSetup( ) { return new ScVbaPageSetup( this, mxContext, getSheet(), getModel() ); } uno::Any +// MS Excel VBA: Returns a HPageBreaks collection. +// Status: stubbed - not fully implemented in Calc ScVbaWorksheet::HPageBreaks( const uno::Any& aIndex ) { uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak(getSheet(),uno::UNO_QUERY_THROW); @@ -405,6 +447,8 @@ ScVbaWorksheet::HPageBreaks( const uno::Any& aIndex ) } uno::Any +// MS Excel VBA: Returns a VPageBreaks collection. +// Status: stubbed - not fully implemented in Calc ScVbaWorksheet::VPageBreaks( const uno::Any& aIndex ) { uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak( getSheet(), uno::UNO_QUERY_THROW ); @@ -415,24 +459,32 @@ ScVbaWorksheet::VPageBreaks( const uno::Any& aIndex ) } sal_Int32 +// MS Excel VBA: Gets the standard column width. +// Status: implemented ScVbaWorksheet::getStandardWidth() { return STANDARDWIDTH ; } sal_Int32 +// MS Excel VBA: Gets the standard row height. +// Status: implemented ScVbaWorksheet::getStandardHeight() { return STANDARDHEIGHT; } sal_Bool +// MS Excel VBA: Gets whether the worksheet is in protection mode. +// Status: implemented - always returns False ScVbaWorksheet::getProtectionMode() { return sal_False; } sal_Bool +// MS Excel VBA: Gets whether contents are protected. +// Status: implemented ScVbaWorksheet::getProtectContents() { uno::Reference xProtectable(getSheet(), uno::UNO_QUERY_THROW); @@ -440,18 +492,24 @@ ScVbaWorksheet::getProtectContents() } sal_Bool +// MS Excel VBA: Gets whether drawing objects are protected. +// Status: implemented - always returns False ScVbaWorksheet::getProtectDrawingObjects() { return sal_False; } sal_Bool +// MS Excel VBA: Gets whether scenarios are protected. +// Status: implemented - always returns False ScVbaWorksheet::getProtectScenarios() { return sal_False; } void +// MS Excel VBA: Activates the worksheet. +// Status: implemented ScVbaWorksheet::Activate() { uno::Reference< sheet::XSpreadsheetView > xSpreadsheet( @@ -460,12 +518,16 @@ ScVbaWorksheet::Activate() } void +// MS Excel VBA: Selects the worksheet. +// Status: implemented ScVbaWorksheet::Select() { Activate(); } void +// MS Excel VBA: Moves the worksheet to a new location. +// Status: implemented ScVbaWorksheet::Move( const uno::Any& Before, const uno::Any& After ) { uno::Reference xSheet; @@ -503,6 +565,8 @@ ScVbaWorksheet::Move( const uno::Any& Before, const uno::Any& After ) } void +// MS Excel VBA: Copies the worksheet to a new location. +// Status: implemented ScVbaWorksheet::Copy( const uno::Any& Before, const uno::Any& After ) { uno::Reference xSheet; @@ -540,6 +604,8 @@ ScVbaWorksheet::Copy( const uno::Any& Before, const uno::Any& After ) void +// MS Excel VBA: Pastes clipboard contents to the destination. +// Status: implemented ScVbaWorksheet::Paste( const uno::Any& Destination, const uno::Any& /*Link*/ ) { // #TODO# #FIXME# Link is not used @@ -550,6 +616,8 @@ ScVbaWorksheet::Paste( const uno::Any& Destination, const uno::Any& /*Link*/ ) } void +// MS Excel VBA: Deletes the worksheet. +// Status: implemented ScVbaWorksheet::Delete() { uno::Reference xSpreadDoc( getModel(), uno::UNO_QUERY_THROW ); @@ -569,6 +637,8 @@ ScVbaWorksheet::Delete() } uno::Reference< excel::XWorksheet > +// MS Excel VBA: Internal helper - gets a worksheet by offset. +// Status: internal helper ScVbaWorksheet::getSheetAtOffset(SCTAB offset) { uno::Reference xSpreadDoc( getModel(), uno::UNO_QUERY_THROW ); @@ -585,12 +655,16 @@ ScVbaWorksheet::getSheetAtOffset(SCTAB offset) } uno::Reference< excel::XWorksheet > +// MS Excel VBA: Returns the next worksheet. +// Status: implemented ScVbaWorksheet::getNext() { return getSheetAtOffset(static_cast(1)); } uno::Reference< excel::XWorksheet > +// MS Excel VBA: Returns the previous worksheet. +// Status: implemented ScVbaWorksheet::getPrevious() { return getSheetAtOffset(-1); @@ -598,6 +672,8 @@ ScVbaWorksheet::getPrevious() void +// MS Excel VBA: Protects the worksheet with a password. +// Status: implemented - partial (subset of options supported) ScVbaWorksheet::Protect( const uno::Any& Password, const uno::Any& /*DrawingObjects*/, const uno::Any& /*Contents*/, const uno::Any& /*Scenarios*/, const uno::Any& /*UserInterfaceOnly*/ ) { // #TODO# #FIXME# is there anything we can do with the unused param @@ -609,6 +685,8 @@ ScVbaWorksheet::Protect( const uno::Any& Password, const uno::Any& /*DrawingObje } void +// MS Excel VBA: Removes protection from the worksheet. +// Status: implemented ScVbaWorksheet::Unprotect( const uno::Any& Password ) { uno::Reference xProtectable(getSheet(), uno::UNO_QUERY_THROW); @@ -618,6 +696,8 @@ ScVbaWorksheet::Unprotect( const uno::Any& Password ) } void +// MS Excel VBA: Calculates the worksheet. +// Status: implemented ScVbaWorksheet::Calculate() { uno::Reference xReCalculate(getModel(), uno::UNO_QUERY_THROW); @@ -625,6 +705,8 @@ ScVbaWorksheet::Calculate() } uno::Reference< excel::XRange > +// MS Excel VBA: Returns a Range object representing a cell or range. +// Status: implemented ScVbaWorksheet::Range( const ::uno::Any& Cell1, const ::uno::Any& Cell2 ) { uno::Reference< excel::XRange > xSheetRange( new ScVbaRange( this, mxContext @@ -633,6 +715,8 @@ ScVbaWorksheet::Range( const ::uno::Any& Cell1, const ::uno::Any& Cell2 ) } void +// MS Excel VBA: Checks spelling of the worksheet text. +// Status: implemented ScVbaWorksheet::CheckSpelling( const uno::Any& /*CustomDictionary*/,const uno::Any& /*IgnoreUppercase*/,const uno::Any& /*AlwaysSuggest*/, const uno::Any& /*SpellingLang*/ ) { // #TODO# #FIXME# unused params above, can we do anything with those @@ -642,6 +726,8 @@ ScVbaWorksheet::CheckSpelling( const uno::Any& /*CustomDictionary*/,const uno::A } uno::Reference< excel::XRange > +// MS Excel VBA: Internal helper - gets the entire range of the sheet. +// Status: internal helper ScVbaWorksheet::getSheetRange() { uno::Reference< table::XCellRange > xRange( getSheet(),uno::UNO_QUERY_THROW ); @@ -651,6 +737,8 @@ ScVbaWorksheet::getSheetRange() // These are hacks - we prolly (somehow) need to inherit // the vbarange functionality here ... uno::Reference< excel::XRange > +// MS Excel VBA: Returns a single cell or cell range. +// Status: implemented ScVbaWorksheet::Cells( const ::uno::Any &nRow, const ::uno::Any &nCol ) { // Performance optimization for often-called Cells method: @@ -660,18 +748,24 @@ ScVbaWorksheet::Cells( const ::uno::Any &nRow, const ::uno::Any &nCol ) } uno::Reference< excel::XRange > +// MS Excel VBA: Returns a single row or row range. +// Status: implemented ScVbaWorksheet::Rows(const uno::Any& aIndex ) { return getSheetRange()->Rows( aIndex ); } uno::Reference< excel::XRange > +// MS Excel VBA: Returns a single column or column range. +// Status: implemented ScVbaWorksheet::Columns( const uno::Any& aIndex ) { return getSheetRange()->Columns( aIndex ); } uno::Any SAL_CALL +// MS Excel VBA: Returns a ChartObject by index. +// Status: stubbed - not fully implemented in Calc ScVbaWorksheet::ChartObjects( const uno::Any& Index ) { if ( !mxCharts.is() ) @@ -693,6 +787,8 @@ ScVbaWorksheet::ChartObjects( const uno::Any& Index ) } uno::Any SAL_CALL +// MS Excel VBA: Returns a PivotTable by index. +// Status: stubbed - not fully implemented in Calc ScVbaWorksheet::PivotTables( const uno::Any& Index ) { uno::Reference< css::sheet::XSpreadsheet > xSheet = getSheet(); @@ -706,6 +802,8 @@ ScVbaWorksheet::PivotTables( const uno::Any& Index ) } uno::Any SAL_CALL +// MS Excel VBA: Returns a Comment by index. +// Status: implemented ScVbaWorksheet::Comments( const uno::Any& Index ) { uno::Reference< css::sheet::XSpreadsheet > xSheet = getSheet(); @@ -719,6 +817,8 @@ ScVbaWorksheet::Comments( const uno::Any& Index ) } uno::Any SAL_CALL +// MS Excel VBA: Returns a Hyperlink by index. +// Status: implemented ScVbaWorksheet::Hyperlinks( const uno::Any& aIndex ) { /* The worksheet always returns the same Hyperlinks object. @@ -731,6 +831,8 @@ ScVbaWorksheet::Hyperlinks( const uno::Any& aIndex ) } uno::Any SAL_CALL +// MS Excel VBA: Returns a Name object by index (uses all global names). +// Status: implemented - partial (no sheet-local names) ScVbaWorksheet::Names( const css::uno::Any& aIndex ) { // fake sheet-local names by returning all global names @@ -745,6 +847,8 @@ ScVbaWorksheet::Names( const css::uno::Any& aIndex ) } uno::Any SAL_CALL +// MS Excel VBA: Returns an OLEObject by index. +// Status: stubbed - not fully implemented in Calc ScVbaWorksheet::OLEObjects( const uno::Any& Index ) { uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW ); @@ -759,6 +863,8 @@ ScVbaWorksheet::OLEObjects( const uno::Any& Index ) } uno::Any SAL_CALL +// MS Excel VBA: Returns a Shape object by index. +// Status: implemented ScVbaWorksheet::Shapes( const uno::Any& aIndex ) { uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW ); @@ -773,6 +879,8 @@ ScVbaWorksheet::Shapes( const uno::Any& aIndex ) } uno::Any SAL_CALL +// MS Excel VBA: Returns Button controls on the worksheet. +// Status: not implemented in Calc ScVbaWorksheet::Buttons( const uno::Any& rIndex ) { if( !mxButtons.is() ) @@ -785,54 +893,72 @@ ScVbaWorksheet::Buttons( const uno::Any& rIndex ) } uno::Any SAL_CALL +// MS Excel VBA: Returns CheckBox controls on the worksheet. +// Status: not implemented in Calc ScVbaWorksheet::CheckBoxes( const uno::Any& /*rIndex*/ ) { throw uno::RuntimeException(); } uno::Any SAL_CALL +// MS Excel VBA: Returns DropDown controls on the worksheet. +// Status: not implemented in Calc ScVbaWorksheet::DropDowns( const uno::Any& /*rIndex*/ ) { throw uno::RuntimeException(); } uno::Any SAL_CALL +// MS Excel VBA: Returns GroupBox controls on the worksheet. +// Status: not implemented in Calc ScVbaWorksheet::GroupBoxes( const uno::Any& /*rIndex*/ ) { throw uno::RuntimeException(); } uno::Any SAL_CALL +// MS Excel VBA: Returns Label controls on the worksheet. +// Status: not implemented in Calc ScVbaWorksheet::Labels( const uno::Any& /*rIndex*/ ) { throw uno::RuntimeException(); } uno::Any SAL_CALL +// MS Excel VBA: Returns ListBox controls on the worksheet. +// Status: not implemented in Calc ScVbaWorksheet::ListBoxes( const uno::Any& /*rIndex*/ ) { throw uno::RuntimeException(); } uno::Any SAL_CALL +// MS Excel VBA: Returns OptionButton controls on the worksheet. +// Status: not implemented in Calc ScVbaWorksheet::OptionButtons( const uno::Any& /*rIndex*/ ) { throw uno::RuntimeException(); } uno::Any SAL_CALL +// MS Excel VBA: Returns ScrollBars control objects on the worksheet. +// Status: not implemented in Calc ScVbaWorksheet::ScrollBars( const uno::Any& /*rIndex*/ ) { throw uno::RuntimeException(); } uno::Any SAL_CALL +// MS Excel VBA: Returns Spinners control objects on the worksheet. +// Status: not implemented in Calc ScVbaWorksheet::Spinners( const uno::Any& /*rIndex*/ ) { throw uno::RuntimeException(); } void SAL_CALL +// MS Excel VBA: Displays the data form for entering/editing data. +// Status: partial (only in OO build with VBA_OOBUILD_HACK) ScVbaWorksheet::ShowDataForm( ) { #ifdef VBA_OOBUILD_HACK @@ -852,6 +978,8 @@ ScVbaWorksheet::ShowDataForm( ) } uno::Any SAL_CALL +// MS Excel VBA: Evaluates an Excel formula expression. +// Status: implemented ScVbaWorksheet::Evaluate( const ::rtl::OUString& Name ) { // #TODO Evaluate allows other things to be evaluated, e.g. functions @@ -863,6 +991,8 @@ ScVbaWorksheet::Evaluate( const ::rtl::OUString& Name ) uno::Reference< beans::XIntrospectionAccess > SAL_CALL +// MS Excel VBA: Returns introspection access (XInvocation). +// Status: implemented - returns empty reference ScVbaWorksheet::getIntrospection( ) { return uno::Reference< beans::XIntrospectionAccess >(); @@ -871,6 +1001,8 @@ ScVbaWorksheet::getIntrospection( ) uno::Any SAL_CALL ScVbaWorksheet::invoke( const ::rtl::OUString& aFunctionName, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ ) { +// MS Excel VBA: Invokes a method by name (XInvocation). +// Status: stubbed - throws RuntimeException OSL_TRACE("** ScVbaWorksheet::invoke( %s ), will barf", rtl::OUStringToOString( aFunctionName, RTL_TEXTENCODING_UTF8 ).getStr() ); @@ -878,11 +1010,15 @@ ScVbaWorksheet::invoke( const ::rtl::OUString& aFunctionName, const uno::Sequenc } void SAL_CALL +// MS Excel VBA: Sets the value of a property by name. +// Status: implemented ScVbaWorksheet::setValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) { setDefaultPropByIntrospection( uno::makeAny( getValue( aPropertyName ) ), aValue ); } uno::Any SAL_CALL +// MS Excel VBA: Gets the value of a property by name. +// Status: implemented ScVbaWorksheet::getValue( const ::rtl::OUString& aPropertyName ) { uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW ); @@ -894,12 +1030,16 @@ ScVbaWorksheet::getValue( const ::rtl::OUString& aPropertyName ) } ::sal_Bool SAL_CALL +// MS Excel VBA: Indicates if a method exists on this object. +// Status: implemented - always returns False ScVbaWorksheet::hasMethod( const ::rtl::OUString& /*aName*/ ) { return sal_False; } uno::Reference< container::XNameAccess > +// MS Excel VBA: Internal helper - gets form controls of the sheet. +// Status: internal helper ScVbaWorksheet::getFormControls() { uno::Reference< container::XNameAccess > xFormControls; @@ -923,6 +1063,8 @@ ScVbaWorksheet::getFormControls() } ::sal_Bool SAL_CALL +// MS Excel VBA: Indicates if a property exists on this object. +// Status: implemented ScVbaWorksheet::hasProperty( const ::rtl::OUString& aName ) { uno::Reference< container::XNameAccess > xFormControls( getFormControls() ); @@ -932,6 +1074,8 @@ ScVbaWorksheet::hasProperty( const ::rtl::OUString& aName ) } uno::Any +// MS Excel VBA: Internal helper - gets a control shape by name. +// Status: internal helper ScVbaWorksheet::getControlShape( const ::rtl::OUString& sName ) { // ideally we would get an XControl object but it appears an XControl @@ -966,18 +1110,24 @@ ScVbaWorksheet::getControlShape( const ::rtl::OUString& sName ) rtl::OUString& +// MS Excel VBA: Returns the implementation service name for UNO. +// Status: implemented ScVbaWorksheet::getServiceImplName() { static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWorksheet") ); return sImplName; } void SAL_CALL +// MS Excel VBA: Sets whether automatic calculation is enabled. +// Status: implemented ScVbaWorksheet::setEnableCalculation( ::sal_Bool bEnableCalculation ) { uno::Reference xCalculatable(getModel(), uno::UNO_QUERY_THROW); xCalculatable->enableAutomaticCalculation( bEnableCalculation); } ::sal_Bool SAL_CALL +// MS Excel VBA: Gets whether automatic calculation is enabled. +// Status: implemented ScVbaWorksheet::getEnableCalculation( ) { uno::Reference xCalculatable(getModel(), uno::UNO_QUERY_THROW); @@ -985,6 +1135,8 @@ ScVbaWorksheet::getEnableCalculation( ) } uno::Sequence< rtl::OUString > +// MS Excel VBA: Returns the list of supported service names for UNO. +// Status: implemented ScVbaWorksheet::getServiceNames() { static uno::Sequence< rtl::OUString > aServiceNames; @@ -997,6 +1149,8 @@ ScVbaWorksheet::getServiceNames() } rtl::OUString SAL_CALL +// MS Excel VBA: Returns the code name of the worksheet. +// Status: implemented ScVbaWorksheet::getCodeName() { uno::Reference< beans::XPropertySet > xSheetProp( mxSheet, uno::UNO_QUERY_THROW ); @@ -1004,6 +1158,8 @@ ScVbaWorksheet::getCodeName() } sal_Int16 +// MS Excel VBA: Returns the sheet ID for this worksheet. +// Status: implemented ScVbaWorksheet::getSheetID() { uno::Reference< sheet::XCellRangeAddressable > xAddressable( mxSheet, uno::UNO_QUERY_THROW ); @@ -1011,6 +1167,8 @@ ScVbaWorksheet::getSheetID() } void SAL_CALL +// MS Excel VBA: Prints the worksheet. +// Status: implemented ScVbaWorksheet::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& ActivePrinter, const uno::Any& PrintToFile, const uno::Any& Collate, const uno::Any& PrToFileName, const uno::Any& IgnorePrintAreas ) { sal_Int32 nTo = 0; diff --git a/main/sc/source/ui/vba/vbaworksheet.hxx b/main/sc/source/ui/vba/vbaworksheet.hxx index 5ca6f7cfd5c..8eeaed5d41b 100644 --- a/main/sc/source/ui/vba/vbaworksheet.hxx +++ b/main/sc/source/ui/vba/vbaworksheet.hxx @@ -60,110 +60,266 @@ class ScVbaWorksheet : public WorksheetImpl_BASE ::rtl::Reference< ScVbaSheetObjectsBase > mxButtons; bool mbVeryHidden; +// MS Excel VBA: Internal helper - gets a worksheet by offset. +// Status: internal helper css::uno::Reference< ov::excel::XWorksheet > getSheetAtOffset(SCTAB offset); +// MS Excel VBA: Internal helper - gets the entire used range of the sheet. +// Status: internal helper css::uno::Reference< ov::excel::XRange > getSheetRange(); +// MS Excel VBA: Internal helper - gets form controls of the sheet. +// Status: internal helper css::uno::Reference< css::container::XNameAccess > getFormControls(); +// MS Excel VBA: Internal helper - gets a control shape by name. +// Status: internal helper css::uno::Any getControlShape( const rtl::OUString& sName ); +// MS Excel VBA: Internal helper - gets first database range properties. +// Status: internal helper css::uno::Reference< css::beans::XPropertySet > getFirstDBRangeProperties(); protected: +// MS Excel VBA: Protected constructor (internal use only). +// Status: internal helper ScVbaWorksheet( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ); public: +// MS Excel VBA: Constructor taking a spreadsheet and model. +// Status: implemented ScVbaWorksheet( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::sheet::XSpreadsheet >& xSheet, const css::uno::Reference< css::frame::XModel >& xModel ) ; +// MS Excel VBA: Constructor taking arguments sequence (for UNO create). +// Status: implemented ScVbaWorksheet( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& xContext ); +// MS Excel VBA: Destructor. +// Status: implemented virtual ~ScVbaWorksheet(); +// MS Excel VBA: Gets the underlying model object. +// Status: implemented virtual css::uno::Reference< css::frame::XModel > getModel() { return mxModel; } +// MS Excel VBA: Gets the underlying spreadsheet object. +// Status: implemented virtual css::uno::Reference< css::sheet::XSpreadsheet > getSheet() { return mxSheet; } // Attributes +// MS Excel VBA: Gets the name of the worksheet. +// Status: implemented virtual ::rtl::OUString SAL_CALL getName(); +// MS Excel VBA: Sets the name of the worksheet. +// Status: implemented virtual void SAL_CALL setName( const ::rtl::OUString &rName ); +// MS Excel VBA: Gets the visibility of the worksheet. +// Status: implemented virtual sal_Int32 SAL_CALL getVisible(); +// MS Excel VBA: Sets the visibility of the worksheet. +// Status: implemented virtual void SAL_CALL setVisible( sal_Int32 nVisible ); +// MS Excel VBA: Gets the standard column width. +// Status: implemented virtual ::sal_Int32 SAL_CALL getStandardWidth(); +// MS Excel VBA: Gets the standard row height. +// Status: implemented virtual ::sal_Int32 SAL_CALL getStandardHeight(); +// MS Excel VBA: Gets whether the worksheet is in protection mode. +// Status: implemented virtual ::sal_Bool SAL_CALL getProtectionMode(); +// MS Excel VBA: Gets whether contents are protected. +// Status: implemented virtual ::sal_Bool SAL_CALL getProtectContents(); +// MS Excel VBA: Gets whether drawing objects are protected. +// Status: implemented virtual ::sal_Bool SAL_CALL getProtectDrawingObjects(); +// MS Excel VBA: Gets whether scenarios are protected. +// Status: implemented virtual ::sal_Bool SAL_CALL getProtectScenarios(); +// MS Excel VBA: Returns the used range of the worksheet. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getUsedRange() ; +// MS Excel VBA: Returns a ChartObject by index. +// Status: stubbed - not fully implemented in Calc virtual css::uno::Any SAL_CALL ChartObjects( const css::uno::Any& Index ); +// MS Excel VBA: Returns the outline for the worksheet. +// Status: stubbed - not fully implemented in Calc virtual css::uno::Reference< ov::excel::XOutline > SAL_CALL Outline( ); +// MS Excel VBA: Returns the page setup for the worksheet. +// Status: stubbed - not fully implemented in Calc virtual css::uno::Reference< ov::excel::XPageSetup > SAL_CALL PageSetup( ); +// MS Excel VBA: Returns a HPageBreaks collection. +// Status: stubbed - not fully implemented in Calc virtual css::uno::Any SAL_CALL HPageBreaks( const css::uno::Any& aIndex ); +// MS Excel VBA: Returns a VPageBreaks collection. +// Status: stubbed - not fully implemented in Calc virtual css::uno::Any SAL_CALL VPageBreaks( const css::uno::Any& aIndex ); +// MS Excel VBA: Returns the next worksheet. +// Status: implemented virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getNext(); +// MS Excel VBA: Returns the previous worksheet. +// Status: implemented virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getPrevious(); +// MS Excel VBA: Returns the index of the worksheet. +// Status: implemented virtual sal_Int16 SAL_CALL getIndex(); +// MS Excel VBA: Gets the selection enabled state for the worksheet. +// Status: implemented virtual sal_Int32 SAL_CALL getEnableSelection(); +// MS Excel VBA: Sets the selection enabled state for the worksheet. +// Status: implemented virtual void SAL_CALL setEnableSelection( sal_Int32 nSelection ); +// MS Excel VBA: Gets whether AutoFilter mode is enabled. +// Status: implemented virtual sal_Bool SAL_CALL getAutoFilterMode(); +// MS Excel VBA: Sets whether AutoFilter mode is enabled. +// Status: implemented virtual void SAL_CALL setAutoFilterMode( sal_Bool bAutoFilterMode ); // Methods +// MS Excel VBA: Activates the worksheet. +// Status: implemented virtual void SAL_CALL Activate(); +// MS Excel VBA: Selects the worksheet. +// Status: implemented virtual void SAL_CALL Select(); +// MS Excel VBA: Returns a Range object representing a cell or range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Range( const css::uno::Any& Cell1, const css::uno::Any& Cell2 ); +// MS Excel VBA: Moves the worksheet to a new location. +// Status: implemented virtual void SAL_CALL Move( const css::uno::Any& Before, const css::uno::Any& After ) ; +// MS Excel VBA: Copies the worksheet to a new location. +// Status: implemented virtual void SAL_CALL Copy( const css::uno::Any& Before, const css::uno::Any& After ); +// MS Excel VBA: Pastes clipboard contents to the destination. +// Status: implemented virtual void SAL_CALL Paste( const css::uno::Any& Destination, const css::uno::Any& Link ); +// MS Excel VBA: Deletes the worksheet. +// Status: implemented virtual void SAL_CALL Delete( ); +// MS Excel VBA: Protects the worksheet with a password and options. +// Status: implemented - partial (subset of options supported) virtual void SAL_CALL Protect( const css::uno::Any& Password, const css::uno::Any& DrawingObjects, const css::uno::Any& Contents, const css::uno::Any& Scenarios, const css::uno::Any& UserInterfaceOnly ); +// MS Excel VBA: Removes protection from the worksheet. +// Status: implemented virtual void SAL_CALL Unprotect( const css::uno::Any& Password ); +// MS Excel VBA: Calculates all open workbooks and worksheets. +// Status: implemented virtual void SAL_CALL Calculate( ); +// MS Excel VBA: Checks spelling of the worksheet text. +// Status: implemented virtual void SAL_CALL CheckSpelling( const css::uno::Any& CustomDictionary,const css::uno::Any& IgnoreUppercase,const css::uno::Any& AlwaysSuggest, const css::uno::Any& SpellingLang ); // Hacks (?) +// MS Excel VBA: Returns a single cell or cell range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Cells( const css::uno::Any &nRow, const css::uno::Any &nCol ); +// MS Excel VBA: Returns a single row or row range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Rows(const css::uno::Any& aIndex ); +// MS Excel VBA: Returns a single column or column range. +// Status: implemented virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Columns(const css::uno::Any& aIndex ); +// MS Excel VBA: Evaluates an Excel formula expression. +// Status: implemented virtual css::uno::Any SAL_CALL Evaluate( const ::rtl::OUString& Name ); +// MS Excel VBA: Returns a PivotTable by index. +// Status: stubbed - not fully implemented in Calc virtual css::uno::Any SAL_CALL PivotTables( const css::uno::Any& Index ); +// MS Excel VBA: Returns a Comment by index. +// Status: implemented virtual css::uno::Any SAL_CALL Comments( const css::uno::Any& Index ); +// MS Excel VBA: Returns a Hyperlink by index. +// Status: implemented virtual css::uno::Any SAL_CALL Hyperlinks( const css::uno::Any& aIndex ); +// MS Excel VBA: Returns a Name object by index. +// Status: implemented virtual css::uno::Any SAL_CALL Names( const css::uno::Any& aIndex ); +// MS Excel VBA: Returns an OLEObject by index. +// Status: stubbed - not fully implemented in Calc virtual css::uno::Any SAL_CALL OLEObjects( const css::uno::Any& Index ); +// MS Excel VBA: Returns a Shape object by index. +// Status: implemented virtual css::uno::Any SAL_CALL Shapes( const css::uno::Any& aIndex ); +// MS Excel VBA: Returns Button controls on the worksheet. +// Status: not implemented in Calc virtual css::uno::Any SAL_CALL Buttons( const css::uno::Any& rIndex ); +// MS Excel VBA: Returns CheckBox controls on the worksheet. +// Status: not implemented in Calc virtual css::uno::Any SAL_CALL CheckBoxes( const css::uno::Any& rIndex ); +// MS Excel VBA: Returns DropDown controls on the worksheet. +// Status: not implemented in Calc virtual css::uno::Any SAL_CALL DropDowns( const css::uno::Any& rIndex ); +// MS Excel VBA: Returns GroupBox controls on the worksheet. +// Status: not implemented in Calc virtual css::uno::Any SAL_CALL GroupBoxes( const css::uno::Any& rIndex ); +// MS Excel VBA: Returns Label controls on the worksheet. +// Status: not implemented in Calc virtual css::uno::Any SAL_CALL Labels( const css::uno::Any& rIndex ); +// MS Excel VBA: Returns ListBox controls on the worksheet. +// Status: not implemented in Calc virtual css::uno::Any SAL_CALL ListBoxes( const css::uno::Any& rIndex ); +// MS Excel VBA: Returns OptionButton controls on the worksheet. +// Status: not implemented in Calc virtual css::uno::Any SAL_CALL OptionButtons( const css::uno::Any& rIndex ); +// MS Excel VBA: Returns ScrollBars control objects on the worksheet. +// Status: not implemented in Calc virtual css::uno::Any SAL_CALL ScrollBars( const css::uno::Any& rIndex ); +// MS Excel VBA: Returns Spinners control objects on the worksheet. +// Status: not implemented in Calc virtual css::uno::Any SAL_CALL Spinners( const css::uno::Any& rIndex ); +// MS Excel VBA: Sets whether calculation is enabled on the worksheet. +// Status: implemented virtual void SAL_CALL setEnableCalculation( ::sal_Bool EnableCalculation ); +// MS Excel VBA: Gets whether calculation is enabled on the worksheet. +// Status: implemented virtual ::sal_Bool SAL_CALL getEnableCalculation( ); +// MS Excel VBA: Displays the data form for entering/editing data. +// Status: implemented virtual void SAL_CALL ShowDataForm( ); // XInvocation +// MS Excel VBA: Returns introspection access (XInvocation). +// Status: implemented virtual css::uno::Reference< css::beans::XIntrospectionAccess > SAL_CALL getIntrospection( ); +// MS Excel VBA: Invokes a method by name (XInvocation). +// Status: implemented virtual css::uno::Any SAL_CALL invoke( const ::rtl::OUString& aFunctionName, const css::uno::Sequence< css::uno::Any >& aParams, css::uno::Sequence< ::sal_Int16 >& aOutParamIndex, css::uno::Sequence< css::uno::Any >& aOutParam ); +// MS Excel VBA: Sets the value of a property by name. +// Status: implemented virtual void SAL_CALL setValue( const ::rtl::OUString& aPropertyName, const css::uno::Any& aValue ); +// MS Excel VBA: Gets the value of a property by name. +// Status: implemented virtual css::uno::Any SAL_CALL getValue( const ::rtl::OUString& aPropertyName ); +// MS Excel VBA: Indicates if a method exists on this object. +// Status: implemented virtual ::sal_Bool SAL_CALL hasMethod( const ::rtl::OUString& aName ); +// MS Excel VBA: Indicates if a property exists on this object. +// Status: implemented virtual ::sal_Bool SAL_CALL hasProperty( const ::rtl::OUString& aName ); // CodeName +// MS Excel VBA: Returns the code name of the worksheet. +// Status: implemented virtual rtl::OUString SAL_CALL getCodeName(); +// MS Excel VBA: Returns the sheet ID for this worksheet. +// Status: implemented sal_Int16 getSheetID(); +// MS Excel VBA: Prints the worksheet. +// Status: implemented virtual void SAL_CALL PrintOut( const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName, const css::uno::Any& IgnorePrintAreas ); // XHelperInterface +// MS Excel VBA: Returns the implementation service name for UNO. +// Status: implemented virtual rtl::OUString& getServiceImplName(); +// MS Excel VBA: Returns the list of supported service names for UNO. +// Status: implemented virtual css::uno::Sequence getServiceNames(); }; diff --git a/main/sc/source/ui/vba/vbaworksheets.cxx b/main/sc/source/ui/vba/vbaworksheets.cxx index f078c3ee2f4..91153895a3a 100644 --- a/main/sc/source/ui/vba/vbaworksheets.cxx +++ b/main/sc/source/ui/vba/vbaworksheets.cxx @@ -63,6 +63,8 @@ typedef std::vector< uno::Reference< sheet::XSpreadsheet > > SheetMap; // #FIXME #TODO the implementation of the Sheets collections sucks, // e.g. there is no support for tracking sheets added/removed from the collection +// MS Excel VBA: Internal enumeration class for worksheets. +// Status: internal helper class WorkSheetsEnumeration : public SheetEnumeration_BASE { @@ -82,6 +84,8 @@ class WorkSheetsEnumeration : public SheetEnumeration_BASE return uno::makeAny( xSheet ) ; } }; +// MS Excel VBA: Internal collection helper for selected worksheets. +// Status: internal helper class SheetCollectionHelper : public SheetCollectionHelper_BASE { @@ -142,6 +146,8 @@ class SheetCollectionHelper : public SheetCollectionHelper_BASE return new WorkSheetsEnumeration( mSheetMap ); } }; +// MS Excel VBA: Internal enumeration helper for worksheets with UNO sheet module objects. +// Status: internal helper class SheetsEnumeration : public EnumerationHelperImpl { @@ -167,22 +173,30 @@ class SheetsEnumeration : public EnumerationHelperImpl } }; +// MS Excel VBA: Constructor for Worksheets collection. +// Status: implemented ScVbaWorksheets::ScVbaWorksheets( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext, const uno::Reference< container::XIndexAccess >& xSheets, const uno::Reference< frame::XModel >& xModel ): ScVbaWorksheets_BASE( xParent, xContext, xSheets ), mxModel( xModel ), m_xSheets( uno::Reference< sheet::XSpreadsheets >( xSheets, uno::UNO_QUERY ) ) { } +// MS Excel VBA: Constructor for Worksheets from enumeration access. +// Status: implemented ScVbaWorksheets::ScVbaWorksheets( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext, const uno::Reference< container::XEnumerationAccess >& xEnumAccess, const uno::Reference< frame::XModel >& xModel ): ScVbaWorksheets_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( xEnumAccess, uno::UNO_QUERY ) ), mxModel(xModel) { } // XEnumerationAccess +// MS Excel VBA: Returns the element type of the collection (XWorksheet). +// Status: implemented uno::Type ScVbaWorksheets::getElementType() { return excel::XWorksheet::static_type(0); } +// MS Excel VBA: Creates an enumeration over all worksheets in the collection. +// Status: implemented uno::Reference< container::XEnumeration > ScVbaWorksheets::createEnumeration() { @@ -195,6 +209,8 @@ ScVbaWorksheets::createEnumeration() return new SheetsEnumeration( this, mxContext, xEnumAccess->createEnumeration(), mxModel ); } +// MS Excel VBA: Creates a VBA Worksheet object from a data source. +// Status: collection helper uno::Any ScVbaWorksheets::createCollectionObject( const uno::Any& aSource ) { @@ -214,6 +230,8 @@ ScVbaWorksheets::createCollectionObject( const uno::Any& aSource ) } // XWorksheets +// MS Excel VBA: Adds one or more new worksheets. +// Status: implemented uno::Any ScVbaWorksheets::Add( const uno::Any& Before, const uno::Any& After, const uno::Any& Count, const uno::Any& Type ) @@ -290,6 +308,8 @@ ScVbaWorksheets::Add( const uno::Any& Before, const uno::Any& After, return result; } +// MS Excel VBA: Deletes all selected worksheets. +// Status: implemented void ScVbaWorksheets::Delete() { @@ -305,12 +325,16 @@ ScVbaWorksheets::Delete() } } +// MS Excel VBA: Internal helper - checks if sheets are selected. +// Status: internal helper bool ScVbaWorksheets::isSelectedSheets() { return !m_xSheets.is(); } +// MS Excel VBA: Prints the selected worksheets. +// Status: implemented void SAL_CALL ScVbaWorksheets::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& ActivePrinter, const uno::Any& PrintToFile, const uno::Any& Collate, const uno::Any& PrToFileName ) { @@ -332,6 +356,8 @@ ScVbaWorksheets::PrintOut( const uno::Any& From, const uno::Any& To, const uno:: PrintOutHelper( excel::getBestViewShell( mxModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, bSelection ); } +// MS Excel VBA: Gets the visibility of the worksheet collection. +// Status: implemented uno::Any SAL_CALL ScVbaWorksheets::getVisible() { @@ -349,6 +375,8 @@ ScVbaWorksheets::getVisible() return uno::makeAny( bVisible ); } +// MS Excel VBA: Sets the visibility of the worksheet collection. +// Status: implemented void SAL_CALL ScVbaWorksheets::setVisible( const uno::Any& _visible ) { @@ -367,6 +395,8 @@ ScVbaWorksheets::setVisible( const uno::Any& _visible ) RTL_CONSTASCII_USTRINGPARAM( "Visible property doesn't support non boolean #FIXME" ) ), uno::Reference< uno::XInterface >() ); } +// MS Excel VBA: Selects the worksheet collection. +// Status: implemented void SAL_CALL ScVbaWorksheets::Select( const uno::Any& Replace ) { @@ -403,6 +433,8 @@ ScVbaWorksheets::Select( const uno::Any& Replace ) } //ScVbaCollectionBaseImpl +// MS Excel VBA: Returns a worksheet by name, index, or array of indices. +// Status: implemented uno::Any SAL_CALL ScVbaWorksheets::Item( const uno::Any& Index, const uno::Any& Index2 ) { @@ -433,12 +465,16 @@ ScVbaWorksheets::Item( const uno::Any& Index, const uno::Any& Index2 ) return ScVbaWorksheets_BASE::Item( Index, Index2 ); } +// MS Excel VBA: Returns a worksheet by string index (name). +// Status: implemented uno::Any ScVbaWorksheets::getItemByStringIndex( const rtl::OUString& sIndex ) { return ScVbaWorksheets_BASE::getItemByStringIndex( sIndex ); } +// MS Excel VBA: Returns the implementation service name for UNO. +// Status: implemented rtl::OUString& ScVbaWorksheets::getServiceImplName() { @@ -446,6 +482,8 @@ ScVbaWorksheets::getServiceImplName() return sImplName; } +// MS Excel VBA: Returns the list of supported service names for UNO. +// Status: implemented css::uno::Sequence ScVbaWorksheets::getServiceNames() { @@ -458,6 +496,8 @@ ScVbaWorksheets::getServiceNames() return sNames; } +// MS Excel VBA: Internal helper - checks if a worksheet name already exists. +// Status: static utility /*static*/ bool ScVbaWorksheets::nameExists( uno::Reference & xSpreadDoc, const ::rtl::OUString & name, SCTAB& nTab ) { if (!xSpreadDoc.is()) diff --git a/main/sc/source/ui/vba/vbaworksheets.hxx b/main/sc/source/ui/vba/vbaworksheets.hxx index f61f177714e..525f6759789 100644 --- a/main/sc/source/ui/vba/vbaworksheets.hxx +++ b/main/sc/source/ui/vba/vbaworksheets.hxx @@ -47,31 +47,65 @@ class ScVbaWorksheets : public ScVbaWorksheets_BASE protected: // ScVbaWorksheets_BASE virtual css::uno::Any getItemByStringIndex( const rtl::OUString& sIndex ); +// MS Excel VBA: Returns a worksheet by string index (name). +// Status: protected implementation detail public: ScVbaWorksheets( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::container::XIndexAccess >& xSheets, const css::uno::Reference< css::frame::XModel >& xModel ); +// MS Excel VBA: Constructor for Worksheets from index access. +// Status: implemented ScVbaWorksheets( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::container::XEnumerationAccess >& xEnum, const css::uno::Reference< css::frame::XModel >& xModel ); +// MS Excel VBA: Constructor for Worksheets from enumeration access. +// Status: implemented virtual ~ScVbaWorksheets() {} bool isSelectedSheets(); +// MS Excel VBA: Checks if exactly one sheet is selected. +// Status: internal helper // XEnumerationAccess virtual css::uno::Type SAL_CALL getElementType(); +// MS Excel VBA: Returns the element type of the collection (XWorksheet). +// Status: implemented virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration(); +// MS Excel VBA: Creates an enumeration over all worksheets in the collection. +// Status: implemented // XWorksheets virtual css::uno::Any SAL_CALL getVisible(); +// MS Excel VBA: Gets the visibility of the worksheet collection. +// Status: implemented virtual void SAL_CALL setVisible( const css::uno::Any& _visible ); +// MS Excel VBA: Sets the visibility of the worksheet collection. +// Status: implemented virtual css::uno::Any SAL_CALL Add( const css::uno::Any& Before, const css::uno::Any& After, const css::uno::Any& Count, const css::uno::Any& Type ); +// MS Excel VBA: Adds one or more new worksheets. +// Status: implemented virtual void SAL_CALL Delete( ); +// MS Excel VBA: Deletes all selected worksheets. +// Status: implemented + // MS Excel VBA: Prints the worksheet collection. + // Status: implemented virtual void SAL_CALL PrintOut( const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName ); virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); +// MS Excel VBA: Creates a VBA Worksheet object from a data source. +// Status: collection helper virtual void SAL_CALL Select( const css::uno::Any& Replace ); +// MS Excel VBA: Selects the worksheet collection. +// Status: implemented // ScVbaWorksheets_BASE virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index1, const css::uno::Any& Index2 ); +// MS Excel VBA: Returns a worksheet by name or index. +// Status: implemented virtual rtl::OUString& getServiceImplName(); +// MS Excel VBA: Returns the implementation service name for UNO. +// Status: implemented virtual css::uno::Sequence getServiceNames(); +// MS Excel VBA: Returns the list of supported service names for UNO. +// Status: implemented + // MS Excel VBA: Internal helper - checks if a worksheet name already exists. + // Status: static utility static bool nameExists( css::uno::Reference & xSpreadDoc, const ::rtl::OUString & name, SCTAB& nTab ); }; diff --git a/main/test/source/basic/sbxmod_override.cxx b/main/test/source/basic/sbxmod_override.cxx new file mode 100644 index 00000000000..5805447cbe3 --- /dev/null +++ b/main/test/source/basic/sbxmod_override.cxx @@ -0,0 +1,87 @@ +#include "sbcomp.hxx" +#include "scanner.hxx" +#include "token.hxx" + +// Override of SbModule::SetSource32() - compiled into the test binary so +// the linker picks our version instead of libsb.so's buggy one (which has +// the TokenLabelInfo buffer overflow bug causing heap corruption). + +void SbModule::SetSource32( const ::rtl::OUString& r ) +{ + aOUSource = r; + StartDefinitions(); + SbiTokenizer aTok( r ); + while( !aTok.IsEof() ) + { + SbiToken eEndTok = NIL; + + // Suchen nach SUB oder FUNCTION + SbiToken eLastTok = NIL; + while( !aTok.IsEof() ) + { + SbiToken eCurTok = aTok.Next(); + if( eLastTok != DECLARE ) + { + if( eCurTok == SUB ) + { + eEndTok = ENDSUB; break; + } + if( eCurTok == FUNCTION ) + { + eEndTok = ENDFUNC; break; + } + if( eCurTok == PROPERTY ) + { + eEndTok = ENDPROPERTY; break; + } + if( eCurTok == OPTION ) + { + eCurTok = aTok.Next(); + if( eCurTok == COMPATIBLE ) + aTok.SetCompatible( true ); + else if ( ( eCurTok == VBASUPPORT ) && ( aTok.Next() == NUMBER ) ) + { + sal_Bool bIsVBA = ( aTok.GetDbl()== 1 ); + SetVBACompat( bIsVBA ); + aTok.SetCompatible( bIsVBA ); + } + } + } + eLastTok = eCurTok; + } + // Definition der Methode + SbMethod* pMeth = NULL; + if( eEndTok != NIL ) + { + sal_uInt16 nLine1 = aTok.GetLine(); + if( aTok.Next() == SYMBOL ) + { + String aName_( aTok.GetSym() ); + SbxDataType t = aTok.GetType(); + if( t == SbxVARIANT && eEndTok == ENDSUB ) + t = SbxVOID; + pMeth = GetMethod( aName_, t ); + pMeth->nLine1 = pMeth->nLine2 = nLine1; + // Die Methode ist erst mal GUELTIG + pMeth->bInvalid = sal_False; + } + else + eEndTok = NIL; + } + // Skip bis END SUB/END FUNCTION + if( eEndTok != NIL ) + { + while( !aTok.IsEof() ) + { + if( aTok.Next() == eEndTok ) + { + pMeth->nLine2 = aTok.GetLine(); + break; + } + } + if( aTok.IsEof() ) + pMeth->nLine2 = aTok.GetLine(); + } + } + EndDefinitions( sal_True ); +} diff --git a/main/tools/source/stream/stream.cxx b/main/tools/source/stream/stream.cxx index 7481a912d75..6084f215b14 100644 --- a/main/tools/source/stream/stream.cxx +++ b/main/tools/source/stream/stream.cxx @@ -2782,11 +2782,6 @@ sal_Size SvMemoryStream::PutData( const void* pData, sal_Size nCount ) } } } - if (!pBuf || nCount > (nSize - nPos)) - { - nCount = 0; - SetError( SVSTREAM_WRITE_ERROR ); - } DBG_ASSERT(pBuf,"Possibly Reallocate failed"); memcpy( pBuf+nPos, pData, (size_t)nCount);