diff options
author | Tamás Zolnai <tamas.zolnai@collabora.com> | 2017-08-09 16:06:17 +0200 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2017-08-09 19:07:33 +0200 |
commit | 4a764319cbad4e2589cc105145ac27defbf49ff6 (patch) | |
tree | 9e020cfde1025dea3b1b1fc5839bba27b39ddd8e | |
parent | 286c27e805c4501451857abff19c23b3719146a3 (diff) |
tdf#91384: DOCX: import ActiveX controls
Change-Id: Iebf2ff65fcec3231acfc962fb2f1abc2ed2dc67a
Reviewed-on: https://gerrit.libreoffice.org/40930
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
-rw-r--r-- | include/oox/vml/vmldrawing.hxx | 1 | ||||
-rw-r--r-- | include/oox/vml/vmlshapecontext.hxx | 9 | ||||
-rw-r--r-- | oox/source/vml/vmldrawing.cxx | 1 | ||||
-rw-r--r-- | oox/source/vml/vmldrawingfragment.cxx | 3 | ||||
-rw-r--r-- | oox/source/vml/vmlshape.cxx | 13 | ||||
-rw-r--r-- | oox/source/vml/vmlshapecontext.cxx | 14 | ||||
-rw-r--r-- | sw/CppunitTest_sw_ooxmlimport.mk | 3 | ||||
-rwxr-xr-x | sw/qa/extras/ooxmlimport/data/activex_checkbox.docx | bin | 0 -> 13851 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 29 | ||||
-rw-r--r-- | writerfilter/source/ooxml/model.xml | 24 |
10 files changed, 66 insertions, 31 deletions
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 fe7afb417b52..f73055b3355f 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 const & 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 85d6febc73c5..a222af59443c 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 2d03cb7e38e0..b51a9020393f 100644 --- a/oox/source/vml/vmlshape.cxx +++ b/oox/source/vml/vmlshape.cxx @@ -1185,18 +1185,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 eed6154768a1..f49d0ddfae04 100644 --- a/oox/source/vml/vmlshapecontext.cxx +++ b/oox/source/vml/vmlshapecontext.cxx @@ -262,6 +262,9 @@ ContextHandlerRef ShapeContextBase::createShapeContext( ContextHandler2Helper co 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; } @@ -556,6 +559,17 @@ ContextHandlerRef RectangleShapeContext::onCreateContext( sal_Int32 nElement, co return ShapeContext::onCreateContext( nElement, rAttribs ); } +ControlShapeContext::ControlShapeContext( ::oox::core::ContextHandler2Helper const & 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 112231f62a04..4638a3d32c61 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 Binary files differnew file mode 100755 index 000000000000..d7415ef5a5c6 --- /dev/null +++ b/sw/qa/extras/ooxmlimport/data/activex_checkbox.docx diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index bbbf1e65e740..bea70605fdae 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 @@ -1441,6 +1443,33 @@ DECLARE_OOXMLIMPORT_TEST(testGroupShapeFontName, "groupshape-fontname.docx") CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(getRun(getParagraphOfText(1, xText), 1), "CharFontNameAsian")); } +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/ooxml/model.xml b/writerfilter/source/ooxml/model.xml index 49fe6f8f44ad..386d51d7c364 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> @@ -17503,11 +17486,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"/> @@ -17520,7 +17498,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"/> @@ -17528,7 +17505,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> |