oox/source/ole/axcontrol.cxx | 9 +---- oox/source/vml/vmldrawing.cxx | 55 +++++++++++++++++++++++++++++++ sc/qa/unit/subsequent_filters-test.cxx | 51 ++++++++++++++++++++++++++-- sc/source/filter/oox/drawingfragment.cxx | 3 + 4 files changed, 107 insertions(+), 11 deletions(-)
New commits: commit d878b20f968a27a9643da629303bc6880ebfc2c9 Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Sat Sep 29 14:38:31 2018 +0300 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Thu Oct 11 10:36:11 2018 +0200 tdf#111980 oox optionbutton autoGroup inside GroupBox The area of a GroupBox indicates which radio buttons are considered to be part of the same group. The button needs to be fully inside of the groupbox in order to participate. This patch resolves the last worry of commit 9f969799629fe6bdf8b922d8cb922846aa646ece Reviewed-on: https://gerrit.libreoffice.org/61131 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_l...@sil.org> Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> (cherry picked from commit 048b8e45813f6a19a4ff56e1d676fe9450325cd2) Change-Id: Ie6057337c63bf9eb173a0615e30c8d4e4d0c7a19 diff --git a/oox/source/ole/axcontrol.cxx b/oox/source/ole/axcontrol.cxx index bb6fdbc6b1c7..cfe7121ff1f0 100644 --- a/oox/source/ole/axcontrol.cxx +++ b/oox/source/ole/axcontrol.cxx @@ -1555,13 +1555,8 @@ void AxMorphDataModelBase::convertProperties( PropertyMap& rPropMap, const Contr rConv.convertColor( rPropMap, PROP_TextColor, mnTextColor ); if ( mnDisplayStyle == AX_DISPLAYSTYLE_OPTBUTTON ) { - // Form Radio Controls (non-ActiveX) have no group name, but autoGroup - // with their group box, or frame, or sheet, or document. - // So ensure that SOME name is given for a group name - // TODO: ActiveX controls without a Group name shouldn't autogroup - // with non-ActiveX option buttons. - // TODO: each application should test if control's area is fully inside - // a GroupBox, and give those a separate group name. + // If unspecified, radio buttons autoGroup in the same document/sheet + // NOTE: form controls should not autoGroup with ActiveX controls - see drawingfragment.cxx OUString sGroupName = !maGroupName.isEmpty() ? maGroupName : "autoGroup_"; rPropMap.setProperty( PROP_GroupName, sGroupName ); } diff --git a/oox/source/vml/vmldrawing.cxx b/oox/source/vml/vmldrawing.cxx index 57c099c0745d..944047c25b55 100644 --- a/oox/source/vml/vmldrawing.cxx +++ b/oox/source/vml/vmldrawing.cxx @@ -34,6 +34,8 @@ #include <oox/ole/axcontrol.hxx> #include <oox/vml/vmlshape.hxx> #include <oox/vml/vmlshapecontainer.hxx> +#include <tools/diagnose_ex.h> +#include <tools/gen.hxx> namespace oox { namespace vml { @@ -145,6 +147,59 @@ void Drawing::convertAndInsert() const { Reference< XShapes > xShapes( mxDrawPage, UNO_QUERY ); mxShapes->convertAndInsert( xShapes ); + + // Group together form control radio buttons that are in the same groupBox + std::map<OUString, tools::Rectangle> GroupBoxMap; + std::map<Reference< XPropertySet >, tools::Rectangle> RadioButtonMap; + for ( sal_Int32 i = 0; i < xShapes->getCount(); ++i ) + { + try + { + Reference< XControlShape > xCtrlShape( xShapes->getByIndex(i), UNO_QUERY_THROW ); + Reference< XControlModel > xCtrlModel( xCtrlShape->getControl(), UNO_SET_THROW ); + Reference< XServiceInfo > xModelSI (xCtrlModel, UNO_QUERY_THROW ); + Reference< XPropertySet > aProps( xCtrlModel, UNO_QUERY_THROW ); + + OUString sName; + aProps->getPropertyValue("Name") >>= sName; + const ::Point aPoint( xCtrlShape->getPosition().X, xCtrlShape->getPosition().Y ); + const ::Size aSize( xCtrlShape->getSize().Width, xCtrlShape->getSize().Height ); + const tools::Rectangle aRect( aPoint, aSize ); + if ( !sName.isEmpty() + && xModelSI->supportsService("com.sun.star.awt.UnoControlGroupBoxModel") ) + { + GroupBoxMap[sName] = aRect; + } + else if ( xModelSI->supportsService("com.sun.star.awt.UnoControlRadioButtonModel") ) + { + OUString sGroupName; + aProps->getPropertyValue("GroupName") >>= sGroupName; + // only Form Controls are affected by Group Boxes - see drawingfragment.cxx + if ( sGroupName == "autoGroup_formControl" ) + RadioButtonMap[aProps] = aRect; + } + } + catch (uno::Exception&) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + for ( auto& BoxItr : GroupBoxMap ) + { + const uno::Any aGroup( OUString("autoGroup_").concat(BoxItr.first) ); + for ( auto RadioItr = RadioButtonMap.begin(); RadioItr != RadioButtonMap.end(); ) + { + if ( BoxItr.second.IsInside(RadioItr->second) ) + { + RadioItr->first->setPropertyValue("GroupName", aGroup ); + // If conflict, first created GroupBox wins + RadioButtonMap.erase( RadioItr++ ); + } + else + RadioItr++; + } + } + } sal_Int32 Drawing::getLocalShapeIndex( const OUString& rShapeId ) const diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx index 8ff9d539a736..cc6309e63afb 100644 --- a/sc/qa/unit/subsequent_filters-test.cxx +++ b/sc/qa/unit/subsequent_filters-test.cxx @@ -1699,6 +1699,33 @@ void ScFiltersTest::testActiveXOptionButtonGroup() CPPUNIT_ASSERT_EQUAL( sGroupName4, sGroupName5 ); CPPUNIT_ASSERT( sGroupName2 != sGroupName5 ); CPPUNIT_ASSERT( sGroupName != sGroupName5 ); + + OUString sGroupName7; //Form radiobutton autogrouped by GroupBox + xControlShape.set(xIA_DrawPage->getByIndex(7), uno::UNO_QUERY_THROW); + xPropertySet.set(xControlShape->getControl(), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("GroupName") >>= sGroupName7; + CPPUNIT_ASSERT_EQUAL( OUString("autoGroup_Group Box 7"), sGroupName7 ); + + OUString sGroupName8; + xControlShape.set(xIA_DrawPage->getByIndex(8), uno::UNO_QUERY_THROW); + xPropertySet.set(xControlShape->getControl(), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("GroupName") >>= sGroupName8; + CPPUNIT_ASSERT_EQUAL( sGroupName7, sGroupName8 ); + CPPUNIT_ASSERT( sGroupName4 != sGroupName8 ); + CPPUNIT_ASSERT( sGroupName2 != sGroupName8 ); + CPPUNIT_ASSERT( sGroupName != sGroupName8 ); + + OUString sGroupName9; //Form radiobutton not fully inside GroupBox + xControlShape.set(xIA_DrawPage->getByIndex(9), uno::UNO_QUERY_THROW); + xPropertySet.set(xControlShape->getControl(), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("GroupName") >>= sGroupName9; + CPPUNIT_ASSERT_EQUAL( sGroupName4, sGroupName9 ); + + OUString sGroupName10; //ActiveX unaffected by GroupBox + xControlShape.set(xIA_DrawPage->getByIndex(10), uno::UNO_QUERY_THROW); + xPropertySet.set(xControlShape->getControl(), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("GroupName") >>= sGroupName10; + CPPUNIT_ASSERT_EQUAL( sGroupName, sGroupName10 ); } void ScFiltersTest::testChartImportODS() diff --git a/sc/source/filter/oox/drawingfragment.cxx b/sc/source/filter/oox/drawingfragment.cxx index 959ad82408dd..9452a3bbcd4a 100644 --- a/sc/source/filter/oox/drawingfragment.cxx +++ b/sc/source/filter/oox/drawingfragment.cxx @@ -535,7 +535,8 @@ Reference< XShape > VmlDrawing::createAndInsertClientXShape( const ::oox::vml::S case XML_Radio: { AxOptionButtonModel& rAxModel = aControl.createModel< AxOptionButtonModel >(); - // unique name to prevent autoGroping with ActiveX controls. + + // unique name to prevent autoGrouping with ActiveX controls and which a GroupBox may override - see vmldrawing.cxx. rAxModel.maGroupName = "autoGroup_formControl"; convertControlText( rAxModel.maFontData, rAxModel.mnTextColor, rAxModel.maCaption, pTextBox, pClientData->mnTextHAlign ); convertControlBackground( rAxModel, rShape ); commit 080adb39b352dc122c95e4988f67c38a2bf564d3 Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Fri Sep 28 20:41:34 2018 +0300 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Thu Oct 11 10:21:48 2018 +0200 tdf#111980 sc optionbutton autoGroups different for form/activeX This patch only affects calc. (Perhaps .xls* is the only format that supports non-activeX radio buttons?) Commit 9f969799629fe6bdf8b922d8cb922846aa646ece worried about form and activeX buttons sharing the autoGroup_. This patch prevents that. Change-Id: Ia57a14f1cdd6363aa5d6d991469668fcc56016ca Reviewed-on: https://gerrit.libreoffice.org/61095 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_l...@sil.org> (cherry picked from commit a7756236858788b11816cbaba433768ba4ccc72a) diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx index 56cc573a91a1..8ff9d539a736 100644 --- a/sc/qa/unit/subsequent_filters-test.cxx +++ b/sc/qa/unit/subsequent_filters-test.cxx @@ -1671,18 +1671,34 @@ void ScFiltersTest::testActiveXOptionButtonGroup() xPropertySet->getPropertyValue("GroupName") >>= sGroupName; CPPUNIT_ASSERT_EQUAL(OUString("Sheet1"), sGroupName); - // Form optionbuttons (without Group names) were not grouped. + // Optionbuttons (without Group names) were not grouped. // The two optionbuttons should have the same auto-generated group name. + OUString sGroupName2; //ActiveX controls + xControlShape.set(xIA_DrawPage->getByIndex(2), uno::UNO_QUERY_THROW); + xPropertySet.set(xControlShape->getControl(), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("GroupName") >>= sGroupName2; + CPPUNIT_ASSERT_EQUAL( false, sGroupName2.isEmpty() ); + + OUString sGroupName3; + xControlShape.set(xIA_DrawPage->getByIndex(3), uno::UNO_QUERY_THROW); + xPropertySet.set(xControlShape->getControl(), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("GroupName") >>= sGroupName3; + CPPUNIT_ASSERT_EQUAL( sGroupName2, sGroupName3 ); + CPPUNIT_ASSERT( sGroupName != sGroupName3 ); + + OUString sGroupName4; //Form controls xControlShape.set(xIA_DrawPage->getByIndex(4), uno::UNO_QUERY_THROW); xPropertySet.set(xControlShape->getControl(), uno::UNO_QUERY_THROW); - xPropertySet->getPropertyValue("GroupName") >>= sGroupName; - CPPUNIT_ASSERT_EQUAL(false, sGroupName.isEmpty()); + xPropertySet->getPropertyValue("GroupName") >>= sGroupName4; + CPPUNIT_ASSERT_EQUAL( false, sGroupName4.isEmpty() ); OUString sGroupName5; xControlShape.set(xIA_DrawPage->getByIndex(5), uno::UNO_QUERY_THROW); xPropertySet.set(xControlShape->getControl(), uno::UNO_QUERY_THROW); xPropertySet->getPropertyValue("GroupName") >>= sGroupName5; - CPPUNIT_ASSERT_EQUAL(sGroupName, sGroupName5); + CPPUNIT_ASSERT_EQUAL( sGroupName4, sGroupName5 ); + CPPUNIT_ASSERT( sGroupName2 != sGroupName5 ); + CPPUNIT_ASSERT( sGroupName != sGroupName5 ); } void ScFiltersTest::testChartImportODS() diff --git a/sc/source/filter/oox/drawingfragment.cxx b/sc/source/filter/oox/drawingfragment.cxx index 5500f160dd9e..959ad82408dd 100644 --- a/sc/source/filter/oox/drawingfragment.cxx +++ b/sc/source/filter/oox/drawingfragment.cxx @@ -535,6 +535,8 @@ Reference< XShape > VmlDrawing::createAndInsertClientXShape( const ::oox::vml::S case XML_Radio: { AxOptionButtonModel& rAxModel = aControl.createModel< AxOptionButtonModel >(); + // unique name to prevent autoGroping with ActiveX controls. + rAxModel.maGroupName = "autoGroup_formControl"; convertControlText( rAxModel.maFontData, rAxModel.mnTextColor, rAxModel.maCaption, pTextBox, pClientData->mnTextHAlign ); convertControlBackground( rAxModel, rShape ); rAxModel.maValue = OUString::number( pClientData->mnChecked ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits