include/oox/vml/vmldrawing.hxx | 1 include/oox/vml/vmlshapecontext.hxx | 9 ++++++ oox/source/vml/vmldrawing.cxx | 1 oox/source/vml/vmldrawingfragment.cxx | 3 +- oox/source/vml/vmlshape.cxx | 13 +++++--- oox/source/vml/vmlshapecontext.cxx | 14 +++++++++ sw/CppunitTest_sw_ooxmlimport.mk | 3 +- sw/qa/extras/ooxmlimport/data/activex_checkbox.docx |binary sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 29 ++++++++++++++++++++ writerfilter/source/dmapper/OLEHandler.cxx | 7 ++++ writerfilter/source/ooxml/model.xml | 24 ---------------- 11 files changed, 73 insertions(+), 31 deletions(-)
New commits: commit 8170245a9d9b9aeff913e0b3477fc2a9d508af80 Author: Tamás Zolnai <tamas.zol...@collabora.com> Date: Wed Aug 23 16:21:29 2017 +0200 tdf#91384: DOCX: import ActiveX controls Reviewed-on: https://gerrit.libreoffice.org/40930 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com> (cherry picked from commit 4a764319cbad4e2589cc105145ac27defbf49ff6) Change-Id: Iebf2ff65fcec3231acfc962fb2f1abc2ed2dc67a Avoid warning in OleHandler Related to ActiveX controls. Change-Id: Ief7ee67ca8e4f086a1d5e0400d0eaf3ebc8cdaaf Reviewed-on: https://gerrit.libreoffice.org/40934 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com> (cherry picked from commit 368b583b992f2e9cad46c2362c9529a07c36d7a9) Reviewed-on: https://gerrit.libreoffice.org/41483 Reviewed-by: Andras Timar <andras.ti...@collabora.com> Tested-by: Andras Timar <andras.ti...@collabora.com> diff --git a/include/oox/vml/vmldrawing.hxx b/include/oox/vml/vmldrawing.hxx index e9309f6c8497..e75fd480b82f 100644 --- a/include/oox/vml/vmldrawing.hxx +++ b/include/oox/vml/vmldrawing.hxx @@ -81,6 +81,7 @@ struct OOX_DLLPUBLIC ControlInfo OUString maShapeId; ///< Shape identifier for shape lookup. OUString maFragmentPath; ///< Path to the fragment describing the form control properties. OUString maName; ///< Programmatical name of the form control. + bool mbTextContentShape; ///< Whether this control shape will be imported to Writer or not (has AnchorType poperty or not). explicit ControlInfo(); diff --git a/include/oox/vml/vmlshapecontext.hxx b/include/oox/vml/vmlshapecontext.hxx index 1c1565b62397..55a2ff70f9e2 100644 --- a/include/oox/vml/vmlshapecontext.hxx +++ b/include/oox/vml/vmlshapecontext.hxx @@ -178,6 +178,15 @@ public: onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; }; +class ControlShapeContext : public ShapeContextBase +{ +public: + explicit ControlShapeContext( + ::oox::core::ContextHandler2Helper& rParent, + ShapeContainer& rShapes, + const AttributeList& rAttribs ); +}; + } // namespace vml } // namespace oox diff --git a/oox/source/vml/vmldrawing.cxx b/oox/source/vml/vmldrawing.cxx index 1a7d2e096376..56bf5034376a 100644 --- a/oox/source/vml/vmldrawing.cxx +++ b/oox/source/vml/vmldrawing.cxx @@ -79,6 +79,7 @@ void OleObjectInfo::setShapeId( sal_Int32 nShapeId ) } ControlInfo::ControlInfo() + : mbTextContentShape(false) { } diff --git a/oox/source/vml/vmldrawingfragment.cxx b/oox/source/vml/vmldrawingfragment.cxx index c1bed09b73fd..5f7c91f24934 100644 --- a/oox/source/vml/vmldrawingfragment.cxx +++ b/oox/source/vml/vmldrawingfragment.cxx @@ -51,7 +51,8 @@ ContextHandlerRef DrawingFragment::onCreateContext( sal_Int32 nElement, const At { // DOCX filter handles plain shape elements with this fragment handler case VMLDRAWING_WORD: - if ( getNamespace( nElement ) == NMSP_vml ) + if ( getNamespace( nElement ) == NMSP_vml + || nElement == W_TOKEN(control) ) // Control shape also defined as a vml shape return ShapeContextBase::createShapeContext( *this, mrDrawing.getShapes(), nElement, rAttribs ); break; diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx index 11d08754c01a..9f9903a04e88 100644 --- a/oox/source/vml/vmlshape.cxx +++ b/oox/source/vml/vmlshape.cxx @@ -1171,18 +1171,21 @@ Reference< XShape > ComplexShape::implConvertAndInsert( const Reference< XShapes const ControlInfo* pControlInfo = mrDrawing.getControlInfo( maTypeModel.maShapeId ); if( pControlInfo && !pControlInfo->maFragmentPath.isEmpty() ) { - OSL_ENSURE( nShapeType == VML_SHAPETYPE_HOSTCONTROL, "ComplexShape::implConvertAndInsert - unexpected shape type" ); - OUString aShapeName = getShapeName(); - if( !aShapeName.isEmpty() ) + if( !pControlInfo->maName.isEmpty() ) { - OSL_ENSURE( aShapeName == pControlInfo->maName, "ComplexShape::implConvertAndInsert - control name mismatch" ); // load the control properties from fragment - ::oox::ole::EmbeddedControl aControl( aShapeName ); + ::oox::ole::EmbeddedControl aControl(pControlInfo->maName); if( rFilter.importFragment( new ::oox::ole::AxControlFragment( rFilter, pControlInfo->maFragmentPath, aControl ) ) ) { // create and return the control shape (including control model) sal_Int32 nCtrlIndex = -1; Reference< XShape > xShape = mrDrawing.createAndInsertXControlShape( aControl, rxShapes, rShapeRect, nCtrlIndex ); + + if (pControlInfo->mbTextContentShape) + { + PropertySet aPropertySet(xShape); + lcl_SetAnchorType(aPropertySet, maTypeModel, mrDrawing.getFilter().getGraphicHelper()); + } // on error, proceed and try to create picture from replacement image if( xShape.is() ) return xShape; diff --git a/oox/source/vml/vmlshapecontext.cxx b/oox/source/vml/vmlshapecontext.cxx index 9311351601d5..800ec9ad0582 100644 --- a/oox/source/vml/vmlshapecontext.cxx +++ b/oox/source/vml/vmlshapecontext.cxx @@ -262,6 +262,9 @@ ContextHandlerRef ShapeContextBase::createShapeContext( ContextHandler2Helper& r case VML_TOKEN( diagram ): case VML_TOKEN( image ): return new ShapeContext( rParent, rShapes.createShape< ComplexShape >(), rAttribs ); + + case W_TOKEN(control): + return new ControlShapeContext( rParent, rShapes, rAttribs ); } return nullptr; } @@ -554,6 +557,17 @@ ContextHandlerRef RectangleShapeContext::onCreateContext( sal_Int32 nElement, co return ShapeContext::onCreateContext( nElement, rAttribs ); } +ControlShapeContext::ControlShapeContext( ::oox::core::ContextHandler2Helper& rParent, ShapeContainer& rShapes, const AttributeList& rAttribs ) + : ShapeContextBase (rParent) +{ + ::oox::vml::ControlInfo aInfo; + aInfo.maShapeId = rAttribs.getXString( W_TOKEN( shapeid ), OUString() ); + aInfo.maFragmentPath = getFragmentPathFromRelId(rAttribs.getString( R_TOKEN(id), OUString() )); + aInfo.maName = rAttribs.getString( W_TOKEN( name ), OUString() ); + aInfo.mbTextContentShape = true; + rShapes.getDrawing().registerControl(aInfo); +} + } // namespace vml } // namespace oox diff --git a/sw/CppunitTest_sw_ooxmlimport.mk b/sw/CppunitTest_sw_ooxmlimport.mk index 76f78f21b8ae..71e95d1733f8 100644 --- a/sw/CppunitTest_sw_ooxmlimport.mk +++ b/sw/CppunitTest_sw_ooxmlimport.mk @@ -83,7 +83,8 @@ $(eval $(call gb_CppunitTest_use_components,sw_ooxmlimport,\ sw/util/swd \ sw/util/msword \ sfx2/util/sfx \ - starmath/util/sm \ + sot/util/sot \ + starmath/util/sm \ svl/source/fsstor/fsstorage \ svl/util/svl \ svtools/util/svt \ diff --git a/sw/qa/extras/ooxmlimport/data/activex_checkbox.docx b/sw/qa/extras/ooxmlimport/data/activex_checkbox.docx new file mode 100755 index 000000000000..d7415ef5a5c6 Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/activex_checkbox.docx differ diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index dde5f4157910..4eb2512a4bf8 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -60,7 +60,9 @@ #include <unotools/streamwrap.hxx> #include <comphelper/propertysequence.hxx> #include <com/sun/star/drawing/HomogenMatrix3.hpp> +#include <com/sun/star/drawing/XControlShape.hpp> #include <com/sun/star/awt/CharSet.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> #include <test/mtfxmldump.hxx> class Test : public SwModelTestBase @@ -1589,6 +1591,33 @@ DECLARE_OOXMLIMPORT_TEST(testTdf111550, "tdf111550.docx") getCell(innerTable, "A1", "[outer:A2]\n[inner:A1]"); } +DECLARE_OOXMLIMPORT_TEST( testActiveXCheckbox, "activex_checkbox.docx" ) +{ + uno::Reference<drawing::XControlShape> xControlShape( getShape(1), uno::UNO_QUERY ); + CPPUNIT_ASSERT( xControlShape.is() ); + + // Check control type + uno::Reference<beans::XPropertySet> xPropertySet( xControlShape->getControl(), uno::UNO_QUERY ); + uno::Reference<lang::XServiceInfo> xServiceInfo( xPropertySet, uno::UNO_QUERY ); + CPPUNIT_ASSERT_EQUAL( true, bool( xServiceInfo->supportsService( "com.sun.star.form.component.CheckBox" ) ) ); + + // Check custom label + CPPUNIT_ASSERT_EQUAL( OUString( "Custom Caption" ), getProperty<OUString>(xPropertySet, "Label") ); + + // Check background color (highlight system color) + CPPUNIT_ASSERT_EQUAL( sal_Int32( 0x316AC5 ), getProperty<sal_Int32>(xPropertySet, "BackgroundColor") ); + + // Check Text color (active border system color) + CPPUNIT_ASSERT_EQUAL(sal_Int32(0xD4D0C8), getProperty<sal_Int32>(xPropertySet, "TextColor")); + + // Check state of the checkbox + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), getProperty<sal_Int16>(xPropertySet, "State")); + + // Check anchor type + uno::Reference<beans::XPropertySet> xPropertySet2(xControlShape, uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER,getProperty<text::TextContentAnchorType>(xPropertySet2,"AnchorType")); +} + // tests should only be added to ooxmlIMPORT *if* they fail round-tripping in ooxmlEXPORT CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/writerfilter/source/dmapper/OLEHandler.cxx b/writerfilter/source/dmapper/OLEHandler.cxx index 6dbe0aae2f87..22dcac179034 100644 --- a/writerfilter/source/dmapper/OLEHandler.cxx +++ b/writerfilter/source/dmapper/OLEHandler.cxx @@ -43,6 +43,7 @@ #include <com/sun/star/lang/XComponent.hpp> #include <com/sun/star/lang/XInitialization.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/text/XTextDocument.hpp> #include <com/sun/star/text/WrapTextMode.hpp> #include <com/sun/star/uno/XComponentContext.hpp> @@ -105,6 +106,12 @@ void OLEHandler::lcl_attribute(Id rName, Value & rVal) { uno::Reference< drawing::XShape > xTempShape; rVal.getAny() >>= xTempShape; + + // Control shape is handled on a different code path + uno::Reference< lang::XServiceInfo > xSInfo( xTempShape, uno::UNO_QUERY_THROW ); + if(xSInfo->supportsService("com.sun.star.drawing.ControlShape")) + break; + if( xTempShape.is() ) { m_xShape.set( xTempShape ); diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml index 4eb98b86c6bf..453f15570451 100644 --- a/writerfilter/source/ooxml/model.xml +++ b/writerfilter/source/ooxml/model.xml @@ -12455,17 +12455,6 @@ <ref name="CT_PPrChange"/> </element> </define> - <define name="CT_Control"> - <attribute name="name"> - <data type="string"/> - </attribute> - <attribute name="shapeid"> - <data type="string"/> - </attribute> - <attribute name="r:id"> - <ref name="ST_String"/> - </attribute> - </define> <define name="CT_Background"> <ref name="CT_PictureBase"/> <attribute name="color"> @@ -12496,9 +12485,6 @@ </define> <define name="CT_Object"> <ref name="CT_PictureBase"/> - <element name="control"> - <ref name="CT_Control"/> - </element> <attribute name="dxaOrig"> <data type="string"/> </attribute> @@ -12511,9 +12497,6 @@ <element name="movie"> <ref name="CT_Rel"/> </element> - <element name="control"> - <ref name="CT_Control"/> - </element> </define> <define name="CT_Drawing"> <choice> @@ -17514,11 +17497,6 @@ <element name="sectPr" tokenid="ooxml:CT_PPr_sectPr"/> <element name="pPrChange" tokenid="ooxml:CT_PPr_pPrChange"/> </resource> - <resource name="CT_Control" resource="Properties"> - <attribute name="name" tokenid="ooxml:CT_Control_name"/> - <attribute name="shapeid" tokenid="ooxml:CT_Control_shapeid"/> - <attribute name="r:id" tokenid="ooxml:CT_Control_r_id"/> - </resource> <resource name="CT_Background" resource="Properties"> <attribute name="color" tokenid="ooxml:CT_Background_color"/> <attribute name="themeColor" tokenid="ooxml:CT_Background_themeColor"/> @@ -17531,7 +17509,6 @@ </resource> <resource name="CT_PictureBase" resource="Properties"/> <resource name="CT_Object" resource="Shape"> - <element name="control" tokenid="ooxml:CT_Object_control"/> <attribute name="dxaOrig" tokenid="ooxml:CT_Object_dxaOrig"/> <attribute name="dyaOrig" tokenid="ooxml:CT_Object_dyaOrig"/> <action name="end" action="sendPropertiesWithId" sendtokenid="ooxml:object"/> @@ -17539,7 +17516,6 @@ </resource> <resource name="CT_Picture" resource="Shape"> <element name="movie" tokenid="ooxml:CT_Picture_movie"/> - <element name="control" tokenid="ooxml:CT_Picture_control"/> <action name="end" action="sendPropertiesWithId" sendtokenid="ooxml:object"/> <action name="end" action="clearProps"/> </resource>
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits