[Libreoffice-commits] core.git: basic/source include/vbahelper oovbaapi/ooo oovbaapi/UnoApi_oovbaapi.mk sc/Library_vbaobj.mk sc/source vbahelper/source

Tamas Bunth tamas.bunth at collabora.co.uk
Fri Sep 8 07:29:56 UTC 2017


 basic/source/runtime/runtime.cxx        |    2 -
 include/vbahelper/vbashape.hxx          |    2 +
 oovbaapi/UnoApi_oovbaapi.mk             |    2 +
 oovbaapi/ooo/vba/msforms/XLine.idl      |   41 +++++++++++++++++++++++++++++++
 oovbaapi/ooo/vba/msforms/XOval.idl      |   41 +++++++++++++++++++++++++++++++
 sc/Library_vbaobj.mk                    |    2 +
 sc/source/ui/vba/vbaapplication.cxx     |   21 ++++++++++++++--
 sc/source/ui/vba/vbalineshape.cxx       |   34 +++++++++++++++++++++++++
 sc/source/ui/vba/vbalineshape.hxx       |   37 ++++++++++++++++++++++++++++
 sc/source/ui/vba/vbaovalshape.cxx       |   34 +++++++++++++++++++++++++
 sc/source/ui/vba/vbaovalshape.hxx       |   37 ++++++++++++++++++++++++++++
 vbahelper/source/vbahelper/vbashape.cxx |   42 ++++++++++++++++++++++++++++++++
 12 files changed, 292 insertions(+), 3 deletions(-)

New commits:
commit 8e8c789742874ac823e68f6154050c64b6fc5b85
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
Date:   Thu Sep 7 22:00:01 2017 +0200

    oovbaapi: create XOval and XLine shape types
    
    This is needed in order to make "TypeOf myLine Is Line" or similar
    expressions return the expected "true" value.
    
    The implementation of the basic interpreter of TypeOf uses XTypeProvider
    to determine the type of an object by getting the last part of the type
    name. E.g. "ooo:vba::msforms::XLine" is determined as a "Line". That's
    why I created the XLine and XOval blank classes.
    
    TypeOf doc:
    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/typeof-operator
    
    Change-Id: Ia49cc92d672e30d0126f02d61a55a956ac1425f0
    Reviewed-on: https://gerrit.libreoffice.org/42083
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tamás Bunth <btomi96 at gmail.com>

diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index 5d9764fa7581..032e4d85128b 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -3174,7 +3174,7 @@ bool SbiRuntime::checkClass_Impl( const SbxVariableRef& refVal,
             t = pProp->getRealType();
         }
     }
-    if( t == SbxOBJECT )
+    if( t == SbxOBJECT || bVBAEnabled )
     {
         SbxObject* pObj = dynamic_cast<SbxObject*>(pVal);
         if (!pObj)
diff --git a/include/vbahelper/vbashape.hxx b/include/vbahelper/vbashape.hxx
index 17f459fa4ad6..dfc6973cbcb7 100644
--- a/include/vbahelper/vbashape.hxx
+++ b/include/vbahelper/vbashape.hxx
@@ -84,6 +84,8 @@ public:
     /// @throws css::uno::RuntimeException
     static sal_Int32 getType( const css::uno::Reference< css::drawing::XShape >& rShape );
 
+    static sal_Int32 getAutoShapeType( const css::uno::Reference< css::drawing::XShape >& rShape );
+
     // Attributes
     virtual OUString SAL_CALL getName() override;
     virtual void SAL_CALL setName( const OUString& _name ) override;
diff --git a/oovbaapi/UnoApi_oovbaapi.mk b/oovbaapi/UnoApi_oovbaapi.mk
index d99d7c3772d9..f977f44d0b08 100644
--- a/oovbaapi/UnoApi_oovbaapi.mk
+++ b/oovbaapi/UnoApi_oovbaapi.mk
@@ -530,10 +530,12 @@ $(eval $(call gb_UnoApi_add_idlfiles,oovbaapi,ooo/vba/msforms,\
 	XGroupBox \
 	XImage \
 	XLabel \
+	XLine \
 	XLineFormat \
 	XListBox \
 	XMultiPage \
 	XNewFont \
+	XOval \
 	XPages \
 	XPictureFormat \
 	XProgressBar \
diff --git a/oovbaapi/ooo/vba/msforms/XLine.idl b/oovbaapi/ooo/vba/msforms/XLine.idl
new file mode 100644
index 000000000000..18cd4be551ea
--- /dev/null
+++ b/oovbaapi/ooo/vba/msforms/XLine.idl
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   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 .
+ */
+#ifndef __ooo_vba_msforms_XLineShape_idl__
+#define __ooo_vba_msforms_XLineShape_idl__
+
+#include <com/sun/star/uno/XInterface.idl>
+
+module ooo {  module vba { module msforms {
+
+/*
+ * This class stub is created in order to make "TypeOf myShape Is Line" expression
+ * return true. It is determined using XTypeProvider::getTypes(), which is
+ * implemented automatically based on the name of the class.
+ */
+interface XLine: com::sun::star::uno::XInterface
+{
+
+
+};
+
+}; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oovbaapi/ooo/vba/msforms/XOval.idl b/oovbaapi/ooo/vba/msforms/XOval.idl
new file mode 100644
index 000000000000..e87fea25484d
--- /dev/null
+++ b/oovbaapi/ooo/vba/msforms/XOval.idl
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   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 .
+ */
+#ifndef __ooo_vba_msforms_XOvalShape_idl__
+#define __ooo_vba_msforms_XOvalShape_idl__
+
+#include <com/sun/star/uno/XInterface.idl>
+
+module ooo {  module vba { module msforms {
+
+/*
+ * This class stub is created in order to make "TypeOf myShape Is Oval" expression
+ * return true. It is determined using XTypeProvider::getTypes(), which is
+ * implemented automatically based on the name of the class.
+ */
+interface XOval: com::sun::star::uno::XInterface
+{
+
+
+};
+
+}; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/Library_vbaobj.mk b/sc/Library_vbaobj.mk
index 2d04d28d5bb5..082b254c88df 100644
--- a/sc/Library_vbaobj.mk
+++ b/sc/Library_vbaobj.mk
@@ -84,6 +84,7 @@ $(eval $(call gb_Library_add_exception_objects,vbaobj,\
 	sc/source/ui/vba/vbahyperlink \
 	sc/source/ui/vba/vbahyperlinks \
 	sc/source/ui/vba/vbainterior \
+	sc/source/ui/vba/vbalineshape \
 	sc/source/ui/vba/vbamenubar  \
 	sc/source/ui/vba/vbamenubars \
 	sc/source/ui/vba/vbamenu \
@@ -95,6 +96,7 @@ $(eval $(call gb_Library_add_exception_objects,vbaobj,\
 	sc/source/ui/vba/vbaoleobject \
 	sc/source/ui/vba/vbaoleobjects \
 	sc/source/ui/vba/vbaoutline \
+	sc/source/ui/vba/vbaovalshape \
 	sc/source/ui/vba/vbapagebreak \
 	sc/source/ui/vba/vbapagebreaks \
 	sc/source/ui/vba/vbapagesetup \
diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx
index bab488c48b5d..1c915d15ae3b 100644
--- a/sc/source/ui/vba/vbaapplication.cxx
+++ b/sc/source/ui/vba/vbaapplication.cxx
@@ -33,6 +33,7 @@
 #include <ooo/vba/excel/XlCalculation.hpp>
 #include <ooo/vba/excel/XlMousePointer.hpp>
 #include <ooo/vba/office/MsoShapeType.hpp>
+#include <ooo/vba/office/MsoAutoShapeType.hpp>
 
 #include "service.hxx"
 #include "vbaapplication.hxx"
@@ -51,6 +52,8 @@
 #include "vbanames.hxx"
 #include <vbahelper/vbashape.hxx>
 #include "vbatextboxshape.hxx"
+#include "vbaovalshape.hxx"
+#include "vbalineshape.hxx"
 #include "vbaassistant.hxx"
 #include "sc.hrc"
 #include "macromgr.hxx"
@@ -259,14 +262,28 @@ ScVbaApplication::getSelection()
     // if ScVbaShape::getType( xShape ) == office::MsoShapeType::msoAutoShape
     // and the uno object implements the com.sun.star.drawing.Text service
     // return a textboxshape object
-    if ( ScVbaShape::getType( xShape ) == office::MsoShapeType::msoAutoShape )
+    sal_Int32 nType = ScVbaShape::getType( xShape );
+    if ( nType == office::MsoShapeType::msoAutoShape )
     {
+        // TODO Oval with text box
+        if( ScVbaShape::getAutoShapeType( xShape ) == office::MsoAutoShapeType::msoShapeOval )
+        {
+            return uno::makeAny( uno::Reference< msforms::XOval >(new ScVbaOvalShape( mxContext, xShape, xShapes, xModel ) ) );
+        }
+
+
         uno::Reference< lang::XServiceInfo > xShapeServiceInfo( xShape, uno::UNO_QUERY_THROW );
         if ( xShapeServiceInfo->supportsService("com.sun.star.drawing.Text")  )
         {
-                return uno::makeAny( uno::Reference< msforms::XTextBoxShape >(new ScVbaTextBoxShape( mxContext, xShape, xShapes, xModel ) ) );
+                return uno::makeAny( uno::Reference< msforms::XTextBoxShape >(
+                            new ScVbaTextBoxShape( mxContext, xShape, xShapes, xModel ) ) );
         }
     }
+    else if ( nType == office::MsoShapeType::msoLine )
+    {
+        return uno::makeAny( uno::Reference< msforms::XLine >( new ScVbaLineShape(
+                        mxContext, xShape, xShapes, xModel ) ) );
+    }
         return uno::makeAny( uno::Reference< msforms::XShape >(new ScVbaShape( this, mxContext, xShape, xShapes, xModel, ScVbaShape::getType( xShape ) ) ) );
     }
     else if( xServiceInfo->supportsService("com.sun.star.sheet.SheetCellRange") ||
diff --git a/sc/source/ui/vba/vbalineshape.cxx b/sc/source/ui/vba/vbalineshape.cxx
new file mode 100644
index 000000000000..fac0f17155c9
--- /dev/null
+++ b/sc/source/ui/vba/vbalineshape.cxx
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   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 .
+ */
+
+#include "vbalineshape.hxx"
+
+using namespace com::sun::star;
+using namespace ooo::vba;
+
+/*
+ * This is implemented as a new class in order to provide XTypeProvider
+ * interface. This is needed by TypeOf ... Is ... basic operator.
+ */
+
+ScVbaLineShape::ScVbaLineShape( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape >& xShape, const uno::Reference< drawing::XShapes >& xShapes, const uno::Reference< frame::XModel >& xModel ) : LineShapeImpl_BASE( uno::Reference< XHelperInterface >(), xContext, xShape, xShapes, xModel, ScVbaShape::getType( xShape )  )
+{}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/vba/vbalineshape.hxx b/sc/source/ui/vba/vbalineshape.hxx
new file mode 100644
index 000000000000..08ce5f17b841
--- /dev/null
+++ b/sc/source/ui/vba/vbalineshape.hxx
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   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 .
+ */
+#ifndef INCLUDED_SC_SOURCE_UI_VBA_VBALINESHAPE_HXX
+#define INCLUDED_SC_SOURCE_UI_VBA_VBALINESHAPE_HXX
+
+#include <ooo/vba/msforms/XLine.hpp>
+#include <cppuhelper/implbase.hxx>
+#include <vbahelper/vbashape.hxx>
+
+typedef cppu::ImplInheritanceHelper< ScVbaShape, ov::msforms::XLine > LineShapeImpl_BASE;
+
+class ScVbaLineShape : public LineShapeImpl_BASE
+{
+public:
+    ScVbaLineShape( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape, const css::uno::Reference< css::drawing::XShapes >& xShapes, const css::uno::Reference< css::frame::XModel >& xModel );
+
+};
+
+#endif // INCLUDED_SC_SOURCE_UI_VBA_VBALINESHAPE_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/vba/vbaovalshape.cxx b/sc/source/ui/vba/vbaovalshape.cxx
new file mode 100644
index 000000000000..8efc877ee104
--- /dev/null
+++ b/sc/source/ui/vba/vbaovalshape.cxx
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   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 .
+ */
+
+#include "vbaovalshape.hxx"
+
+using namespace com::sun::star;
+using namespace ooo::vba;
+
+/*
+ * This is implemented as a new class in order to provide XTypeProvider
+ * interface. This is needed by TypeOf ... Is ... basic operator.
+ */
+
+ScVbaOvalShape::ScVbaOvalShape( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape >& xShape, const uno::Reference< drawing::XShapes >& xShapes, const uno::Reference< frame::XModel >& xModel ) : OvalShapeImpl_BASE( uno::Reference< XHelperInterface >(), xContext, xShape, xShapes, xModel, ScVbaShape::getType( xShape )  )
+{}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/vba/vbaovalshape.hxx b/sc/source/ui/vba/vbaovalshape.hxx
new file mode 100644
index 000000000000..72ec0996af38
--- /dev/null
+++ b/sc/source/ui/vba/vbaovalshape.hxx
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   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 .
+ */
+#ifndef INCLUDED_SC_SOURCE_UI_VBA_VBAOVALSHAPE_HXX
+#define INCLUDED_SC_SOURCE_UI_VBA_VBAOVALSHAPE_HXX
+
+#include <ooo/vba/msforms/XOval.hpp>
+#include <cppuhelper/implbase.hxx>
+#include <vbahelper/vbashape.hxx>
+
+typedef cppu::ImplInheritanceHelper< ScVbaShape, ov::msforms::XOval > OvalShapeImpl_BASE;
+
+class ScVbaOvalShape : public OvalShapeImpl_BASE
+{
+public:
+    ScVbaOvalShape( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape, const css::uno::Reference< css::drawing::XShapes >& xShapes, const css::uno::Reference< css::frame::XModel >& xModel );
+
+};
+
+#endif // INCLUDED_SC_SOURCE_UI_VBA_VBAOVALSHAPE_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vbahelper/source/vbahelper/vbashape.cxx b/vbahelper/source/vbahelper/vbashape.cxx
index ca012370267c..e7aed451efe2 100644
--- a/vbahelper/source/vbahelper/vbashape.cxx
+++ b/vbahelper/source/vbahelper/vbashape.cxx
@@ -29,6 +29,7 @@
 #include <com/sun/star/text/TextContentAnchorType.hpp>
 #include <com/sun/star/text/RelOrientation.hpp>
 #include <ooo/vba/office/MsoShapeType.hpp>
+#include <ooo/vba/office/MsoAutoShapeType.hpp>
 #include <ooo/vba/word/WdRelativeHorizontalPosition.hpp>
 #include <ooo/vba/word/WdRelativeVerticalPosition.hpp>
 
@@ -154,6 +155,47 @@ ScVbaShape::getType( const css::uno::Reference< drawing::XShape >& xShape )
         throw uno::RuntimeException("the shape type do not be supported: " + sShapeType );
 }
 
+sal_Int32 ScVbaShape::getAutoShapeType(const css::uno::Reference< drawing::XShape >& xShape)
+{
+    assert( ScVbaShape::getType( xShape ) == office::MsoShapeType::msoAutoShape );
+
+    OUString sShapeType;
+    uno::Reference< drawing::XShapeDescriptor > xShapeDescriptor( xShape, uno::UNO_QUERY_THROW );
+    sShapeType = xShapeDescriptor->getShapeType();
+    SAL_INFO("vbahelper", "ScVbaShape::getAutoShapeType: " << sShapeType);
+
+    if( sShapeType == "com.sun.star.drawing.EllipseShape" )
+        return office::MsoAutoShapeType::msoShapeOval;
+    else if ( sShapeType == "com.sun.star.drawing.RectangleShape" )
+        return office::MsoAutoShapeType::msoShapeRectangle;
+    else if ( sShapeType == "com.sun.star.drawing.CustomShape" )
+    {
+        uno::Reference< beans::XPropertySet > aXPropSet( xShape, uno::UNO_QUERY );
+        uno::Any aGeoPropSet = aXPropSet->getPropertyValue( "CustomShapeGeometry" );
+        uno::Sequence< beans::PropertyValue > aGeoPropSeq;
+        if ( aGeoPropSet >>= aGeoPropSeq )
+        {
+            for( const auto& rProp : aGeoPropSeq )
+            {
+                if( rProp.Name == "Type" )
+                {
+                    OUString sType;
+                    if( rProp.Value >>= sType )
+                    {
+                        if( sType.endsWith( "ellipse" ) )
+                            return office::MsoAutoShapeType::msoShapeOval;
+                        // TODO other custom shapes here
+                    }
+                }
+            }
+        }
+    }
+
+    SAL_WARN( "vbahelper", "ScVbaShape::getAutoShapeType: unknown auto type" );
+    return -1; // could not decide
+
+}
+
 // Attributes
 OUString SAL_CALL
 ScVbaShape::getName()


More information about the Libreoffice-commits mailing list