33#include <com/sun/star/container/XIndexAccess.hpp>
34#include <com/sun/star/form/XFormsSupplier2.hpp>
35#include <com/sun/star/frame/XModel.hpp>
36#include <com/sun/star/xforms/XFormsSupplier.hpp>
37#include <com/sun/star/form/FormComponentType.hpp>
38#include <com/sun/star/lang/XServiceInfo.hpp>
39#include <com/sun/star/script/XEventAttacherManager.hpp>
40#include <com/sun/star/util/NumberFormatsSupplier.hpp>
46#include <com/sun/star/text/XText.hpp>
68 static const OUString s_sControlNumberStyleNamePrefix(
"C");
69 return s_sControlNumberStyleNamePrefix;
74 ,m_pControlNumberStyles(nullptr)
102 Reference< XFormsSupplier2 > xFormsSupp(_rxDrawPage, UNO_QUERY);
103 OSL_ENSURE(xFormsSupp.is(),
"OFormLayerXMLExport_Impl::impl_isFormPageContainingForms: invalid draw page (no XFormsSupplier)! Doin' nothing!");
104 if (!xFormsSupp.is())
107 if ( !xFormsSupp->hasForms() )
111 _rxForms.set(xFormsSupp->getForms(), UNO_QUERY);
112 Reference< XServiceInfo > xSI(_rxForms, UNO_QUERY);
113 OSL_ENSURE(xSI.is(),
"OFormLayerXMLExport_Impl::impl_isFormPageContainingForms: invalid collection (must not be NULL and must have a ServiceInfo)!");
117 if (!xSI->supportsService(
"com.sun.star.form.Forms"))
119 OSL_FAIL(
"OFormLayerXMLExport_Impl::impl_isFormPageContainingForms: invalid collection (is no com.sun.star.form.Forms)!");
127 const Sequence< ScriptEventDescriptor >& _rEvents)
135 const Sequence< ScriptEventDescriptor >& _rEvents)
138 OUString sReferringControls;
141 sReferringControls = aReferring->second;
147 OControlExport aExportImpl(*
this, _rxControl, sControlId, sReferringControls, _rEvents);
152 const Sequence< ScriptEventDescriptor >& _rEvents)
154 OSL_ENSURE(_rxProps.is(),
"OFormLayerXMLExport_Impl::exportForm: invalid property set!");
155 OFormExport aAttributeHandler(*
this, _rxProps, _rEvents);
172 sal_Int32
nElements = _rxCollection->getCount();
174 Reference< XEventAttacherManager > xElementEventManager(_rxCollection, UNO_QUERY);
175 Sequence< ScriptEventDescriptor > aElementEvents;
177 Reference< XPropertySetInfo > xPropsInfo;
183 Reference< XPropertySet > xCurrentProps( _rxCollection->getByIndex(
i), UNO_QUERY );
184 OSL_ENSURE(xCurrentProps.is(),
"OFormLayerXMLExport_Impl::exportCollectionElements: invalid child element, skipping!");
185 if (!xCurrentProps.is())
189 xPropsInfo = xCurrentProps->getPropertySetInfo();
190 OSL_ENSURE(xPropsInfo.is(),
"OFormLayerXMLExport_Impl::exportCollectionElements: no property set info!");
191 if (!xPropsInfo.is())
199 if (xElementEventManager.is())
200 aElementEvents = xElementEventManager->getScriptEvents(
i);
218 "caught an exception ... skipping the current element!");
226 OUString aObjectStyle;
228 MapPropertySet2String::const_iterator aObjectStylePos =
m_aGridColumnStyles.find( _rxObject );
230 aObjectStyle = aObjectStylePos->second;
261 Reference< XIndexAccess > xCollectionIndex;
268 OSL_ENSURE(bPageIsKnown,
"OFormLayerXMLExport_Impl::exportForms: exporting a page which has not been examined!");
282 Reference< XFormsSupplier2 > xFormsSupp( _rxDrawPage, UNO_QUERY );
283 SAL_WARN_IF( !xFormsSupp.is(),
"xmloff",
"OFormLayerXMLExport_Impl::pageContainsForms: no XFormsSupplier2!" );
284 return xFormsSupp.is() && xFormsSupp->hasForms();
289 Reference< css::xforms::XFormsSupplier > xXFormSupp(
m_rContext.
GetModel(), UNO_QUERY );
290 Reference< XNameContainer > xForms;
291 if ( xXFormSupp.is() )
292 xForms = xXFormSupp->getXForms();
293 return xForms.is() && xForms->hasElements();
298 if (!_rxDrawPage.is())
301 bool bKnownPage =
false;
347 Reference< XFormsSupplier2 > xFormsSupp( _rxDrawPage, UNO_QUERY );
348 if ( xFormsSupp.is() && !xFormsSupp->hasForms() )
362 "OFormLayerXMLExport_Impl::getControlId: can not find the control!");
368 OUString sNumberStyle;
371 if ( -1 != nOwnFormatKey )
379 OUString sNumberStyle;
384 OSL_ENSURE(
m_pControlNumberStyles,
"OFormLayerXMLExport_Impl::getControlNumberStyle: have a control which has a format style, but no style exporter!");
396 Reference< XIndexAccess > xCollectionIndex;
404 OSL_ENSURE(!bPageIsKnown,
"OFormLayerXMLExport_Impl::examineForms: examining a page twice!");
406 ::std::stack< Reference< XIndexAccess > > aContainerHistory;
407 ::std::stack< sal_Int32 > aIndexHistory;
409 Reference< XIndexAccess > xLoop = xCollectionIndex;
410 sal_Int32 nChildPos = 0;
413 if (nChildPos < xLoop->getCount())
415 Reference< XPropertySet > xCurrent( xLoop->getByIndex( nChildPos ), UNO_QUERY );
416 OSL_ENSURE(xCurrent.is(),
"OFormLayerXMLExport_Impl::examineForms: invalid child object");
423 Reference< XIndexAccess > xNextContainer(xCurrent, UNO_QUERY);
424 OSL_ENSURE(xNextContainer.is(),
"OFormLayerXMLExport_Impl::examineForms: what the heck is this ... no control, no container?");
425 aContainerHistory.push(xLoop);
426 aIndexHistory.push(nChildPos);
428 xLoop = xNextContainer;
436 while ((nChildPos >= xLoop->getCount()) && !aContainerHistory.empty() )
438 xLoop = aContainerHistory.top();
439 aContainerHistory.pop();
440 nChildPos = aIndexHistory.top();
445 if (nChildPos >= xLoop->getCount())
457 struct AccumulateSize
459 size_t operator()(
size_t _size,
const MapPropertySet2Map::value_type& _map )
const
461 return _size +
_map.second.size();
467 OUString sControlId =
"control";
469 size_t nKnownControlCount = ::std::accumulate( _rAllPagesControlIds.begin(), _rAllPagesControlIds.end(),
size_t(0), AccumulateSize() );
470 sControlId += OUString::number(
static_cast<sal_Int32
>(nKnownControlCount) + 1 );
476 for (
const auto& outer : _rAllPagesControlIds )
477 for (
const auto& inner : outer.second )
479 OSL_ENSURE( inner.second != sControlId,
480 "lcl_findFreeControlId: auto-generated control ID is already used!" );
489 Reference< XPropertySetInfo > xCurrentInfo = _rxObject->getPropertySetInfo();
490 OSL_ENSURE(xCurrentInfo.is(),
"OFormLayerXMLExport_Impl::checkExamineControl: no property set info");
498 OUString sCurrentId = lcl_findFreeControlId(
m_aControlIds );
505 Reference< XPropertySet > xCurrentReference( _rxObject->getPropertyValue(
PROPERTY_CONTROLLABEL ), UNO_QUERY );
506 if (xCurrentReference.is())
509 if (!sReferencedBy.isEmpty())
512 sReferencedBy +=
",";
513 sReferencedBy += sCurrentId;
524 Reference< XText > xControlText( _rxObject, UNO_QUERY );
525 if ( xControlText.is() )
531 sal_Int16 nControlType = FormComponentType::CONTROL;
533 if ( FormComponentType::GRIDCONTROL == nControlType )
547 Reference< XIndexAccess > xContainer( _rxControl, UNO_QUERY );
548 OSL_ENSURE( xContainer.is(),
"OFormLayerXMLExport_Impl::collectGridColumnStylesAndIds: grid control not being a container?!" );
549 if ( !xContainer.is() )
552 Reference< XPropertySetInfo > xColumnPropertiesMeta;
554 sal_Int32
nCount = xContainer->getCount();
557 Reference< XPropertySet > xColumnProperties( xContainer->getByIndex(
i ), UNO_QUERY );
558 OSL_ENSURE( xColumnProperties.is(),
"OFormLayerXMLExport_Impl::collectGridColumnStylesAndIds: invalid grid column encountered!" );
559 if ( !xColumnProperties.is() )
565 OUString sCurrentId = lcl_findFreeControlId(
m_aControlIds );
570 xColumnPropertiesMeta = xColumnProperties->getPropertySetInfo();
575 OUString sColumnNumberStyle;
576 if ( xColumnPropertiesMeta.is() && xColumnPropertiesMeta->hasPropertyByName(
PROPERTY_FORMATKEY ) )
579 if ( !sColumnNumberStyle.isEmpty() )
583 OSL_ENSURE ( -1 != nStyleMapIndex,
"OFormLayerXMLExport_Impl::collectGridColumnStylesAndIds: could not obtain the index for our context id!");
586 aPropertyStates.push_back( aNumberStyleState );
591 if ( !aPropertyStates.empty() )
596 "OFormLayerXMLExport_Impl::collectGridColumnStylesAndIds: already have a style for this column!" );
613 if ( -1 != nOwnFormatKey )
617 return nOwnFormatKey;
624 if ( -1 == nOwnFormatKey )
630 "OFormLayerXMLExport_Impl::examineControlNumberFormat: already handled this control!");
637 OSL_ENSURE(
m_xControlNumberFormats.is(),
"OFormLayerXMLExport_Impl::ensureTranslateFormat: no own formats supplier!");
640 sal_Int32 nOwnFormatKey = -1;
643 sal_Int32 nControlFormatKey = -1;
645 if (aControlFormatKey >>= nControlFormatKey)
648 Reference< XNumberFormatsSupplier > xControlFormatsSupplier;
650 Reference< XNumberFormats > xControlFormats;
651 if (xControlFormatsSupplier.is())
652 xControlFormats = xControlFormatsSupplier->getNumberFormats();
653 OSL_ENSURE(xControlFormats.is(),
"OFormLayerXMLExport_Impl::ensureTranslateFormat: formatted control without supplier!");
657 OUString sFormatDescription;
658 if (xControlFormats.is())
660 Reference< XPropertySet > xControlFormat = xControlFormats->getByKey(nControlFormatKey);
668 if (-1 == nOwnFormatKey)
673 OSL_ENSURE(-1 != nOwnFormatKey,
"OFormLayerXMLExport_Impl::ensureTranslateFormat: could not translate the controls format key!");
676 OSL_ENSURE(!aControlFormatKey.hasValue(),
"OFormLayerXMLExport_Impl::ensureTranslateFormat: invalid number format property value!");
678 return nOwnFormatKey;
687 Reference< XNumberFormatsSupplier > xFormatsSupplier;
689 OSL_ENSURE(!
m_xControlNumberFormats.is(),
"OFormLayerXMLExport_Impl::getControlNumberStyleExport: inconsistence!");
696 Locale aLocale (
"en",
"US", OUString() );
704 OSL_ENSURE(
m_xControlNumberFormats.is(),
"OFormLayerXMLExport_Impl::getControlNumberStyleExport: could not obtain my default number formats!");
718 Reference< XPropertySet > xProps( _rxControl, UNO_QUERY );
719 OSL_ENSURE( xProps.is(),
"OFormLayerXMLExport_Impl::excludeFromExport: invalid control model!" );
720 ::std::pair< PropertySetBag::const_iterator, bool > aPos =
722 OSL_ENSURE( aPos.second,
"OFormLayerXMLExport_Impl::excludeFromExport: element already exists in the ignore list!" );
XMLEventExport & GetEventExport()
get Event export, with handlers for script types "None" and "StarBasic" already registered; other han...
rtl::Reference< XMLTextParagraphExport > const & GetTextParagraphExport()
const css::uno::Reference< css::frame::XModel > & GetModel() const
rtl::Reference< SvXMLAutoStylePoolP > const & GetAutoStylePool()
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
OUString GetStyleName(sal_uInt32 nKey)
void Export(bool bIsAutoStyle)
void SetUsed(sal_uInt32 nKey)
void AddTranslationTable(const XMLEventNameTranslation *pTransTable)
register additional event names
const_iterator find(const Value &x) const
const_iterator end() const
std::pair< const_iterator, bool > insert(Value &&x)
Helper class for exporting a grid column.
Helper class for handling xml elements representing a form control.
#define CTF_FORMS_DATA_STYLE
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
constexpr OUStringLiteral XML_STYLE_FAMILY_CONTROL_PREFIX
#define SAL_WARN_IF(condition, area, stream)
void * _map(void *p, typelib_TypeDescriptionReference *pType, typelib_TypeDescription *pTypeDescr, uno_Mapping *mapping)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
constexpr OUStringLiteral PROPERTY_COLUMNSERVICENAME
::std::unordered_map< css::uno::Reference< css::drawing::XDrawPage >, MapPropertySet2String > MapPropertySet2Map
void initializePropertyMaps()
constexpr OUStringLiteral PROPERTY_CLASSID
const XMLEventNameTranslation * g_pFormsEventTranslation
::std::unordered_map< css::uno::Reference< css::beans::XPropertySet >, OUString > MapPropertySet2String
constexpr OUStringLiteral PROPERTY_CONTROLLABEL
constexpr OUStringLiteral PROPERTY_FORMATSTRING
const XMLPropertyMapEntry * getControlStylePropertyMap()
constexpr OUStringLiteral PROPERTY_LOCALE
constexpr OUStringLiteral PROPERTY_FORMATSSUPPLIER
constexpr OUStringLiteral PROPERTY_FORMATKEY
Smart struct to transport an Any with an index to the appropriate property-name.
const Reference< XComponentContext > & m_rContext