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 44be6dcb42b31dee2b9ba4969e35726c150bf267
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/comp/parser.cxx        | 106 +++++++++++++++++++++++++------
 main/basic/source/inc/parser.hxx         |   2 +
 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/vbafiledialog.hxx  |   1 -
 main/sc/source/ui/vba/vbarange.cxx       |   2 +-
 8 files changed, 99 insertions(+), 30 deletions(-)

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/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/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