23#include <com/sun/star/beans/XPropertySet.hpp>
24#include <com/sun/star/drawing/XControlShape.hpp>
25#include <com/sun/star/drawing/XDrawPage.hpp>
26#include <com/sun/star/drawing/XShapes.hpp>
27#include <com/sun/star/lang/XMultiServiceFactory.hpp>
28#include <com/sun/star/text/HoriOrientation.hpp>
29#include <com/sun/star/text/RelOrientation.hpp>
30#include <com/sun/star/text/VertOrientation.hpp>
31#include <osl/diagnose.h>
32#include <rtl/ustring.hxx>
53using ::oox::core::XmlFilterBase;
58OUString lclGetShapeId( sal_Int32 nShapeId )
61 static constexpr OUStringLiteral
aStr =
u"\0s";
62 return aStr + OUString::number( nShapeId );
66sal_Int32 lclGetShapeId( std::u16string_view rShapeId )
69 return ((rShapeId.size() >= 3) && (rShapeId[ 0 ] ==
'\0') && (rShapeId[ 1 ] ==
's')) ?
o3tl::toInt32(rShapeId.substr( 2 )) : -1;
76 mbDmlShape( bDmlShape )
86 : mbTextContentShape(false)
101 OSL_ENSURE(
mxDrawPage.is(),
"Drawing::Drawing - missing UNO draw page" );
111 mxCtrlForm.reset( new ::oox::ole::EmbeddedForm(
118 OSL_ENSURE( nBlockId > 0,
"Drawing::registerBlockId - invalid block index" );
122 BlockIdVector::iterator aIt = ::std::lower_bound(
maBlockIds.begin(),
maBlockIds.end(), nBlockId );
123 if( (aIt ==
maBlockIds.end()) || (nBlockId != *aIt) )
130 OSL_ENSURE( !rOleObject.
maShapeId.isEmpty(),
"Drawing::registerOleObject - missing OLE object shape id" );
131 OSL_ENSURE(
maOleObjects.count( rOleObject.
maShapeId ) == 0,
"Drawing::registerOleObject - OLE object already registered" );
137 OSL_ENSURE( !rControl.
maShapeId.isEmpty(),
"Drawing::registerControl - missing form control shape id" );
138 OSL_ENSURE( !rControl.
maName.isEmpty(),
"Drawing::registerControl - missing form control name" );
139 OSL_ENSURE(
maControls.count( rControl.
maShapeId ) == 0,
"Drawing::registerControl - form control already registered" );
151 mxShapes->convertAndInsert( xShapes );
154 std::map<OUString, tools::Rectangle> GroupBoxMap;
156 for ( sal_Int32
i = 0;
i < xShapes->getCount(); ++
i )
160 Reference< XControlShape > xCtrlShape( xShapes->getByIndex(
i), UNO_QUERY );
161 if (!xCtrlShape.is())
163 Reference< XControlModel > xCtrlModel( xCtrlShape->getControl(), UNO_SET_THROW );
164 Reference< XServiceInfo > xModelSI (xCtrlModel, UNO_QUERY_THROW );
165 Reference< XPropertySet > aProps( xCtrlModel, UNO_QUERY_THROW );
168 aProps->getPropertyValue(
"Name") >>=
sName;
169 const ::Point aPoint( xCtrlShape->getPosition().X, xCtrlShape->getPosition().Y );
170 const ::Size aSize( xCtrlShape->getSize().Width, xCtrlShape->getSize().Height );
172 if ( !
sName.isEmpty()
173 && xModelSI->supportsService(
"com.sun.star.awt.UnoControlGroupBoxModel") )
175 GroupBoxMap[
sName] = aRect;
177 else if ( xModelSI->supportsService(
"com.sun.star.awt.UnoControlRadioButtonModel") )
180 aProps->getPropertyValue(
"GroupName") >>= sGroupName;
182 if ( sGroupName ==
"autoGroup_formControl" )
183 RadioButtonMap[aProps] = aRect;
186 catch (uno::Exception&)
191 for (
const auto& BoxItr : GroupBoxMap )
193 const uno::Any aGroup(
"autoGroup_" + BoxItr.first );
194 for (
auto RadioItr = RadioButtonMap.begin(); RadioItr != RadioButtonMap.end(); )
196 if ( BoxItr.second.Contains(RadioItr->second) )
198 RadioItr->first->setPropertyValue(
"GroupName", aGroup );
200 RadioItr = RadioButtonMap.erase(RadioItr);
211 sal_Int32 nShapeId = lclGetShapeId( rShapeId );
212 if( nShapeId <= 0 )
return -1;
235 sal_Int32 nBlockId = (nShapeId - 1) / 1024;
236 BlockIdVector::iterator aIt = ::std::lower_bound(
maBlockIds.begin(),
maBlockIds.end(), nBlockId );
240 if( (aIt ==
maBlockIds.end()) || (*aIt != nBlockId) )
244 sal_Int32 nBlockOffset = (nShapeId - 1) % 1024 + 1;
247 return 1024 *
nIndex + nBlockOffset;
261 const Reference< XShapes >& rxShapes,
const awt::Rectangle& rShapeRect )
const
263 OSL_ENSURE( !rService.isEmpty(),
"Drawing::createAndInsertXShape - missing UNO shape service name" );
264 OSL_ENSURE( rxShapes.is(),
"Drawing::createAndInsertXShape - missing XShapes container" );
265 Reference< XShape > xShape;
266 if( !rService.isEmpty() && rxShapes.is() )
try
269 xShape.set( xModelFactory->createInstance( rService ), UNO_QUERY_THROW );
270 if ( rService !=
"com.sun.star.text.TextFrame" )
273 rxShapes->add( xShape );
274 xShape->setPosition( awt::Point( rShapeRect.X, rShapeRect.Y ) );
278 Reference< XPropertySet > xPropSet( xShape, UNO_QUERY_THROW );
279 xPropSet->setPropertyValue(
"HoriOrient",
Any( HoriOrientation::NONE ) );
280 xPropSet->setPropertyValue(
"VertOrient",
Any( VertOrientation::NONE ) );
281 xPropSet->setPropertyValue(
"HoriOrientPosition",
Any( rShapeRect.X ) );
282 xPropSet->setPropertyValue(
"VertOrientPosition",
Any( rShapeRect.Y ) );
283 xPropSet->setPropertyValue(
"HoriOrientRelation",
Any( RelOrientation::FRAME ) );
284 xPropSet->setPropertyValue(
"VertOrientRelation",
Any( RelOrientation::FRAME ) );
286 xShape->setSize( awt::Size( rShapeRect.Width, rShapeRect.Height ) );
290 TOOLS_WARN_EXCEPTION(
"oox",
"Drawing::createAndInsertXShape - error during shape object creation" );
292 OSL_ENSURE( xShape.is(),
"Drawing::createAndInsertXShape - cannot instantiate shape object" );
297 const Reference< XShapes >& rxShapes,
const awt::Rectangle& rShapeRect, sal_Int32& rnCtrlIndex )
const
299 Reference< XShape > xShape;
309 Reference< XControlShape >( xShape, UNO_QUERY_THROW )->setControl( xCtrlModel );
334 const Reference< XShapes >& ,
const awt::Rectangle& )
const
336 return Reference< XShape >();
340 const awt::Rectangle& ,
const ShapeBase& ,
bool )
static const MapType::mapped_type * getMapElement(const MapType &rMap, const typename MapType::key_type &rKey)
Returns the pointer to an existing element of the passed map, or a null pointer, if an element with t...
const css::uno::Reference< css::frame::XModel > & getModel() const
Returns the document model (always existing).
const css::uno::Reference< css::lang::XMultiServiceFactory > & getModelFactory() const
Returns the service factory provided by the document model (always existing).
GraphicHelper & getGraphicHelper() const
Returns a helper for the handling of graphics and graphic objects.
const ControlInfo * getControlInfo(const OUString &rShapeId) const
Returns the registered info structure for a form control, if extant.
css::uno::Reference< css::drawing::XShape > createAndInsertXShape(const OUString &rService, const css::uno::Reference< css::drawing::XShapes > &rxShapes, const css::awt::Rectangle &rShapeRect) const
Creates a new UNO shape object, inserts it into the passed UNO shape container, and sets the shape po...
virtual bool convertClientAnchor(css::awt::Rectangle &orShapeRect, const OUString &rShapeAnchor) const
Derived classes may calculate the shape rectangle from a non-standard anchor information string.
void registerOleObject(const OleObjectInfo &rOleObject)
Registers the passed embedded OLE object.
void finalizeFragmentImport()
Final processing after import of the fragment.
::oox::ole::EmbeddedForm & getControlForm() const
Returns the form object used to process ActiveX form controls.
void registerControl(const ControlInfo &rControl)
Registers the passed embedded form control.
std::unique_ptr<::oox::ole::EmbeddedForm > mxCtrlForm
The control form used to process embedded controls.
ControlInfoMap maControls
Info about all embedded form controls, mapped by control name.
::oox::core::XmlFilterBase & mrFilter
Filter object that imports/exports the VML drawing.
void convertAndInsert() const
Creates and inserts all UNO shapes into the draw page.
BlockIdVector maBlockIds
Block identifiers used by this drawing.
sal_Int32 getLocalShapeIndex(std::u16string_view rShapeId) const
Returns the local shape index from the passed global shape identifier.
virtual void notifyXShapeInserted(const css::uno::Reference< css::drawing::XShape > &rxShape, const css::awt::Rectangle &rShapeRect, const ShapeBase &rShape, bool bGroupChild)
Derived classes may want to know that a UNO shape has been inserted.
OleObjectInfoMap maOleObjects
Info about all embedded OLE objects, mapped by shape id.
Drawing(::oox::core::XmlFilterBase &rFilter, const css::uno::Reference< css::drawing::XDrawPage > &rxDrawPage, DrawingType eType)
virtual bool isShapeSupported(const ShapeBase &rShape) const
Derived classes may disable conversion of specific shapes.
virtual css::uno::Reference< css::drawing::XShape > createAndInsertClientXShape(const ShapeBase &rShape, const css::uno::Reference< css::drawing::XShapes > &rxShapes, const css::awt::Rectangle &rShapeRect) const
Derived classes create a UNO shape according to the passed shape model.
std::unique_ptr< ShapeContainer > mxShapes
All shapes and shape templates.
void registerBlockId(sal_Int32 nBlockId)
Registers a block of shape identifiers reserved by this drawing.
css::uno::Reference< css::drawing::XShape > createAndInsertXControlShape(const ::oox::ole::EmbeddedControl &rControl, const css::uno::Reference< css::drawing::XShapes > &rxShapes, const css::awt::Rectangle &rShapeRect, sal_Int32 &rnCtrlIndex) const
Creates a new UNO shape object for a form control, inserts the control model into the form,...
const OleObjectInfo * getOleObjectInfo(const OUString &rShapeId) const
Returns the registered info structure for an OLE object, if extant.
css::uno::Reference< css::drawing::XDrawPage > mxDrawPage
UNO draw page used to insert the shapes.
virtual OUString getShapeBaseName(const ShapeBase &rShape) const
Derived classes may return additional base names for automatic shape name creation.
A shape object that is part of a drawing.
Container that holds a list of shapes and shape templates.
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
DrawingType
Enumerates different types of VML drawings.
const PowerPointImport & mrFilter
uno::Reference< drawing::XDrawPage > mxDrawPage
Contains information about a form control embedded in a draw page.
OUString maName
Programmatical name of the form control.
void setShapeId(sal_Int32 nShapeId)
Sets the string representation of the passed numeric shape identifier.
OUString maShapeId
Shape identifier for shape lookup.
Contains information about an OLE object embedded in a draw page.
void setShapeId(sal_Int32 nShapeId)
Sets the string representation of the passed numeric shape identifier.
OUString maShapeId
Shape identifier for shape lookup.