/** Returns the textual representation of a numeric VML shape identifier. */
OUString lclGetShapeId( sal_Int32 nShapeId )
{ // identifier consists of a literal NUL character, a lowercase 's', and the id static constexpr OUStringLiteral aStr = u"\0s"; return aStr + OUString::number( nShapeId );
}
/** Returns the numeric VML shape identifier from its textual representation. */
sal_Int32 lclGetShapeId( std::u16string_view rShapeId )
{ // identifier consists of a literal NUL character, a lowercase 's', and the id return ((rShapeId.size() >= 3) && (rShapeId[ 0 ] == '\0') && (rShapeId[ 1 ] == 's')) ? o3tl::toInt32(rShapeId.substr( 2 )) : -1;
}
// 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 ); if (!xCtrlShape.is()) continue;
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(u"Name"_ustr) >>= 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(u"com.sun.star.awt.UnoControlGroupBoxModel"_ustr) )
{
GroupBoxMap[sName] = aRect;
} elseif ( xModelSI->supportsService(u"com.sun.star.awt.UnoControlRadioButtonModel"_ustr) )
{
OUString sGroupName;
aProps->getPropertyValue(u"GroupName"_ustr) >>= 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("oox.vml");
}
} for ( constauto& BoxItr : GroupBoxMap )
{ const uno::Any aGroup( "autoGroup_" + BoxItr.first ); for ( auto RadioItr = RadioButtonMap.begin(); RadioItr != RadioButtonMap.end(); )
{ if ( BoxItr.second.Contains(RadioItr->second) )
{
RadioItr->first->setPropertyValue(u"GroupName"_ustr, aGroup ); // If conflict, first created GroupBox wins
RadioItr = RadioButtonMap.erase(RadioItr);
} else
++RadioItr;
}
}
/* Shapes in a drawing are counted per registered shape identifier blocks asstoredintheo:idmapelement.Thecontentsofthiselementhave beenstoredinourmembermaBlockIds.Eachblockrepresents1024shape identifiers,startingwithidentifier1fortheblock#0.Thismeans, block#0representstheidentifiers1-1024,block#1representsthe identifiers1025-2048,andsoon.Thelocalshapeindexhastobe calculatedaccordingtoallblocksregisteredforthisdrawing.
// get block id from shape id and find its index in the list of used blocks
sal_Int32 nBlockId = (nShapeId - 1) / 1024;
BlockIdVector::iterator aIt = ::std::lower_bound( maBlockIds.begin(), maBlockIds.end(), nBlockId );
sal_Int32 nIndex = static_cast< sal_Int32 >( aIt - maBlockIds.begin() );
// block id not found in set -> register it now (value of nIndex remains valid) if( (aIt == maBlockIds.end()) || (*aIt != nBlockId) )
maBlockIds.insert( aIt, nBlockId );
// get one-based offset of shape id in its block
sal_Int32 nBlockOffset = (nShapeId - 1) % 1024 + 1;
// calculate the local shape index
sal_Int32 nRet; if (o3tl::checked_add(1024 * nIndex, nBlockOffset, nRet))
{
SAL_WARN("oox", "getLocalShapeIndex: overflow on " << 1024 * nIndex << " + " << nBlockOffset);
nRet = -1;
} return nRet;
}
Reference< XShape > Drawing::createAndInsertXControlShape( const ::oox::ole::EmbeddedControl& rControl, const Reference< XShapes >& rxShapes, const awt::Rectangle& rShapeRect, sal_Int32& rnCtrlIndex ) const
{
Reference< XShape > xShape; try
{ // create control model and insert it into the form of the draw page
Reference< XControlModel > xCtrlModel( getControlForm().convertAndInsert( rControl, rnCtrlIndex ), UNO_SET_THROW );
// create the control shape
xShape = createAndInsertXShape( u"com.sun.star.drawing.ControlShape"_ustr, rxShapes, rShapeRect );
// set the control model at the shape
Reference< XControlShape >( xShape, UNO_QUERY_THROW )->setControl( xCtrlModel );
} catch (Exception const&)
{
TOOLS_WARN_EXCEPTION("oox", "exception inserting Shape");
} return xShape;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.