This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch symphony-vba
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 23dd14d1d8e309c538ad5ebeddd6f4d0b3f550f3
Author: Pedro Giffuni <[email protected]>
AuthorDate: Fri Oct 30 09:59:54 2026 -0500

    Implement Scripting.Dictionary for VBA compatibility
    
    Add Scripting.Dictionary implementation (ooo.vba.scripting.Dictionary 
service)
    with full Item/Add/Exists/Keys/Items/Remove/RemoveAll/Count/CompareMode/Key 
support.
    
    Key changes:
    - sbunooobj.cxx: Add SBX_HINT_DATACHANGED handler for pMeth to support
      dict("key") = value setter via invoke("Item", [key, value])
    - sb.cxx: Add CreateObject("Scripting.Dictionary") handler
    - vbadictionary.cxx/hxx: Full Dictionary UNO component implementation
    - XDictionary.idl: IDL interface with XDefaultMethod, XInvocation,
      XPropertySet, XHelperInterface
    - Add INTERFACE token to SbiToken enum for VBA parsing
    - Fix pre-existing build errors in vbadictionary, vbaapplication,
      vbafiledialog, and vbarange
---
 main/basic/source/classes/sb.cxx                |  13 +
 main/basic/source/classes/sbunoobj.cxx          |  43 +++
 main/basic/source/comp/parser.cxx               | 106 ++++-
 main/basic/source/inc/parser.hxx                |   2 +
 main/basic/source/inc/token.hxx                 |   2 +-
 main/oovbaapi/UnoApi_oovbaapi.mk                |   1 +
 main/oovbaapi/ooo/vba/scripting/XDictionary.idl |  67 ++++
 main/sc/Library_vbaobj.mk                       |   1 +
 main/sc/source/ui/vba/helperdecl.hxx            |   3 -
 main/sc/source/ui/vba/service.cxx               |   8 +-
 main/sc/source/ui/vba/vbaapplication.cxx        |   6 +-
 main/sc/source/ui/vba/vbadictionary.cxx         | 488 ++++++++++++++++++++++++
 main/sc/source/ui/vba/vbadictionary.hxx         | 129 +++++++
 main/sc/source/ui/vba/vbafiledialog.hxx         |   1 -
 main/sc/source/ui/vba/vbarange.cxx              |   2 +-
 15 files changed, 841 insertions(+), 31 deletions(-)

diff --git a/main/basic/source/classes/sb.cxx b/main/basic/source/classes/sb.cxx
index 11350c1f88..4962e08152 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 65093db807..03b4fcda8b 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/parser.cxx 
b/main/basic/source/comp/parser.cxx
index da47fef8c6..914825a84f 100644
--- a/main/basic/source/comp/parser.cxx
+++ b/main/basic/source/comp/parser.cxx
@@ -940,9 +940,33 @@ void SbiParser::PPIf()
        }
 }
 
-// Helper: Evaluate a conditional compilation expression.
-// Supports: True, False, identifier (looked up in maConstMap), Not expr, expr 
= expr
-bool SbiParser::evaluatePPCondition()
+// 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;
@@ -957,7 +981,19 @@ bool SbiParser::evaluatePPCondition()
        }
 
        // Get the left operand
-       if( eCurTok == SYMBOL )
+       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;
@@ -969,17 +1005,36 @@ bool SbiParser::evaluatePPCondition()
                {
                        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();
-                               bResult = (aName.EqualsIgnoreCaseAscii( aVal ));
+                               // 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 = (maConstMap.count( aName ) > 0 &&
-                                          (maConstMap[ aName ] == (nVal != 
0.0)));
+                               bResult = (bLVal == (nVal != 0.0));
+                               Next();
                        }
                }
                else if( eCurTok == THEN )
@@ -988,27 +1043,17 @@ bool SbiParser::evaluatePPCondition()
                        if( maConstMap.count( aName ) > 0 )
                                bResult = maConstMap[ aName ];
                        else
-                               bResult = false; // unknown constant defaults 
to false
+                               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( aSym.EqualsIgnoreCaseAscii( "True" ) )
-       {
-               bResult = true;
-               Next();
-               Peek();
-       }
-       else if( aSym.EqualsIgnoreCaseAscii( "False" ) )
-       {
-               bResult = false;
-               Next();
-               Peek();
-       }
        else if( eCurTok == NUMBER )
        {
                bResult = (nVal != 0.0);
@@ -1028,6 +1073,27 @@ bool SbiParser::evaluatePPCondition()
        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()
 {
diff --git a/main/basic/source/inc/parser.hxx b/main/basic/source/inc/parser.hxx
index 40656bc849..c4c9c16f7f 100644
--- a/main/basic/source/inc/parser.hxx
+++ b/main/basic/source/inc/parser.hxx
@@ -143,6 +143,8 @@ public:
        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
 
diff --git a/main/basic/source/inc/token.hxx b/main/basic/source/inc/token.hxx
index f5b887a58d..56bb14fea1 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,
diff --git a/main/oovbaapi/UnoApi_oovbaapi.mk b/main/oovbaapi/UnoApi_oovbaapi.mk
index 4ec8deabf7..df3e3e35f0 100644
--- a/main/oovbaapi/UnoApi_oovbaapi.mk
+++ b/main/oovbaapi/UnoApi_oovbaapi.mk
@@ -142,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/scripting/XDictionary.idl 
b/main/oovbaapi/ooo/vba/scripting/XDictionary.idl
new file mode 100644
index 0000000000..4c9f952bd5
--- /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 <com/sun/star/uno/XInterface.idl>
+#endif
+
+#ifndef __ooo_vba_XHelperInterface_idl__
+#include <ooo/vba/XHelperInterface.idl>
+#endif
+
+#ifndef __com_sun_star_script_XDefaultMethod_idl__
+#include <com/sun/star/script/XDefaultMethod.idl>
+#endif
+
+#ifndef __com_sun_star_script_XInvocation_idl__
+#include <com/sun/star/script/XInvocation.idl>
+#endif
+
+#ifndef __com_sun_star_container_XEnumeration_idl__
+#include <com/sun/star/container/XEnumeration.idl>
+#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 edb11b5e73..68d6e405e0 100644
--- a/main/sc/Library_vbaobj.mk
+++ b/main/sc/Library_vbaobj.mk
@@ -122,6 +122,7 @@ $(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 \
diff --git a/main/sc/source/ui/vba/helperdecl.hxx 
b/main/sc/source/ui/vba/helperdecl.hxx
index 4ea4b6793a..063d862c0a 100644
--- a/main/sc/source/ui/vba/helperdecl.hxx
+++ b/main/sc/source/ui/vba/helperdecl.hxx
@@ -19,9 +19,6 @@
  *
  *************************************************************/
 
-#ifndef SC_VBA_HELPERDECL_HXX
-#define SC_VBA_HELPERDECL_HXX
-
 #ifndef SC_VBA_HELPERDECL_HXX
 #define SC_VBA_HELPERDECL_HXX
 #include <comphelper/servicedecl.hxx>
diff --git a/main/sc/source/ui/vba/service.cxx 
b/main/sc/source/ui/vba/service.cxx
index c3e36dcf91..cbfbba0c33 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"
 {
@@ -86,9 +90,9 @@ extern "C"
     {
                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 );
+       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 e646800d36..425d0ae8a0 100644
--- a/main/sc/source/ui/vba/vbaapplication.cxx
+++ b/main/sc/source/ui/vba/vbaapplication.cxx
@@ -32,7 +32,7 @@
 #include <com/sun/star/sheet/XCalculatable.hpp>
 #include <com/sun/star/frame/XLayoutManager.hpp>
 #include <com/sun/star/frame/XModel.hpp>
-#include <com/sun/star/script/XScript.hpp>
+#include <com/sun/star/script/provider/XScript.hpp>
 #include <com/sun/star/script/provider/XScriptProvider.hpp>
 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
 #include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
@@ -226,7 +226,7 @@ sal_Bool SAL_CALL
 ScVbaApplication::hasMethod( const ::rtl::OUString& Name )
 {
     // Application.Run is implemented as a typed method on XApplication
-    if( Name.equalsIgnoreAsciiCase( "Run" ) )
+    if( Name.equalsIgnoreAsciiCaseAscii( "Run" ) )
         return sal_True;
     uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, 
mxContext ) );
     return xWSF->hasMethod( Name );
@@ -1513,7 +1513,7 @@ ScVbaApplication::Run( const rtl::OUString& rMacroName, 
const uno::Any& Arg1, co
             
rtl::OUString::createFromAscii("?language=Basic&location=document");
 
         // Get the script
-        uno::Reference< script::XScript > xScript = 
xScriptProvider->getScript( sScriptURI );
+        uno::Reference< script::provider::XScript > xScript = 
xScriptProvider->getScript( sScriptURI );
         if( !xScript.is() )
             throw script::BasicErrorException( ::rtl::OUString(), 
uno::Reference< uno::XInterface >(), 1000, ::rtl::OUString() );
 
diff --git a/main/sc/source/ui/vba/vbadictionary.cxx 
b/main/sc/source/ui/vba/vbadictionary.cxx
new file mode 100644
index 0000000000..767d023295
--- /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 <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/beans/Property.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/script/BasicErrorException.hpp>
+#include <com/sun/star/uno/Type.hxx>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/uno/DeploymentException.hpp>
+#include <comphelper/sequence.hxx>
+#include <basic/sbuno.hxx>
+#include <osl/diagnose.h>
+#include <rtl/ustrbuf.hxx>
+
+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<sal_Int32>(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<sal_Int32>(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<sal_Int32>(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<sal_Int32>(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<sal_Int32>(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_<ScVbaDictionary, sdecl::with_args<false> > 
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 0000000000..30b34d64b7
--- /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 <cppuhelper/implbase3.hxx>
+#include <ooo/vba/scripting/XDictionary.hpp>
+#include <ooo/vba/XHelperInterface.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/script/XDefaultMethod.hpp>
+#include <com/sun/star/script/XInvocation.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/XPropertySetInfo.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/uno/Exception.hpp>
+#include <rtl/ustring.hxx>
+#include <sal/types.h>
+
+#include <vector>
+#include <utility>
+#include <algorithm>
+
+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.hxx 
b/main/sc/source/ui/vba/vbafiledialog.hxx
index 7885540839..e727dad17d 100644
--- a/main/sc/source/ui/vba/vbafiledialog.hxx
+++ b/main/sc/source/ui/vba/vbafiledialog.hxx
@@ -85,7 +85,6 @@ private:
     rtl::OUString m_sTitle;
     sal_Bool m_bAllowMultiSelect;
     css::uno::Sequence< rtl::OUString > m_sSelectedItems;
-    css::uno::Reference< css::frame::XModel > m_xModel;
     VbaFileDialogSelectedItems *m_pSelectedItems;
     VbaFileDialogSelectedObj m_FileDialogSelectedObj;
 };
diff --git a/main/sc/source/ui/vba/vbarange.cxx 
b/main/sc/source/ui/vba/vbarange.cxx
index 25178feeb9..1cfcca298e 100644
--- a/main/sc/source/ui/vba/vbarange.cxx
+++ b/main/sc/source/ui/vba/vbarange.cxx
@@ -1746,7 +1746,7 @@ ScVbaRange::getValue2()
        if ( m_Areas->getCount() > 1 )
        {
                uno::Reference< excel::XRange > xRange( getArea( 0 ), 
uno::UNO_QUERY_THROW );
-               return xRange->getValue2();
+                return xRange->getValue();
        }
 
        CellValueGetter2 valueGetter;

Reply via email to