From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001
From: Daniel Baumann
Date: Sun, 7 Apr 2024 11:06:44 +0200
Subject: Adding upstream version 4:7.4.7.
Signed-off-by: Daniel Baumann
---
xmloff/source/forms/callbacks.hxx | 79 +
xmloff/source/forms/controlelement.cxx | 87 +
xmloff/source/forms/controlelement.hxx | 88 +
xmloff/source/forms/controlpropertyhdl.cxx | 343 +++
xmloff/source/forms/controlpropertymap.cxx | 119 ++
xmloff/source/forms/controlpropertymap.hxx | 51 +
xmloff/source/forms/elementexport.cxx | 2185 ++++++++++++++++++++
xmloff/source/forms/elementexport.hxx | 311 +++
xmloff/source/forms/elementimport.cxx | 2073 +++++++++++++++++++
xmloff/source/forms/elementimport.hxx | 674 ++++++
xmloff/source/forms/eventexport.cxx | 126 ++
xmloff/source/forms/eventexport.hxx | 71 +
xmloff/source/forms/eventimport.cxx | 135 ++
xmloff/source/forms/eventimport.hxx | 77 +
xmloff/source/forms/formattributes.cxx | 405 ++++
xmloff/source/forms/formattributes.hxx | 414 ++++
xmloff/source/forms/formcellbinding.cxx | 433 ++++
xmloff/source/forms/formcellbinding.hxx | 260 +++
xmloff/source/forms/formenums.cxx | 191 ++
xmloff/source/forms/formenums.hxx | 54 +
xmloff/source/forms/formevents.cxx | 70 +
xmloff/source/forms/formevents.hxx | 30 +
xmloff/source/forms/formlayerexport.cxx | 121 ++
xmloff/source/forms/formlayerimport.cxx | 90 +
xmloff/source/forms/gridcolumnproptranslator.cxx | 299 +++
xmloff/source/forms/gridcolumnproptranslator.hxx | 66 +
.../source/forms/handler/form_handler_factory.cxx | 65 +
xmloff/source/forms/handler/vcl_date_handler.cxx | 93 +
xmloff/source/forms/handler/vcl_date_handler.hxx | 40 +
xmloff/source/forms/handler/vcl_time_handler.cxx | 96 +
xmloff/source/forms/handler/vcl_time_handler.hxx | 40 +
xmloff/source/forms/layerexport.cxx | 727 +++++++
xmloff/source/forms/layerexport.hxx | 299 +++
xmloff/source/forms/layerimport.cxx | 553 +++++
xmloff/source/forms/layerimport.hxx | 175 ++
xmloff/source/forms/logging.cxx | 41 +
xmloff/source/forms/logging.hxx | 59 +
xmloff/source/forms/officeforms.cxx | 177 ++
xmloff/source/forms/officeforms.hxx | 92 +
xmloff/source/forms/property_description.hxx | 103 +
xmloff/source/forms/property_meta_data.cxx | 156 ++
xmloff/source/forms/property_meta_data.hxx | 42 +
xmloff/source/forms/propertyexport.cxx | 683 ++++++
xmloff/source/forms/propertyexport.hxx | 413 ++++
xmloff/source/forms/propertyimport.cxx | 524 +++++
xmloff/source/forms/propertyimport.hxx | 226 ++
xmloff/source/forms/strings.hxx | 209 ++
xmloff/source/forms/valueproperties.cxx | 180 ++
xmloff/source/forms/valueproperties.hxx | 67 +
49 files changed, 13912 insertions(+)
create mode 100644 xmloff/source/forms/callbacks.hxx
create mode 100644 xmloff/source/forms/controlelement.cxx
create mode 100644 xmloff/source/forms/controlelement.hxx
create mode 100644 xmloff/source/forms/controlpropertyhdl.cxx
create mode 100644 xmloff/source/forms/controlpropertymap.cxx
create mode 100644 xmloff/source/forms/controlpropertymap.hxx
create mode 100644 xmloff/source/forms/elementexport.cxx
create mode 100644 xmloff/source/forms/elementexport.hxx
create mode 100644 xmloff/source/forms/elementimport.cxx
create mode 100644 xmloff/source/forms/elementimport.hxx
create mode 100644 xmloff/source/forms/eventexport.cxx
create mode 100644 xmloff/source/forms/eventexport.hxx
create mode 100644 xmloff/source/forms/eventimport.cxx
create mode 100644 xmloff/source/forms/eventimport.hxx
create mode 100644 xmloff/source/forms/formattributes.cxx
create mode 100644 xmloff/source/forms/formattributes.hxx
create mode 100644 xmloff/source/forms/formcellbinding.cxx
create mode 100644 xmloff/source/forms/formcellbinding.hxx
create mode 100644 xmloff/source/forms/formenums.cxx
create mode 100644 xmloff/source/forms/formenums.hxx
create mode 100644 xmloff/source/forms/formevents.cxx
create mode 100644 xmloff/source/forms/formevents.hxx
create mode 100644 xmloff/source/forms/formlayerexport.cxx
create mode 100644 xmloff/source/forms/formlayerimport.cxx
create mode 100644 xmloff/source/forms/gridcolumnproptranslator.cxx
create mode 100644 xmloff/source/forms/gridcolumnproptranslator.hxx
create mode 100644 xmloff/source/forms/handler/form_handler_factory.cxx
create mode 100644 xmloff/source/forms/handler/vcl_date_handler.cxx
create mode 100644 xmloff/source/forms/handler/vcl_date_handler.hxx
create mode 100644 xmloff/source/forms/handler/vcl_time_handler.cxx
create mode 100644 xmloff/source/forms/handler/vcl_time_handler.hxx
create mode 100644 xmloff/source/forms/layerexport.cxx
create mode 100644 xmloff/source/forms/layerexport.hxx
create mode 100644 xmloff/source/forms/layerimport.cxx
create mode 100644 xmloff/source/forms/layerimport.hxx
create mode 100644 xmloff/source/forms/logging.cxx
create mode 100644 xmloff/source/forms/logging.hxx
create mode 100644 xmloff/source/forms/officeforms.cxx
create mode 100644 xmloff/source/forms/officeforms.hxx
create mode 100644 xmloff/source/forms/property_description.hxx
create mode 100644 xmloff/source/forms/property_meta_data.cxx
create mode 100644 xmloff/source/forms/property_meta_data.hxx
create mode 100644 xmloff/source/forms/propertyexport.cxx
create mode 100644 xmloff/source/forms/propertyexport.hxx
create mode 100644 xmloff/source/forms/propertyimport.cxx
create mode 100644 xmloff/source/forms/propertyimport.hxx
create mode 100644 xmloff/source/forms/strings.hxx
create mode 100644 xmloff/source/forms/valueproperties.cxx
create mode 100644 xmloff/source/forms/valueproperties.hxx
(limited to 'xmloff/source/forms')
diff --git a/xmloff/source/forms/callbacks.hxx b/xmloff/source/forms/callbacks.hxx
new file mode 100644
index 000000000..0134152b8
--- /dev/null
+++ b/xmloff/source/forms/callbacks.hxx
@@ -0,0 +1,79 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include
+#include
+#include
+#include
+
+class SvXMLExport;
+class SvXMLExportPropertyMapper;
+
+namespace xmloff
+{
+
+ //= IFormsExportContext
+ class IFormsExportContext
+ {
+ public:
+ virtual SvXMLExport& getGlobalContext() = 0;
+ virtual ::rtl::Reference< SvXMLExportPropertyMapper > getStylePropertyMapper() = 0;
+
+ /** steps through a collection and exports all children of this collection
+ */
+ virtual void exportCollectionElements(
+ const css::uno::Reference< css::container::XIndexAccess >& _rxCollection) = 0;
+
+ virtual OUString getObjectStyleName(
+ const css::uno::Reference< css::beans::XPropertySet >& _rxObject ) = 0;
+
+ protected:
+ ~IFormsExportContext() {}
+ };
+
+ //= IEventAttacherManager
+ class IEventAttacherManager
+ {
+ public:
+ virtual void registerEvents(
+ const css::uno::Reference< css::beans::XPropertySet >& _rxElement,
+ const css::uno::Sequence< css::script::ScriptEventDescriptor >& _rEvents
+ ) = 0;
+
+ protected:
+ ~IEventAttacherManager() {}
+ };
+
+ //= IEventAttacher
+ class IEventAttacher
+ {
+ public:
+ virtual void registerEvents(
+ const css::uno::Sequence< css::script::ScriptEventDescriptor >& _rEvents
+ ) = 0;
+
+ protected:
+ ~IEventAttacher() {}
+ };
+
+} // namespace xmloff
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/forms/controlelement.cxx b/xmloff/source/forms/controlelement.cxx
new file mode 100644
index 000000000..af752ae4b
--- /dev/null
+++ b/xmloff/source/forms/controlelement.cxx
@@ -0,0 +1,87 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "controlelement.hxx"
+#include
+
+using namespace ::xmloff::token;
+
+namespace xmloff
+{
+
+ //= OControlElement
+ const char* OControlElement::getElementName(ElementType _eType)
+ {
+ switch (_eType)
+ {
+ case TEXT: return "text";
+ case TEXT_AREA: return "textarea";
+ case PASSWORD: return "password";
+ case FILE: return "file";
+ case FORMATTED_TEXT: return "formatted-text";
+ case FIXED_TEXT: return "fixed-text";
+ case COMBOBOX: return "combobox";
+ case LISTBOX: return "listbox";
+ case BUTTON: return "button";
+ case IMAGE: return "image";
+ case CHECKBOX: return "checkbox";
+ case RADIO: return "radio";
+ case FRAME: return "frame";
+ case IMAGE_FRAME: return "image-frame";
+ case HIDDEN: return "hidden";
+ case GRID: return "grid";
+ case VALUERANGE: return "value-range";
+ case TIME: return "time";
+ case DATE: return "date";
+
+ default: return "generic-control";
+ }
+ }
+
+ sal_Int32 OControlElement::getElementToken(ElementType _eType)
+ {
+ switch (_eType)
+ {
+ case TEXT: return XML_TEXT;
+ case TEXT_AREA: return XML_TEXTAREA;
+ case PASSWORD: return XML_PASSWORD;
+ case FILE: return XML_FILE;
+ case FORMATTED_TEXT: return XML_FORMATTED_TEXT;
+ case FIXED_TEXT: return XML_FIXED_TEXT;
+ case COMBOBOX: return XML_COMBOBOX;
+ case LISTBOX: return XML_LISTBOX;
+ case BUTTON: return XML_BUTTON;
+ case IMAGE: return XML_IMAGE;
+ case CHECKBOX: return XML_CHECKBOX;
+ case RADIO: return XML_RADIO;
+ case FRAME: return XML_FRAME;
+ case IMAGE_FRAME: return XML_IMAGE_FRAME;
+ case HIDDEN: return XML_HIDDEN;
+ case GRID: return XML_GRID;
+ case VALUERANGE: return XML_VALUE_RANGE;
+ case TIME: return XML_TIME;
+ case DATE: return XML_DATE;
+
+ default: return XML_GENERIC_CONTROL;
+ }
+ }
+
+} // namespace xmloff
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/forms/controlelement.hxx b/xmloff/source/forms/controlelement.hxx
new file mode 100644
index 000000000..df7f12a43
--- /dev/null
+++ b/xmloff/source/forms/controlelement.hxx
@@ -0,0 +1,88 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include
+
+namespace xmloff
+{
+
+ //= OControlElement
+ /** helper for translating between control types and XML tags
+ */
+ class OControlElement
+ {
+ public:
+ enum ElementType
+ {
+ TEXT = 0,
+ TEXT_AREA,
+ PASSWORD,
+ FILE,
+ FORMATTED_TEXT,
+ FIXED_TEXT,
+ COMBOBOX,
+ LISTBOX,
+ BUTTON,
+ IMAGE,
+ CHECKBOX,
+ RADIO,
+ FRAME,
+ IMAGE_FRAME,
+ HIDDEN,
+ GRID,
+ VALUERANGE,
+ GENERIC_CONTROL,
+ TIME,
+ DATE,
+
+ UNKNOWN // must be the last element
+ };
+
+ protected:
+ /** ctor.
+ This default constructor is protected, 'cause this class is not intended to be instantiated
+ directly. Instead, the derived classes should be used.
+ */
+ OControlElement() { }
+
+ public:
+ /** retrieves the tag name to be used to describe a control of the given type
+
+ The returned string is the pure element name, without any namespace.
+
+ @param _eType
+ the element type
+ */
+ static const char* getElementName(ElementType _eType);
+
+ /** retrieves the tag name to be used to describe a control of the given type
+
+ The returned string is the pure token, without any namespace.
+
+ @param _eType
+ the element type
+ */
+ static sal_Int32 getElementToken(ElementType _eType);
+ };
+
+} // namespace xmloff
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/forms/controlpropertyhdl.cxx b/xmloff/source/forms/controlpropertyhdl.cxx
new file mode 100644
index 000000000..cb3badee2
--- /dev/null
+++ b/xmloff/source/forms/controlpropertyhdl.cxx
@@ -0,0 +1,343 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include
+
+#include
+#include
+#include
+
+#include
+
+#include
+#include
+#include "formenums.hxx"
+#include
+#include
+#include
+#include
+
+namespace xmloff
+{
+
+ using namespace ::com::sun::star;
+ using namespace ::com::sun::star::uno;
+ using namespace ::com::sun::star::awt;
+ using namespace ::com::sun::star::beans;
+ using namespace ::xmloff::token;
+
+ //= OControlPropertyHandlerFactory
+ OControlPropertyHandlerFactory::OControlPropertyHandlerFactory()
+ {
+ }
+
+ const XMLPropertyHandler* OControlPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType) const
+ {
+ const XMLPropertyHandler* pHandler = nullptr;
+
+ switch (_nType)
+ {
+ case XML_TYPE_TEXT_ALIGN:
+ if (!m_pTextAlignHandler)
+ m_pTextAlignHandler = std::make_unique(aTextAlignMap, XML_TOKEN_INVALID );
+ pHandler = m_pTextAlignHandler.get();
+ break;
+
+ case XML_TYPE_CONTROL_BORDER:
+ if (!m_pControlBorderStyleHandler)
+ m_pControlBorderStyleHandler = std::make_unique( OControlBorderHandler::STYLE );
+ pHandler = m_pControlBorderStyleHandler.get();
+ break;
+
+ case XML_TYPE_CONTROL_BORDER_COLOR:
+ if ( !m_pControlBorderColorHandler )
+ m_pControlBorderColorHandler = std::make_unique( OControlBorderHandler::COLOR );
+ pHandler = m_pControlBorderColorHandler.get();
+ break;
+
+ case XML_TYPE_ROTATION_ANGLE:
+ if (!m_pRotationAngleHandler)
+ m_pRotationAngleHandler = std::make_unique();
+ pHandler = m_pRotationAngleHandler.get();
+ break;
+
+ case XML_TYPE_FONT_WIDTH:
+ if (!m_pFontWidthHandler)
+ m_pFontWidthHandler = std::make_unique();
+ pHandler = m_pFontWidthHandler.get();
+ break;
+
+ case XML_TYPE_CONTROL_TEXT_EMPHASIZE:
+ if (!m_pFontEmphasisHandler)
+ m_pFontEmphasisHandler = std::make_unique( aFontEmphasisMap, XML_NONE );
+ pHandler = m_pFontEmphasisHandler.get();
+ break;
+
+ case XML_TYPE_TEXT_FONT_RELIEF:
+ if (!m_pFontReliefHandler)
+ m_pFontReliefHandler = std::make_unique( aFontReliefMap, XML_NONE );
+ pHandler = m_pFontReliefHandler.get();
+ break;
+ case XML_TYPE_TEXT_LINE_MODE:
+ if (!m_pTextLineModeHandler)
+ {
+ m_pTextLineModeHandler = std::make_unique(
+ ::xmloff::token::XML_SKIP_WHITE_SPACE,
+ ::xmloff::token::XML_CONTINUOUS);
+ }
+ pHandler = m_pTextLineModeHandler.get();
+ break;
+ }
+
+ if (!pHandler)
+ pHandler = XMLPropertyHandlerFactory::GetPropertyHandler(_nType);
+ return pHandler;
+ }
+
+ //= OControlTextEmphasisHandler
+ OControlTextEmphasisHandler::OControlTextEmphasisHandler()
+ {
+ }
+
+ bool OControlTextEmphasisHandler::exportXML( OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
+ {
+ bool bSuccess = false;
+ sal_Int16 nFontEmphasis = sal_Int16();
+ if (_rValue >>= nFontEmphasis)
+ {
+ // the type
+ sal_uInt16 nType = nFontEmphasis & ~(awt::FontEmphasisMark::ABOVE | awt::FontEmphasisMark::BELOW);
+ // the position of the mark
+ bool bBelow = 0 != (nFontEmphasis & awt::FontEmphasisMark::BELOW);
+
+ // convert
+ OUStringBuffer aReturn;
+ bSuccess = SvXMLUnitConverter::convertEnum(aReturn, nType, aFontEmphasisMap, XML_NONE);
+ if (bSuccess)
+ {
+ aReturn.append( ' ' );
+ aReturn.append( GetXMLToken(bBelow ? XML_BELOW : XML_ABOVE) );
+
+ _rStrExpValue = aReturn.makeStringAndClear();
+ }
+ }
+
+ return bSuccess;
+ }
+
+ bool OControlTextEmphasisHandler::importXML( const OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
+ {
+ bool bSuccess = true;
+ sal_uInt16 nEmphasis = awt::FontEmphasisMark::NONE;
+
+ bool bBelow = false;
+ bool bHasPos = false, bHasType = false;
+
+ std::u16string_view sToken;
+ SvXMLTokenEnumerator aTokenEnum(_rStrImpValue);
+ while (aTokenEnum.getNextToken(sToken))
+ {
+ if (!bHasPos)
+ {
+ if (IsXMLToken(sToken, XML_ABOVE))
+ {
+ bBelow = false;
+ bHasPos = true;
+ }
+ else if (IsXMLToken(sToken, XML_BELOW))
+ {
+ bBelow = true;
+ bHasPos = true;
+ }
+ }
+ if (!bHasType)
+ {
+ if (SvXMLUnitConverter::convertEnum(nEmphasis, sToken, aFontEmphasisMap))
+ {
+ bHasType = true;
+ }
+ else
+ {
+ bSuccess = false;
+ break;
+ }
+ }
+ }
+
+ if (bSuccess)
+ {
+ nEmphasis |= bBelow ? awt::FontEmphasisMark::BELOW : awt::FontEmphasisMark::ABOVE;
+ _rValue <<= nEmphasis;
+ }
+
+ return bSuccess;
+ }
+
+ //= OControlBorderHandlerBase
+ OControlBorderHandler::OControlBorderHandler( const OControlBorderHandler::BorderFacet _eFacet )
+ :m_eFacet( _eFacet )
+ {
+ }
+
+ bool OControlBorderHandler::importXML( const OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
+ {
+ std::u16string_view sToken;
+ SvXMLTokenEnumerator aTokens(_rStrImpValue);
+
+ sal_uInt16 nStyle = 1;
+
+ while ( aTokens.getNextToken(sToken) // have a new token
+ && (!sToken.empty()) // really have a new token
+ )
+ {
+ // try interpreting the token as border style
+ if ( m_eFacet == STYLE )
+ {
+ // is it a valid enum value?
+ if ( SvXMLUnitConverter::convertEnum( nStyle, sToken, aBorderTypeMap ) )
+ {
+ _rValue <<= nStyle;
+ return true;
+ }
+ }
+
+ // try interpreting it as color value
+ if ( m_eFacet == COLOR )
+ {
+ sal_Int32 nColor(0);
+ if (::sax::Converter::convertColor( nColor, sToken ))
+ {
+ _rValue <<= nColor;
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ bool OControlBorderHandler::exportXML( OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
+ {
+ bool bSuccess = false;
+
+ OUStringBuffer aOut;
+ switch ( m_eFacet )
+ {
+ case STYLE:
+ {
+ sal_uInt16 nBorder = 0;
+ bSuccess = (_rValue >>= nBorder)
+ && SvXMLUnitConverter::convertEnum( aOut, nBorder, aBorderTypeMap );
+ }
+ break;
+ case COLOR:
+ {
+ sal_Int32 nBorderColor = 0;
+ if ( _rValue >>= nBorderColor )
+ {
+ ::sax::Converter::convertColor(aOut, nBorderColor);
+ bSuccess = true;
+ }
+ }
+ break;
+ } // switch ( m_eFacet )
+
+ if ( !bSuccess )
+ return false;
+
+ if ( !_rStrExpValue.isEmpty() )
+ _rStrExpValue += " ";
+ _rStrExpValue += aOut;
+
+ return true;
+ }
+
+ //= OFontWidthHandler
+ OFontWidthHandler::OFontWidthHandler()
+ {
+ }
+
+ bool OFontWidthHandler::importXML( const OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
+ {
+ sal_Int32 nWidth = 0;
+ bool const bSuccess = ::sax::Converter::convertMeasure(
+ nWidth, _rStrImpValue, util::MeasureUnit::POINT);
+ if (bSuccess)
+ _rValue <<= static_cast(nWidth);
+
+ return bSuccess;
+ }
+
+ bool OFontWidthHandler::exportXML( OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
+ {
+ sal_Int16 nWidth = 0;
+ OUStringBuffer aResult;
+ if (_rValue >>= nWidth)
+ {
+ ::sax::Converter::convertMeasure(aResult, nWidth,
+ util::MeasureUnit::POINT, util::MeasureUnit::POINT);
+ }
+ _rStrExpValue = aResult.makeStringAndClear();
+
+ return !_rStrExpValue.isEmpty();
+ }
+
+ //= ORotationAngleHandler
+ ORotationAngleHandler::ORotationAngleHandler()
+ {
+ }
+
+ bool ORotationAngleHandler::importXML( const OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
+ {
+ double fValue;
+ bool const bSucces =
+ ::sax::Converter::convertDouble(fValue, _rStrImpValue);
+ if (bSucces)
+ {
+ fValue *= 10;
+ _rValue <<= static_cast(fValue);
+ }
+
+ return bSucces;
+ }
+
+ bool ORotationAngleHandler::exportXML( OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
+ {
+ float fAngle = 0;
+ bool bSuccess = (_rValue >>= fAngle);
+
+ if (bSuccess)
+ {
+ OUStringBuffer sValue;
+ ::sax::Converter::convertDouble(sValue, static_cast(fAngle) / 10);
+ _rStrExpValue = sValue.makeStringAndClear();
+ }
+
+ return bSuccess;
+ }
+
+ //= ImageScaleModeHandler
+ ImageScaleModeHandler::ImageScaleModeHandler()
+ :XMLConstantsPropertyHandler( aScaleModeMap, XML_STRETCH )
+ {
+ }
+
+} // namespace xmloff
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/forms/controlpropertymap.cxx b/xmloff/source/forms/controlpropertymap.cxx
new file mode 100644
index 000000000..d0716bd8d
--- /dev/null
+++ b/xmloff/source/forms/controlpropertymap.cxx
@@ -0,0 +1,119 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include "strings.hxx"
+#include
+#include "controlpropertymap.hxx"
+
+#include
+
+using namespace ::xmloff::token;
+
+namespace xmloff
+{
+
+#define MAP_ASCII( name, prefix, token, type, context ) { name, prefix, token, type|XML_TYPE_PROP_TEXT, context, SvtSaveOptions::ODFSVER_010, false }
+#define MAP_CONST( name, prefix, token, type, context ) { name, prefix, token, type|XML_TYPE_PROP_TEXT, context, SvtSaveOptions::ODFSVER_010, false }
+#define MAP_CONST_P( name, prefix, token, type, context ){ name, prefix, token, type|XML_TYPE_PROP_PARAGRAPH, context, SvtSaveOptions::ODFSVER_010, false }
+#define MAP_END() { nullptr, 0, XML_TOKEN_INVALID, 0, 0, SvtSaveOptions::ODFSVER_010, false }
+
+ XMLPropertyMapEntry const aControlStyleProperties[] =
+ {
+ MAP_CONST_P( PROPERTY_ALIGN, XML_NAMESPACE_FO, XML_TEXT_ALIGN, XML_TYPE_TEXT_ALIGN, 0 ),
+ MAP_CONST( PROPERTY_BACKGROUNDCOLOR, XML_NAMESPACE_FO, XML_BACKGROUND_COLOR, XML_TYPE_COLOR, 0 ),
+ MAP_CONST( PROPERTY_BORDER, XML_NAMESPACE_FO, XML_BORDER, XML_TYPE_CONTROL_BORDER|MID_FLAG_MULTI_PROPERTY|MID_FLAG_MERGE_ATTRIBUTE, 0 ),
+ MAP_ASCII( "BorderColor", XML_NAMESPACE_FO, XML_BORDER, XML_TYPE_CONTROL_BORDER_COLOR|MID_FLAG_MULTI_PROPERTY|MID_FLAG_MERGE_ATTRIBUTE, 0 ),
+ MAP_ASCII( "FontCharWidth", XML_NAMESPACE_STYLE, XML_FONT_CHAR_WIDTH, XML_TYPE_NUMBER16, 0 ),
+ MAP_ASCII( "FontCharset", XML_NAMESPACE_STYLE, XML_FONT_CHARSET, XML_TYPE_TEXT_FONTENCODING, 0 ),
+ MAP_ASCII( "FontEmphasisMark", XML_NAMESPACE_STYLE, XML_TEXT_EMPHASIZE, XML_TYPE_CONTROL_TEXT_EMPHASIZE, 0 ),
+ MAP_ASCII( "FontFamily", XML_NAMESPACE_STYLE, XML_FONT_FAMILY_GENERIC, XML_TYPE_TEXT_FONTFAMILY, 0 ),
+ MAP_ASCII( "FontHeight", XML_NAMESPACE_FO, XML_FONT_SIZE, XML_TYPE_CHAR_HEIGHT, 0 ),
+ MAP_ASCII( "FontKerning", XML_NAMESPACE_STYLE, XML_LETTER_KERNING, XML_TYPE_BOOL, 0 ),
+ MAP_ASCII( "FontName", XML_NAMESPACE_STYLE, XML_FONT_NAME, XML_TYPE_STRING, 0 ),
+ MAP_ASCII( "FontOrientation", XML_NAMESPACE_STYLE, XML_ROTATION_ANGLE, XML_TYPE_ROTATION_ANGLE, 0 ),
+ MAP_ASCII( "FontPitch", XML_NAMESPACE_STYLE, XML_FONT_PITCH, XML_TYPE_TEXT_FONTPITCH, 0 ),
+ MAP_ASCII( "FontRelief", XML_NAMESPACE_STYLE, XML_FONT_RELIEF, XML_TYPE_TEXT_FONT_RELIEF|MID_FLAG_MULTI_PROPERTY, 0 ),
+ MAP_ASCII( "FontSlant", XML_NAMESPACE_FO, XML_FONT_STYLE, XML_TYPE_TEXT_POSTURE, 0 ),
+
+ MAP_ASCII( "FontStrikeout", XML_NAMESPACE_STYLE, XML_TEXT_LINE_THROUGH_STYLE, XML_TYPE_TEXT_CROSSEDOUT_STYLE|MID_FLAG_MERGE_PROPERTY, 0),
+ MAP_ASCII( "FontStrikeout", XML_NAMESPACE_STYLE, XML_TEXT_LINE_THROUGH_TYPE, XML_TYPE_TEXT_CROSSEDOUT_TYPE|MID_FLAG_MERGE_PROPERTY, 0),
+ MAP_ASCII( "FontStrikeout", XML_NAMESPACE_STYLE, XML_TEXT_LINE_THROUGH_WIDTH, XML_TYPE_TEXT_CROSSEDOUT_WIDTH|MID_FLAG_MERGE_PROPERTY, 0),
+ MAP_ASCII( "FontStrikeout", XML_NAMESPACE_STYLE, XML_TEXT_LINE_THROUGH_TEXT, XML_TYPE_TEXT_CROSSEDOUT_TEXT|MID_FLAG_MERGE_PROPERTY, 0),
+
+ MAP_ASCII( "FontStyleName", XML_NAMESPACE_STYLE, XML_FONT_STYLE_NAME, XML_TYPE_STRING, 0 ),
+ MAP_ASCII( "FontUnderline", XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_STYLE, XML_TYPE_TEXT_UNDERLINE_STYLE|MID_FLAG_MERGE_PROPERTY, 0 ),
+ MAP_ASCII( "FontUnderline", XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_TYPE, XML_TYPE_TEXT_UNDERLINE_TYPE|MID_FLAG_MERGE_PROPERTY, 0 ),
+ MAP_ASCII( "FontUnderline", XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_WIDTH, XML_TYPE_TEXT_UNDERLINE_WIDTH|MID_FLAG_MERGE_PROPERTY, 0 ),
+ MAP_ASCII( "FontWeight", XML_NAMESPACE_FO, XML_FONT_WEIGHT, XML_TYPE_TEXT_WEIGHT, 0 ),
+ MAP_ASCII( "FontWidth", XML_NAMESPACE_STYLE, XML_FONT_WIDTH, XML_TYPE_FONT_WIDTH, 0 ),
+ MAP_ASCII( "FontWordLineMode", XML_NAMESPACE_FO, XML_SCORE_SPACES, XML_TYPE_NBOOL, 0 ),
+
+ MAP_CONST( PROPERTY_FORMATKEY, XML_NAMESPACE_STYLE, XML_DATA_STYLE_NAME, XML_TYPE_STRING | MID_FLAG_NO_PROPERTY_EXPORT | MID_FLAG_SPECIAL_ITEM, CTF_FORMS_DATA_STYLE ),
+
+ MAP_ASCII( "SymbolColor", XML_NAMESPACE_STYLE, XML_COLOR, XML_TYPE_COLOR, 0 ),
+ MAP_ASCII( "TextColor", XML_NAMESPACE_FO, XML_COLOR, XML_TYPE_COLOR, 0 ),
+ MAP_ASCII( "TextLineColor", XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_COLOR, XML_TYPE_TEXT_UNDERLINE_COLOR|MID_FLAG_MULTI_PROPERTY, 0 ),
+ MAP_END()
+ };
+
+ const XMLPropertyMapEntry* getControlStylePropertyMap( )
+ {
+ return aControlStyleProperties;
+ }
+
+ void initializePropertyMaps()
+ {
+ static bool bSorted = false;
+ if (!bSorted)
+ {
+ XMLPropertyMapEntry const * pEnd;
+ // determine the last element
+ for ( pEnd = aControlStyleProperties; pEnd->msApiName; ++pEnd)
+ ;
+ assert( ::std::is_sorted(aControlStyleProperties, pEnd,
+ [](const XMLPropertyMapEntry& _rLeft, const XMLPropertyMapEntry& _rRight)
+ { return strcmp(_rLeft.msApiName, _rRight.msApiName) < 0; }) );
+ bSorted = true;
+ }
+ }
+
+ //= OFormComponentStyleExportMapper
+ OFormComponentStyleExportMapper::OFormComponentStyleExportMapper( const rtl::Reference< XMLPropertySetMapper >& _rMapper )
+ :SvXMLExportPropertyMapper( _rMapper )
+ {
+ }
+
+ void OFormComponentStyleExportMapper::handleSpecialItem( SvXMLAttributeList& _rAttrList, const XMLPropertyState& _rProperty, const SvXMLUnitConverter& _rUnitConverter,
+ const SvXMLNamespaceMap& _rNamespaceMap, const ::std::vector< XMLPropertyState >* _pProperties,
+ sal_uInt32 _nIdx ) const
+ {
+ // ignore the number style of grid columns - this is formatted elsewhere
+ if ( CTF_FORMS_DATA_STYLE != getPropertySetMapper()->GetEntryContextId( _rProperty.mnIndex ) )
+ SvXMLExportPropertyMapper::handleSpecialItem( _rAttrList, _rProperty, _rUnitConverter, _rNamespaceMap, _pProperties, _nIdx );
+ }
+
+} // namespace xmloff
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/forms/controlpropertymap.hxx b/xmloff/source/forms/controlpropertymap.hxx
new file mode 100644
index 000000000..ff575c137
--- /dev/null
+++ b/xmloff/source/forms/controlpropertymap.hxx
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include
+#include
+
+struct XMLPropertyMapEntry;
+namespace xmloff
+{
+
+ const XMLPropertyMapEntry* getControlStylePropertyMap( );
+
+ void initializePropertyMaps();
+
+ //= OFormComponentStyleExportMapper
+ class OFormComponentStyleExportMapper : public SvXMLExportPropertyMapper
+ {
+ public:
+ explicit OFormComponentStyleExportMapper( const rtl::Reference< XMLPropertySetMapper >& _rMapper );
+
+ void handleSpecialItem(
+ SvXMLAttributeList& _rAttrList,
+ const XMLPropertyState& _rProperty,
+ const SvXMLUnitConverter& _rUnitConverter,
+ const SvXMLNamespaceMap& _rNamespaceMap,
+ const ::std::vector< XMLPropertyState >* _pProperties,
+ sal_uInt32 _nIdx
+ ) const override;
+ };
+
+} // namespace xmloff
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/forms/elementexport.cxx b/xmloff/source/forms/elementexport.cxx
new file mode 100644
index 000000000..72cb6e0ef
--- /dev/null
+++ b/xmloff/source/forms/elementexport.cxx
@@ -0,0 +1,2185 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "elementexport.hxx"
+
+#include "strings.hxx"
+#include
+#include "eventexport.hxx"
+#include "formenums.hxx"
+#include "formcellbinding.hxx"
+#include
+#include "property_meta_data.hxx"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+namespace xmloff
+{
+
+ #if OSL_DEBUG_LEVEL > 0
+ #define RESET_BIT( bitfield, bit ) \
+ bitfield = bitfield & ~bit
+ #else
+ #define RESET_BIT( bitfield, bit )
+ #endif
+
+ using namespace ::xmloff::token;
+ using namespace ::com::sun::star;
+ using namespace ::com::sun::star::uno;
+ using namespace ::com::sun::star::sdb;
+ using namespace ::com::sun::star::awt;
+ using namespace ::com::sun::star::form;
+ using namespace ::com::sun::star::lang;
+ using namespace ::com::sun::star::beans;
+ using namespace ::com::sun::star::container;
+ using namespace ::com::sun::star::script;
+ using namespace ::com::sun::star::io;
+ using namespace ::com::sun::star::table;
+ using namespace ::com::sun::star::text;
+ using namespace ::com::sun::star::form::binding;
+
+ //= OElementExport
+ OElementExport::OElementExport(IFormsExportContext& _rContext, const Reference< XPropertySet >& _rxProps,
+ const Sequence< ScriptEventDescriptor >& _rEvents)
+ :OPropertyExport(_rContext, _rxProps)
+ ,m_aEvents(_rEvents)
+ {
+ }
+
+ OElementExport::~OElementExport()
+ {
+ }
+
+ void OElementExport::doExport()
+ {
+ // collect some general information about the element
+ examine();
+
+ // first add the attributes necessary for the element
+ m_rContext.getGlobalContext().ClearAttrList();
+
+ // add the attributes
+ exportAttributes();
+
+ // start the XML element
+ implStartElement(getXMLElementName());
+
+ // the sub elements (mostly control type dependent)
+ exportSubTags();
+
+ implEndElement();
+ }
+
+ void OElementExport::examine()
+ {
+ // nothing to do here
+ }
+
+ void OElementExport::exportAttributes()
+ {
+ // nothing to do here
+ }
+
+ void OElementExport::exportSubTags()
+ {
+ // the properties which where not exported 'til now
+ exportRemainingProperties();
+
+ // the script:events sub tags
+ exportEvents();
+ }
+
+ void OElementExport::implStartElement(const char* _pName)
+ {
+ m_pXMLElement = std::make_unique(m_rContext.getGlobalContext(), XML_NAMESPACE_FORM, _pName, true, true);
+ }
+
+ void OElementExport::implEndElement()
+ {
+ m_pXMLElement.reset();
+ }
+
+ void OElementExport::exportServiceNameAttribute()
+ {
+ Reference< XPersistObject > xPersistence(m_xProps, UNO_QUERY);
+ if (!xPersistence.is())
+ {
+ OSL_FAIL("OElementExport::exportServiceNameAttribute: no XPersistObject!");
+ return;
+ }
+
+ OUString sServiceName = xPersistence->getServiceName();
+ // we don't want to write the old service name directly: it's a name used for compatibility reasons, but
+ // as we start some kind of new file format here (with this xml export), we don't care about
+ // compatibility ...
+ // So we translate the old persistence service name into new ones, if possible
+
+ OUString sToWriteServiceName = sServiceName;
+#define CHECK_N_TRANSLATE( name ) \
+ else if (sServiceName == SERVICE_PERSISTENT_COMPONENT_##name) \
+ sToWriteServiceName = SERVICE_##name
+
+ if (sServiceName == SERVICE_PERSISTENT_COMPONENT_EDIT)
+ {
+ // special handling for the edit field: we have two controls using this as persistence service name
+ sToWriteServiceName = SERVICE_EDIT;
+ Reference< XServiceInfo > xSI(m_xProps, UNO_QUERY);
+ if (xSI.is() && xSI->supportsService(SERVICE_FORMATTEDFIELD))
+ sToWriteServiceName = SERVICE_FORMATTEDFIELD;
+ }
+ CHECK_N_TRANSLATE( FORM );
+ CHECK_N_TRANSLATE( LISTBOX );
+ CHECK_N_TRANSLATE( COMBOBOX );
+ CHECK_N_TRANSLATE( RADIOBUTTON );
+ CHECK_N_TRANSLATE( GROUPBOX );
+ CHECK_N_TRANSLATE( FIXEDTEXT );
+ CHECK_N_TRANSLATE( COMMANDBUTTON );
+ CHECK_N_TRANSLATE( CHECKBOX );
+ CHECK_N_TRANSLATE( GRID );
+ CHECK_N_TRANSLATE( IMAGEBUTTON );
+ CHECK_N_TRANSLATE( FILECONTROL );
+ CHECK_N_TRANSLATE( TIMEFIELD );
+ CHECK_N_TRANSLATE( DATEFIELD );
+ CHECK_N_TRANSLATE( NUMERICFIELD );
+ CHECK_N_TRANSLATE( CURRENCYFIELD );
+ CHECK_N_TRANSLATE( PATTERNFIELD );
+ CHECK_N_TRANSLATE( HIDDENCONTROL );
+ CHECK_N_TRANSLATE( IMAGECONTROL );
+ CHECK_N_TRANSLATE( FORMATTEDFIELD );
+#if OSL_DEBUG_LEVEL > 0
+ Reference< XServiceInfo > xSI(m_xProps, UNO_QUERY);
+ OSL_ENSURE(xSI.is() && xSI->supportsService(sToWriteServiceName),
+ "OElementExport::exportServiceNameAttribute: wrong service name translation!");
+
+#endif
+ sToWriteServiceName =
+ m_rContext.getGlobalContext().GetNamespaceMap().GetQNameByKey(
+ XML_NAMESPACE_OOO, sToWriteServiceName );
+
+ // now write this
+ AddAttribute(
+ OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::ServiceName),
+ OAttributeMetaData::getCommonControlAttributeName(CCAFlags::ServiceName),
+ sToWriteServiceName);
+ }
+
+ void OElementExport::exportEvents()
+ {
+ if (!m_aEvents.hasElements())
+ // nothing to do
+ return;
+
+ Reference< XNameReplace > xWrapper = new OEventDescriptorMapper(m_aEvents);
+ m_rContext.getGlobalContext().GetEventExport().Export(xWrapper);
+ }
+
+ //= OControlExport
+ OControlExport::OControlExport(IFormsExportContext& _rContext, const Reference< XPropertySet >& _rxControl,
+ const OUString& _rControlId, const OUString& _rReferringControls,
+ const Sequence< ScriptEventDescriptor >& _rEvents)
+ :OElementExport(_rContext, _rxControl, _rEvents)
+ ,m_sControlId(_rControlId)
+ ,m_sReferringControls(_rReferringControls)
+ ,m_nClassId(FormComponentType::CONTROL)
+ ,m_eType( UNKNOWN )
+ ,m_nIncludeCommon(CCAFlags::NONE)
+ ,m_nIncludeDatabase(DAFlags::NONE)
+ ,m_nIncludeSpecial(SCAFlags::NONE)
+ ,m_nIncludeEvents(EAFlags::NONE)
+ ,m_nIncludeBindings(BAFlags::NONE)
+ {
+ OSL_ENSURE(m_xProps.is(), "OControlExport::OControlExport: invalid arguments!");
+ }
+
+ void OControlExport::exportOuterAttributes()
+ {
+ // the control id
+ if (CCAFlags::Name & m_nIncludeCommon)
+ {
+ exportStringPropertyAttribute(
+ OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::Name),
+ OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Name),
+ PROPERTY_NAME
+ );
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~CCAFlags::Name;
+ #endif
+ }
+
+ // the service name
+ if (m_nIncludeCommon & CCAFlags::ServiceName)
+ {
+ exportServiceNameAttribute();
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~CCAFlags::ServiceName;
+ #endif
+ }
+ }
+
+ void OControlExport::exportInnerAttributes()
+ {
+ // the control id
+ if (CCAFlags::ControlId & m_nIncludeCommon)
+ {
+ OSL_ENSURE(!m_sControlId.isEmpty(), "OControlExport::exportInnerAttributes: have no control id for the control!");
+ m_rContext.getGlobalContext().AddAttributeIdLegacy(
+ XML_NAMESPACE_FORM, m_sControlId);
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~CCAFlags::ControlId;
+ #endif
+ }
+
+ // "new-style" properties ...
+ exportGenericHandlerAttributes();
+
+ // common control attributes
+ exportCommonControlAttributes();
+
+ // common database attributes
+ exportDatabaseAttributes();
+
+ // attributes related to external bindings
+ exportBindingAttributes();
+
+ // attributes special to the respective control type
+ exportSpecialAttributes();
+
+ // add the style references to the attributes
+ flagStyleProperties();
+ }
+
+ void OControlExport::exportAttributes()
+ {
+ exportOuterAttributes();
+ }
+
+ void OControlExport::exportSubTags()
+ {
+ // for the upcoming exportRemainingProperties:
+ // if a control has the LabelControl property, this is not stored with the control itself, but instead with
+ // the control which is referenced by this property. As the base class' exportRemainingProperties doesn't
+ // know anything about this, we need to prevent that it tries to export this property
+ exportedProperty(PROPERTY_CONTROLLABEL);
+
+ // if it's a control supporting XText, then we need to declare all text-related properties
+ // as "already exported". This prevents them from being exported as generic "form:property"-tags.
+ // *If* we would export them this way, they would be completely superfluous, and sometimes even
+ // disastrous, since they may, at import time, override paragraph properties which already have
+ // been set before
+ Reference< XText > xControlText( m_xProps, UNO_QUERY );
+ if ( xControlText.is() )
+ {
+ const XMLPropertyMapEntry* pCharAttributeProperties = XMLTextPropertySetMapper::getPropertyMapForType( TextPropMap::TEXT );
+ while ( pCharAttributeProperties->msApiName )
+ {
+ exportedProperty( OUString::createFromAscii( pCharAttributeProperties->msApiName ) );
+ ++pCharAttributeProperties;
+ }
+
+ const XMLPropertyMapEntry* pParaAttributeProperties = XMLTextPropertySetMapper::getPropertyMapForType( TextPropMap::SHAPE_PARA );
+ while ( pParaAttributeProperties->msApiName )
+ {
+ exportedProperty( OUString::createFromAscii( pParaAttributeProperties->msApiName ) );
+ ++pParaAttributeProperties;
+ }
+
+ // the RichText property is not exported. The presence of the text:p element
+ // will be used - upon reading - as indicator for the value of the RichText property
+ exportedProperty( PROPERTY_RICH_TEXT );
+
+ // strange thing: paragraphs support both a CharStrikeout and a CharCrossedOut property
+ // The former is a short/enum value, the latter a boolean. The former has a real meaning
+ // (the strikeout type), the latter hasn't. But, when the CharCrossedOut is exported and
+ // later on imported, it overwrites anything which has previously been imported for
+ // CharStrikeout.
+ // #i27729#
+ exportedProperty( "CharCrossedOut" );
+ }
+
+ if ( m_eType == LISTBOX )
+ {
+ // will be exported in exportListSourceAsElements:
+ if ( controlHasUserSuppliedListEntries() )
+ exportedProperty( PROPERTY_DEFAULT_SELECT_SEQ );
+
+ // will not be exported in a generic way. Either exportListSourceAsElements cares
+ // for them, or we don't need them
+ exportedProperty( PROPERTY_STRING_ITEM_LIST );
+ exportedProperty( PROPERTY_VALUE_SEQ );
+ exportedProperty( PROPERTY_SELECT_SEQ );
+ exportedProperty( PROPERTY_LISTSOURCE );
+ }
+ if ( m_eType == COMBOBOX )
+ exportedProperty( PROPERTY_STRING_ITEM_LIST );
+
+ // let the base class export the remaining properties and the events
+ OElementExport::exportSubTags();
+
+ // special sub tags for some controls
+ switch (m_eType)
+ {
+ case LISTBOX:
+ // don't export the list entries if the are not provided by the user, but obtained implicitly
+ // from other sources
+ // #i26944#
+ if ( controlHasUserSuppliedListEntries() )
+ exportListSourceAsElements();
+ break;
+ case GRID:
+ { // a grid control requires us to store all columns as sub elements
+ Reference< XIndexAccess > xColumnContainer(m_xProps, UNO_QUERY);
+ OSL_ENSURE(xColumnContainer.is(), "OControlExport::exportSubTags: a grid control which is no IndexAccess?!!");
+ if (xColumnContainer.is())
+ m_rContext.exportCollectionElements(xColumnContainer);
+ }
+ break;
+ case COMBOBOX:
+ { // a combox box description has sub elements: the items
+ DBG_CHECK_PROPERTY( PROPERTY_STRING_ITEM_LIST, Sequence< OUString > );
+
+ // don't export the list entries if the are not provided by the user, but obtained implicitly
+ // from other sources
+ // #i26944#
+ if ( controlHasUserSuppliedListEntries() )
+ {
+ // get the item list
+ Sequence< OUString > aListItems;
+ m_xProps->getPropertyValue(PROPERTY_STRING_ITEM_LIST) >>= aListItems;
+ // loop through it and write the sub elements
+ for (const auto& rListItem : std::as_const(aListItems))
+ {
+ m_rContext.getGlobalContext().ClearAttrList();
+ AddAttribute(
+ OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::Label),
+ OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Label),
+ rListItem);
+ SvXMLElementExport aFormElement(m_rContext.getGlobalContext(), XML_NAMESPACE_FORM, "item", true, true);
+ }
+ }
+ }
+ break;
+
+ case TEXT_AREA:
+ {
+ // if we act as rich text control, we need to export some text:p elements
+ if ( xControlText.is() )
+ {
+ bool bActingAsRichText = false;
+ if ( m_xPropertyInfo->hasPropertyByName( PROPERTY_RICH_TEXT ) )
+ {
+ OSL_VERIFY(m_xProps->getPropertyValue( PROPERTY_RICH_TEXT ) >>= bActingAsRichText );
+ }
+
+ if ( bActingAsRichText )
+ m_rContext.getGlobalContext().GetTextParagraphExport()->exportText( xControlText );
+ }
+ }
+ break;
+ default:
+ // nothing do to
+ break;
+ }
+ }
+
+ void OControlExport::exportGenericHandlerAttributes()
+ {
+ const Sequence< Property > aProperties = m_xPropertyInfo->getProperties();
+ for ( auto const & prop : aProperties )
+ {
+ try
+ {
+ // see if this property can already be handled with an IPropertyHandler (which, on the long
+ // term, should be the case for most, if not all, properties)
+ const PropertyDescription* propDescription = metadata::getPropertyDescription( prop.Name );
+ if ( propDescription == nullptr )
+ continue;
+
+ // let the factory provide the concrete handler. Note that caching, if desired, is the task
+ // of the factory
+ PPropertyHandler handler = (*propDescription->factory)( propDescription->propertyId );
+ if ( !handler )
+ {
+ SAL_WARN( "xmloff.forms", "OControlExport::exportGenericHandlerAttributes: invalid property handler provided by the factory!" );
+ continue;
+ }
+
+ // that's a property which has a direct mapping to an attribute
+ if ( !shouldExportProperty( prop.Name ) )
+ // TODO: in the future, we surely need a more sophisticated approach to this, involving the property
+ // handler, or the property description
+ {
+ exportedProperty( prop.Name );
+ continue;
+ }
+
+ const Any propValue = m_xProps->getPropertyValue( prop.Name );
+ OUString attributeValue = handler->getAttributeValue( propValue );
+
+ AddAttribute(
+ propDescription->attribute.namespacePrefix,
+ token::GetXMLToken( propDescription->attribute.attributeToken ),
+ attributeValue
+ );
+
+ exportedProperty( prop.Name );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION("xmloff.forms");
+ }
+ }
+ }
+
+ void OControlExport::exportCommonControlAttributes()
+ {
+ size_t i=0;
+
+ // I decided to handle all the properties here with some static arrays describing the property-attribute
+ // relations. This leads to somewhat ugly code :), but the only alternative I can think of right now
+ // would require maps and O(log n) searches, which seems somewhat expensive as this code is used
+ // very frequently.
+
+ // the extra indents for the respective blocks are to ensure that there is no copy'n'paste error, using
+ // map identifiers from the wrong block
+
+ // some string properties
+ {
+ // the attribute ids of all properties which are expected to be of type string
+ static const CCAFlags nStringPropertyAttributeIds[] =
+ {
+ CCAFlags::Label, CCAFlags::Title
+ };
+ // the names of all properties which are expected to be of type string
+ static const char * aStringPropertyNames[] =
+ {
+ PROPERTY_LABEL, PROPERTY_TITLE
+ };
+ OSL_ENSURE( SAL_N_ELEMENTS(aStringPropertyNames) ==
+ SAL_N_ELEMENTS(nStringPropertyAttributeIds),
+ "OControlExport::exportCommonControlAttributes: somebody tampered with the maps (1)!");
+
+ for (i=0; i 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~nStringPropertyAttributeIds[i];
+ #endif
+ }
+ }
+
+ // some boolean properties
+ {
+ static const CCAFlags nBooleanPropertyAttributeIds[] =
+ { // attribute flags
+ CCAFlags::CurrentSelected, CCAFlags::Disabled, CCAFlags::Dropdown, CCAFlags::Printable, CCAFlags::ReadOnly, CCAFlags::Selected, CCAFlags::TabStop, CCAFlags::EnableVisible
+ };
+ static const char * pBooleanPropertyNames[] =
+ { // property names
+ PROPERTY_STATE, PROPERTY_ENABLED,
+ PROPERTY_DROPDOWN, PROPERTY_PRINTABLE,
+ PROPERTY_READONLY, PROPERTY_DEFAULT_STATE,
+ PROPERTY_TABSTOP, PROPERTY_ENABLEVISIBLE
+ };
+ static const BoolAttrFlags nBooleanPropertyAttrFlags[] =
+ { // attribute defaults
+ BoolAttrFlags::DefaultFalse, BoolAttrFlags::DefaultFalse | BoolAttrFlags::InverseSemantics, BoolAttrFlags::DefaultFalse, BoolAttrFlags::DefaultTrue, BoolAttrFlags::DefaultFalse, BoolAttrFlags::DefaultFalse, BoolAttrFlags::DefaultVoid, BoolAttrFlags::DefaultFalse
+ };
+ #if OSL_DEBUG_LEVEL > 0
+ static const sal_Int32 nIdCount = SAL_N_ELEMENTS(nBooleanPropertyAttributeIds);
+ static const sal_Int32 nNameCount = SAL_N_ELEMENTS(pBooleanPropertyNames);
+ static const sal_Int32 nFlagsCount = SAL_N_ELEMENTS(nBooleanPropertyAttrFlags);
+ OSL_ENSURE((nIdCount == nNameCount) && (nNameCount == nFlagsCount),
+ "OControlExport::exportCommonControlAttributes: somebody tampered with the maps (2)!");
+ #endif
+ for (i=0; i 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~nBooleanPropertyAttributeIds[i];
+ #endif
+ }
+ }
+
+ // some integer properties
+ {
+ // now the common handling
+ static const CCAFlags nIntegerPropertyAttributeIds[] =
+ { // attribute flags
+ CCAFlags::Size, CCAFlags::TabIndex
+ };
+ static const char * pIntegerPropertyNames[] =
+ { // property names
+ PROPERTY_LINECOUNT, PROPERTY_TABINDEX
+ };
+ static const sal_Int16 nIntegerPropertyAttrDefaults[] =
+ { // attribute defaults
+ 5, 0
+ };
+
+ if ( m_nIncludeCommon & CCAFlags::MaxLength )
+ exportedProperty(PROPERTY_MAXTEXTLENGTH);
+
+ #if OSL_DEBUG_LEVEL > 0
+ static const sal_Int32 nIdCount = SAL_N_ELEMENTS(nIntegerPropertyAttributeIds);
+ static const sal_Int32 nNameCount = SAL_N_ELEMENTS(pIntegerPropertyNames);
+ static const sal_Int32 nDefaultCount = SAL_N_ELEMENTS(nIntegerPropertyAttrDefaults);
+ OSL_ENSURE((nIdCount == nNameCount) && (nNameCount == nDefaultCount),
+ "OControlExport::exportCommonControlAttributes: somebody tampered with the maps (3)!");
+ #endif
+ for (i=0; i 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~nIntegerPropertyAttributeIds[i];
+ #endif
+ }
+
+ }
+
+ // some enum properties
+ {
+ if (m_nIncludeCommon & CCAFlags::ButtonType)
+ {
+ exportEnumPropertyAttribute(
+ OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::ButtonType),
+ OAttributeMetaData::getCommonControlAttributeName(CCAFlags::ButtonType),
+ PROPERTY_BUTTONTYPE,
+ aFormButtonTypeMap,
+ FormButtonType_PUSH);
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~CCAFlags::ButtonType;
+ #endif
+ }
+ if ( m_nIncludeCommon & CCAFlags::Orientation )
+ {
+ exportEnumPropertyAttribute(
+ OAttributeMetaData::getCommonControlAttributeNamespace( CCAFlags::Orientation ),
+ OAttributeMetaData::getCommonControlAttributeName( CCAFlags::Orientation ),
+ PROPERTY_ORIENTATION,
+ aOrientationMap,
+ ScrollBarOrientation::HORIZONTAL
+ );
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~CCAFlags::Orientation;
+ #endif
+ }
+
+ if ( m_nIncludeCommon & CCAFlags::VisualEffect )
+ {
+ exportEnumPropertyAttribute(
+ OAttributeMetaData::getCommonControlAttributeNamespace( CCAFlags::VisualEffect ),
+ OAttributeMetaData::getCommonControlAttributeName( CCAFlags::VisualEffect ),
+ PROPERTY_VISUAL_EFFECT,
+ aVisualEffectMap,
+ VisualEffect::LOOK3D
+ );
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~CCAFlags::VisualEffect;
+ #endif
+ }
+ }
+
+ // some properties which require a special handling
+
+ // the target frame
+ if (m_nIncludeCommon & CCAFlags::TargetFrame)
+ {
+ exportTargetFrameAttribute();
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~CCAFlags::TargetFrame;
+ #endif
+ }
+
+ // max text length
+ if ( m_nIncludeCommon & CCAFlags::MaxLength )
+ {
+ // normally, the respective property would be "MaxTextLen"
+ // However, if the model has a property "PersistenceMaxTextLength", then we prefer this
+
+ // determine the name of the property to export
+ OUString sTextLenPropertyName( PROPERTY_MAXTEXTLENGTH );
+ if ( m_xPropertyInfo->hasPropertyByName( PROPERTY_PERSISTENCE_MAXTEXTLENGTH ) )
+ sTextLenPropertyName = PROPERTY_PERSISTENCE_MAXTEXTLENGTH;
+
+ // export it
+ exportInt16PropertyAttribute(
+ OAttributeMetaData::getCommonControlAttributeNamespace( CCAFlags::MaxLength ),
+ OAttributeMetaData::getCommonControlAttributeName( CCAFlags::MaxLength ),
+ sTextLenPropertyName,
+ 0
+ );
+
+ // in either way, both properties count as "exported"
+ exportedProperty( PROPERTY_MAXTEXTLENGTH );
+ exportedProperty( PROPERTY_PERSISTENCE_MAXTEXTLENGTH );
+
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~CCAFlags::MaxLength;
+ #endif
+ }
+
+ if (m_nIncludeCommon & CCAFlags::TargetLocation)
+ {
+ exportTargetLocationAttribute(false);
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~CCAFlags::TargetLocation;
+ #endif
+ }
+
+ // OJ #99721#
+ if (m_nIncludeCommon & CCAFlags::ImageData)
+ {
+ exportImageDataAttribute();
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~CCAFlags::ImageData;
+ #endif
+ }
+
+ // the for attribute
+ // the target frame
+ if (m_nIncludeCommon & CCAFlags::For)
+ {
+ if (!m_sReferringControls.isEmpty())
+ { // there is at least one control referring to the one we're handling currently
+ AddAttribute(
+ OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::For),
+ OAttributeMetaData::getCommonControlAttributeName(CCAFlags::For),
+ m_sReferringControls);
+ }
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~CCAFlags::For;
+ #endif
+ }
+
+ if ((CCAFlags::CurrentValue | CCAFlags::Value) & m_nIncludeCommon)
+ {
+ const char* pCurrentValuePropertyName = nullptr;
+ const char* pValuePropertyName = nullptr;
+
+ // get the property names
+ getValuePropertyNames(m_eType, m_nClassId, pCurrentValuePropertyName, pValuePropertyName);
+
+ // add the attributes if necessary and possible
+ if (pCurrentValuePropertyName && (CCAFlags::CurrentValue & m_nIncludeCommon))
+ {
+ static const OUString pCurrentValueAttributeName = OAttributeMetaData::getCommonControlAttributeName(CCAFlags::CurrentValue);
+ // don't export the current-value if this value originates from a data binding
+ // #i26944#
+ if ( controlHasActiveDataBinding() )
+ exportedProperty( OUString::createFromAscii( pCurrentValuePropertyName ) );
+ else
+ {
+ static const sal_uInt16 nCurrentValueAttributeNamespaceKey = OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::CurrentValue);
+ exportGenericPropertyAttribute(
+ nCurrentValueAttributeNamespaceKey,
+ pCurrentValueAttributeName,
+ pCurrentValuePropertyName
+ );
+ }
+ }
+
+ if (pValuePropertyName && (CCAFlags::Value & m_nIncludeCommon))
+ {
+ static const OUString pValueAttributeName = OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Value);
+ static const sal_uInt16 nValueAttributeNamespaceKey = OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::Value);
+ exportGenericPropertyAttribute(
+ nValueAttributeNamespaceKey,
+ pValueAttributeName,
+ pValuePropertyName);
+ }
+
+ OSL_ENSURE((nullptr == pValuePropertyName) == (CCAFlags::NONE == (CCAFlags::Value & m_nIncludeCommon)),
+ "OControlExport::exportCommonControlAttributes: no property found for the value attribute!");
+ OSL_ENSURE((nullptr == pCurrentValuePropertyName ) == (CCAFlags::NONE == (CCAFlags::CurrentValue & m_nIncludeCommon)),
+ "OControlExport::exportCommonControlAttributes: no property found for the current-value attribute!");
+
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeCommon = m_nIncludeCommon & ~CCAFlags(CCAFlags::CurrentValue | CCAFlags::Value);
+ #endif
+ }
+
+ OSL_ENSURE(CCAFlags::NONE == m_nIncludeCommon,
+ "OControlExport::exportCommonControlAttributes: forgot some flags!");
+ // in the dbg_util version, we should have removed every bit we handled from the mask, so it should
+ // be 0 now ...
+ }
+
+ void OControlExport::exportDatabaseAttributes()
+ {
+#if OSL_DEBUG_LEVEL > 0
+ DAFlags nIncludeDatabase = m_nIncludeDatabase;
+#endif
+ // the only string property: DataField
+ if (DAFlags::DataField & m_nIncludeDatabase)
+ {
+ exportStringPropertyAttribute(
+ OAttributeMetaData::getDatabaseAttributeNamespace(),
+ OAttributeMetaData::getDatabaseAttributeName(DAFlags::DataField),
+ PROPERTY_DATAFIELD);
+ RESET_BIT( nIncludeDatabase, DAFlags::DataField );
+ }
+
+ // InputRequired
+ if ( DAFlags::InputRequired & m_nIncludeDatabase )
+ {
+ exportBooleanPropertyAttribute(
+ OAttributeMetaData::getDatabaseAttributeNamespace(),
+ OAttributeMetaData::getDatabaseAttributeName( DAFlags::InputRequired ),
+ PROPERTY_INPUT_REQUIRED,
+ BoolAttrFlags::DefaultFalse | BoolAttrFlags::DefaultVoid
+ );
+ RESET_BIT( nIncludeDatabase, DAFlags::InputRequired );
+ }
+
+ // the only int16 property: BoundColumn
+ if (DAFlags::BoundColumn & m_nIncludeDatabase)
+ {
+ exportInt16PropertyAttribute(
+ OAttributeMetaData::getDatabaseAttributeNamespace(),
+ OAttributeMetaData::getDatabaseAttributeName(DAFlags::BoundColumn),
+ PROPERTY_BOUNDCOLUMN,
+ 0,
+ true);
+ RESET_BIT( nIncludeDatabase, DAFlags::BoundColumn );
+ }
+
+ // ConvertEmptyToNull
+ if (DAFlags::ConvertEmpty & m_nIncludeDatabase)
+ {
+ exportBooleanPropertyAttribute(
+ OAttributeMetaData::getDatabaseAttributeNamespace(),
+ OAttributeMetaData::getDatabaseAttributeName(DAFlags::ConvertEmpty),
+ PROPERTY_EMPTY_IS_NULL,
+ BoolAttrFlags::DefaultFalse
+ );
+ RESET_BIT( nIncludeDatabase, DAFlags::ConvertEmpty );
+ }
+
+ // the only enum property: ListSourceType
+ if (DAFlags::ListSource_TYPE & m_nIncludeDatabase)
+ {
+ exportEnumPropertyAttribute(
+ OAttributeMetaData::getDatabaseAttributeNamespace(),
+ OAttributeMetaData::getDatabaseAttributeName(DAFlags::ListSource_TYPE),
+ PROPERTY_LISTSOURCETYPE,
+ aListSourceTypeMap,
+ ListSourceType_VALUELIST
+ );
+ RESET_BIT( nIncludeDatabase, DAFlags::ListSource_TYPE );
+ }
+
+ if (m_nIncludeDatabase & DAFlags::ListSource)
+ {
+ exportListSourceAsAttribute();
+ RESET_BIT( nIncludeDatabase, DAFlags::ListSource );
+ }
+
+#if OSL_DEBUG_LEVEL > 0
+ OSL_ENSURE(DAFlags::NONE == nIncludeDatabase,
+ "OControlExport::exportDatabaseAttributes: forgot some flags!");
+ // in the dbg_util version, we should have removed every bit we handled from the mask, so it should
+ // be 0 now ...
+#endif
+ }
+
+ void OControlExport::exportBindingAttributes()
+ {
+#if OSL_DEBUG_LEVEL > 0
+ BAFlags nIncludeBinding = m_nIncludeBindings;
+#endif
+
+ if ( m_nIncludeBindings & BAFlags::LinkedCell )
+ {
+ exportCellBindingAttributes( bool(m_nIncludeBindings & BAFlags::ListLinkingType) );
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ nIncludeBinding = nIncludeBinding & ~BAFlags( BAFlags::LinkedCell | BAFlags::ListLinkingType );
+ #endif
+ }
+
+ if ( m_nIncludeBindings & BAFlags::ListCellRange )
+ {
+ exportCellListSourceRange();
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ nIncludeBinding = nIncludeBinding & ~BAFlags::ListCellRange;
+ #endif
+ }
+
+ if ( m_nIncludeBindings & BAFlags::XFormsBind )
+ {
+ exportXFormsBindAttributes();
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ nIncludeBinding = nIncludeBinding & ~BAFlags::XFormsBind;
+ #endif
+ }
+
+ if ( m_nIncludeBindings & BAFlags::XFormsListBind )
+ {
+ exportXFormsListAttributes();
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ nIncludeBinding = nIncludeBinding & ~BAFlags::XFormsListBind;
+ #endif
+ }
+
+ if ( m_nIncludeBindings & BAFlags::XFormsSubmission )
+ {
+ exportXFormsSubmissionAttributes();
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ nIncludeBinding = nIncludeBinding & ~BAFlags::XFormsSubmission;
+ #endif
+ }
+
+ #if OSL_DEBUG_LEVEL > 0
+ OSL_ENSURE( BAFlags::NONE == nIncludeBinding,
+ "OControlExport::exportBindingAttributes: forgot some flags!");
+ // in the debug version, we should have removed every bit we handled from the mask, so it should
+ // be 0 now ...
+ #endif
+ }
+
+ void OControlExport::exportSpecialAttributes()
+ {
+ sal_Int32 i=0;
+
+ // the boolean properties
+ {
+ static const SCAFlags nBooleanPropertyAttributeIds[] =
+ { // attribute flags
+ SCAFlags::Validation, SCAFlags::MultiLine, SCAFlags::AutoCompletion, SCAFlags::Multiple, SCAFlags::DefaultButton, SCAFlags::IsTristate,
+ SCAFlags::Toggle, SCAFlags::FocusOnClick
+ };
+ static const char * pBooleanPropertyNames[] =
+ { // property names
+ PROPERTY_STRICTFORMAT, PROPERTY_MULTILINE,
+ PROPERTY_AUTOCOMPLETE,
+ PROPERTY_MULTISELECTION,
+ PROPERTY_DEFAULTBUTTON, PROPERTY_TRISTATE,
+ PROPERTY_TOGGLE, PROPERTY_FOCUS_ON_CLICK
+ };
+ static const sal_Int32 nIdCount = SAL_N_ELEMENTS(nBooleanPropertyAttributeIds);
+ #if OSL_DEBUG_LEVEL > 0
+ static const sal_Int32 nNameCount = SAL_N_ELEMENTS(pBooleanPropertyNames);
+ OSL_ENSURE((nIdCount == nNameCount),
+ "OControlExport::exportSpecialAttributes: somebody tampered with the maps (1)!");
+ #endif
+ const SCAFlags* pAttributeId = nBooleanPropertyAttributeIds;
+ for ( i = 0; i < nIdCount; ++i, ++pAttributeId )
+ {
+ if ( *pAttributeId & m_nIncludeSpecial)
+ {
+ exportBooleanPropertyAttribute(
+ OAttributeMetaData::getSpecialAttributeNamespace( *pAttributeId ),
+ OAttributeMetaData::getSpecialAttributeName( *pAttributeId ),
+ OUString::createFromAscii(pBooleanPropertyNames[i]),
+ ( *pAttributeId == SCAFlags::FocusOnClick ) ? BoolAttrFlags::DefaultTrue : BoolAttrFlags::DefaultFalse
+ );
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeSpecial = m_nIncludeSpecial & ~*pAttributeId;
+ #endif
+ }
+ }
+ }
+
+ // the integer properties
+ {
+ static const SCAFlags nIntegerPropertyAttributeIds[] =
+ { // attribute flags
+ SCAFlags::PageStepSize
+ };
+ static const char * pIntegerPropertyNames[] =
+ { // property names
+ PROPERTY_BLOCK_INCREMENT
+ };
+ static const sal_Int32 nIntegerPropertyAttrDefaults[] =
+ { // attribute defaults (XML defaults, not runtime defaults!)
+ 10
+ };
+
+ static const sal_Int32 nIdCount = SAL_N_ELEMENTS( nIntegerPropertyAttributeIds );
+ #if OSL_DEBUG_LEVEL > 0
+ static const sal_Int32 nNameCount = SAL_N_ELEMENTS( pIntegerPropertyNames );
+ OSL_ENSURE( ( nIdCount == nNameCount ),
+ "OControlExport::exportSpecialAttributes: somebody tampered with the maps (2)!" );
+ static const sal_Int32 nDefaultCount = SAL_N_ELEMENTS( nIntegerPropertyAttrDefaults );
+ OSL_ENSURE( ( nIdCount == nDefaultCount ),
+ "OControlExport::exportSpecialAttributes: somebody tampered with the maps (3)!" );
+ #endif
+ for ( i = 0; i < nIdCount; ++i )
+ if ( nIntegerPropertyAttributeIds[i] & m_nIncludeSpecial )
+ {
+ exportInt32PropertyAttribute(
+ OAttributeMetaData::getSpecialAttributeNamespace( nIntegerPropertyAttributeIds[i] ),
+ OAttributeMetaData::getSpecialAttributeName( nIntegerPropertyAttributeIds[i] ),
+ OUString::createFromAscii(pIntegerPropertyNames[i]),
+ nIntegerPropertyAttrDefaults[i]
+ );
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeSpecial = m_nIncludeSpecial & ~nIntegerPropertyAttributeIds[i];
+ #endif
+ }
+
+ if ( SCAFlags::StepSize & m_nIncludeSpecial )
+ {
+ OUString sPropertyName;
+ if ( m_xPropertyInfo->hasPropertyByName( PROPERTY_LINE_INCREMENT ) )
+ sPropertyName = PROPERTY_LINE_INCREMENT;
+ else if ( m_xPropertyInfo->hasPropertyByName( PROPERTY_SPIN_INCREMENT ) )
+ sPropertyName = PROPERTY_SPIN_INCREMENT;
+ else
+ OSL_FAIL( "OControlExport::exportSpecialAttributes: not property which can be mapped to step-size attribute!" );
+
+ if ( !sPropertyName.isEmpty() )
+ exportInt32PropertyAttribute(
+ OAttributeMetaData::getSpecialAttributeNamespace( SCAFlags::StepSize ),
+ OAttributeMetaData::getSpecialAttributeName( SCAFlags::StepSize ),
+ sPropertyName,
+ 1
+ );
+
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeSpecial = m_nIncludeSpecial & ~SCAFlags::StepSize;
+ #endif
+ }
+
+ }
+
+ // the enum properties
+ {
+ if (SCAFlags::State & m_nIncludeSpecial)
+ {
+ exportEnumPropertyAttribute(
+ OAttributeMetaData::getSpecialAttributeNamespace(SCAFlags::State),
+ OAttributeMetaData::getSpecialAttributeName(SCAFlags::State),
+ PROPERTY_DEFAULT_STATE,
+ aCheckStateMap,
+ TRISTATE_FALSE);
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeSpecial = m_nIncludeSpecial & ~SCAFlags::State;
+ #endif
+ }
+
+ if (SCAFlags::CurrentState & m_nIncludeSpecial)
+ {
+ exportEnumPropertyAttribute(
+ OAttributeMetaData::getSpecialAttributeNamespace(SCAFlags::CurrentState),
+ OAttributeMetaData::getSpecialAttributeName(SCAFlags::CurrentState),
+ PROPERTY_STATE,
+ aCheckStateMap,
+ TRISTATE_FALSE);
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeSpecial = m_nIncludeSpecial & ~SCAFlags::CurrentState;
+ #endif
+ }
+ }
+
+ // some properties which require a special handling
+ // the repeat delay
+ {
+ if ( m_nIncludeSpecial & SCAFlags::RepeatDelay )
+ {
+ DBG_CHECK_PROPERTY( PROPERTY_REPEAT_DELAY, sal_Int32 );
+
+ sal_Int32 nRepeatDelay = 0;
+ m_xProps->getPropertyValue( PROPERTY_REPEAT_DELAY ) >>= nRepeatDelay;
+ tools::Time aTime( tools::Time::SYSTEM );
+ aTime.MakeTimeFromMS( nRepeatDelay );
+ util::Duration aDuration;
+ aDuration.Hours = aTime.GetHour();
+ aDuration.Minutes = aTime.GetMin();
+ aDuration.Seconds = aTime.GetSec();
+ aDuration.NanoSeconds = (nRepeatDelay % 1000) * 1000000;
+
+ OUStringBuffer buf;
+ ::sax::Converter::convertDuration(buf, aDuration);
+ AddAttribute(OAttributeMetaData::getSpecialAttributeNamespace( SCAFlags::RepeatDelay )
+ ,OAttributeMetaData::getSpecialAttributeName( SCAFlags::RepeatDelay )
+ ,buf.makeStringAndClear());
+
+ exportedProperty( PROPERTY_REPEAT_DELAY );
+
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeSpecial = m_nIncludeSpecial & ~SCAFlags::RepeatDelay;
+ #endif
+ }
+ }
+
+ // the EchoChar property needs special handling, cause it's a Int16, but must be stored as one-character-string
+ {
+ if (SCAFlags::EchoChar & m_nIncludeSpecial)
+ {
+ DBG_CHECK_PROPERTY( PROPERTY_ECHO_CHAR, sal_Int16 );
+ sal_Int16 nValue(0);
+ m_xProps->getPropertyValue(PROPERTY_ECHO_CHAR) >>= nValue;
+ if (nValue)
+ {
+ OUString sCharacter(reinterpret_cast(&nValue), 1);
+ AddAttribute(
+ OAttributeMetaData::getSpecialAttributeNamespace(SCAFlags::EchoChar),
+ OAttributeMetaData::getSpecialAttributeName(SCAFlags::EchoChar),
+ sCharacter);
+ }
+ exportedProperty(PROPERTY_ECHO_CHAR);
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeSpecial = m_nIncludeSpecial & ~SCAFlags::EchoChar;
+ #endif
+ }
+ }
+
+ // the string properties
+ {
+ static const SCAFlags nStringPropertyAttributeIds[] =
+ { // attribute flags
+ SCAFlags::GroupName
+ };
+ static const std::u16string_view pStringPropertyNames[] =
+ { // property names
+ u"" PROPERTY_GROUP_NAME
+ };
+
+ static const sal_Int32 nIdCount = SAL_N_ELEMENTS( nStringPropertyAttributeIds );
+ #if OSL_DEBUG_LEVEL > 0
+ static const sal_Int32 nNameCount = SAL_N_ELEMENTS( pStringPropertyNames );
+ OSL_ENSURE( ( nIdCount == nNameCount ),
+ "OControlExport::exportSpecialAttributes: somebody tampered with the maps (2)!" );
+ #endif
+ for ( i = 0; i < nIdCount; ++i )
+ if ( nStringPropertyAttributeIds[i] & m_nIncludeSpecial )
+ {
+ exportStringPropertyAttribute(
+ OAttributeMetaData::getSpecialAttributeNamespace( nStringPropertyAttributeIds[i] ),
+ OAttributeMetaData::getSpecialAttributeName( nStringPropertyAttributeIds[i] ),
+ OUString(pStringPropertyNames[i])
+ );
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeSpecial = m_nIncludeSpecial & ~nStringPropertyAttributeIds[i];
+ #endif
+ }
+ }
+
+ if ((SCAFlags::MinValue | SCAFlags::MaxValue) & m_nIncludeSpecial)
+ {
+ // need to export the min value and the max value as attributes
+ // It depends on the real type (FormComponentType) of the control, which properties hold these
+ // values
+ const char* pMinValuePropertyName = nullptr;
+ const char* pMaxValuePropertyName = nullptr;
+ getValueLimitPropertyNames(m_nClassId, pMinValuePropertyName, pMaxValuePropertyName);
+
+ OSL_ENSURE((nullptr == pMinValuePropertyName) == (SCAFlags::NONE == (SCAFlags::MinValue & m_nIncludeSpecial)),
+ "OControlExport::exportCommonControlAttributes: no property found for the min value attribute!");
+ OSL_ENSURE((nullptr == pMaxValuePropertyName) == (SCAFlags::NONE == (SCAFlags::MaxValue & m_nIncludeSpecial)),
+ "OControlExport::exportCommonControlAttributes: no property found for the max value attribute!");
+
+ // add the two attributes
+ static const OUString pMinValueAttributeName = OAttributeMetaData::getSpecialAttributeName(SCAFlags::MinValue);
+ static const OUString pMaxValueAttributeName = OAttributeMetaData::getSpecialAttributeName(SCAFlags::MaxValue);
+ static const sal_uInt16 nMinValueNamespaceKey = OAttributeMetaData::getSpecialAttributeNamespace(SCAFlags::MinValue);
+ static const sal_uInt16 nMaxValueNamespaceKey = OAttributeMetaData::getSpecialAttributeNamespace(SCAFlags::MaxValue);
+
+ if (pMinValuePropertyName && (SCAFlags::MinValue & m_nIncludeSpecial))
+ exportGenericPropertyAttribute(
+ nMinValueNamespaceKey,
+ pMinValueAttributeName,
+ pMinValuePropertyName);
+
+ if (pMaxValuePropertyName && (SCAFlags::MaxValue & m_nIncludeSpecial))
+ exportGenericPropertyAttribute(
+ nMaxValueNamespaceKey,
+ pMaxValueAttributeName,
+ pMaxValuePropertyName);
+ #if OSL_DEBUG_LEVEL > 0
+ // reset the bit for later checking
+ m_nIncludeSpecial = m_nIncludeSpecial & ~SCAFlags(SCAFlags::MinValue | SCAFlags::MaxValue);
+ #endif
+ }
+
+ if ( SCAFlags::ImagePosition & m_nIncludeSpecial )
+ {
+ exportImagePositionAttributes();
+ RESET_BIT( m_nIncludeSpecial, SCAFlags::ImagePosition );
+ }
+
+ OSL_ENSURE(SCAFlags::NONE == m_nIncludeSpecial,
+ "OControlExport::exportSpecialAttributes: forgot some flags!");
+ // in the dbg_util version, we should have removed every bit we handled from the mask, so it should
+ // be 0 now ...
+ }
+
+ OUString OControlExport::getScalarListSourceValue() const
+ {
+ OUString sListSource;
+ Any aListSource = m_xProps->getPropertyValue( PROPERTY_LISTSOURCE );
+ if ( !( aListSource >>= sListSource ) )
+ {
+ Sequence< OUString > aListSourceSequence;
+ aListSource >>= aListSourceSequence;
+ if ( aListSourceSequence.hasElements() )
+ sListSource = aListSourceSequence[ 0 ];
+ }
+ return sListSource;
+ }
+
+ void OControlExport::exportListSourceAsAttribute()
+ {
+ // DAFlags::ListSource needs some special handling
+ DBG_CHECK_PROPERTY_NO_TYPE( PROPERTY_LISTSOURCE );
+
+ OUString sListSource = getScalarListSourceValue();
+ if ( !sListSource.isEmpty() )
+ { // the ListSource property needs to be exported as attribute, and it is not empty
+ AddAttribute(
+ OAttributeMetaData::getDatabaseAttributeNamespace(),
+ OAttributeMetaData::getDatabaseAttributeName(DAFlags::ListSource),
+ sListSource);
+ }
+
+ exportedProperty( PROPERTY_LISTSOURCE );
+ }
+
+ void OControlExport::getSequenceInt16PropertyAsSet(const OUString& _rPropertyName, Int16Set& _rOut)
+ {
+ Sequence< sal_Int16 > aValueSequence;
+ DBG_CHECK_PROPERTY(_rPropertyName, Sequence< sal_Int16 >);
+ m_xProps->getPropertyValue(_rPropertyName) >>= aValueSequence;
+
+ for (const auto& rValue : std::as_const(aValueSequence))
+ _rOut.insert(rValue);
+ }
+
+ void OControlExport::exportListSourceAsElements()
+ {
+ // the string lists
+ Sequence< OUString > aItems, aValues;
+ DBG_CHECK_PROPERTY( PROPERTY_STRING_ITEM_LIST, Sequence< OUString > );
+ m_xProps->getPropertyValue(PROPERTY_STRING_ITEM_LIST) >>= aItems;
+
+ DBG_CHECK_PROPERTY( PROPERTY_LISTSOURCE, Sequence< OUString > );
+ if ( DAFlags::NONE == ( m_nIncludeDatabase & DAFlags::ListSource ) )
+ m_xProps->getPropertyValue(PROPERTY_LISTSOURCE) >>= aValues;
+ // if we exported the list source as attribute, we do not repeat it as sub elements
+
+ // the selection lists
+ Int16Set aSelection, aDefaultSelection;
+ getSequenceInt16PropertyAsSet(PROPERTY_SELECT_SEQ, aSelection);
+ getSequenceInt16PropertyAsSet(PROPERTY_DEFAULT_SELECT_SEQ, aDefaultSelection);
+
+ // the string for "true"
+ OUString sTrue;
+ OUStringBuffer sBuffer;
+ ::sax::Converter::convertBool(sBuffer, true);
+ sTrue = sBuffer.makeStringAndClear();
+
+ // loop through both lists ('til the maximum of both lengths)
+ const OUString* pItems = aItems.getConstArray();
+ const OUString* pValues = aValues.getConstArray();
+
+ sal_Int32 nItems = aItems.getLength();
+ sal_Int32 nValues = aValues.getLength();
+
+ sal_Int16 nMaxLen = static_cast(std::max(nItems, nValues));
+
+ for (sal_Int16 i=0; i= nMaxLen, "OControlExport::exportListSourceAsElements: inconsistence!");
+ // if the maximum (selected or default selected) entry number is less than the maximum item count
+ // in both lists, the entry number should have been removed from the set
+
+ for (sal_Int16 i=nMaxLen; i<=nLastReferredEntry; ++i)
+ {
+ if (aSelection.end() != aSelection.find(i))
+ { // the (not existent) item at this position is selected
+ AddAttribute(
+ OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::CurrentSelected),
+ OAttributeMetaData::getCommonControlAttributeName(CCAFlags::CurrentSelected),
+ sTrue
+ );
+ }
+
+ if (aDefaultSelection.end() != aDefaultSelection.find(i))
+ { // the (not existent) item at this position is selected as default
+ AddAttribute(
+ OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::Selected),
+ OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Selected),
+ sTrue
+ );
+ }
+ SvXMLElementExport aFormElement(m_rContext.getGlobalContext(), XML_NAMESPACE_FORM, "option", true, true);
+ }
+ }
+
+ void OControlExport::implStartElement(const char* _pName)
+ {
+ // before we let the base class start it's outer element, we add a wrapper element
+ const char *pOuterElementName = getOuterXMLElementName();
+ if (pOuterElementName)
+ m_pOuterElement = std::make_unique(
+ m_rContext.getGlobalContext(),
+ XML_NAMESPACE_FORM,
+ pOuterElementName, true,
+ true);
+
+ // add the attributes for the inner element
+ exportInnerAttributes();
+
+ // and start the inner element
+ OElementExport::implStartElement(_pName);
+ }
+
+ void OControlExport::implEndElement()
+ {
+ // end the inner element
+ OElementExport::implEndElement();
+
+ // end the outer element if it exists
+ m_pOuterElement.reset();
+ }
+
+ const char* OControlExport::getOuterXMLElementName() const
+ {
+ return nullptr;
+ }
+
+ const char* OControlExport::getXMLElementName() const
+ {
+ return getElementName(m_eType);
+ }
+
+ void OControlExport::examine()
+ {
+ OSL_ENSURE( ( m_nIncludeCommon == CCAFlags::NONE ) && ( m_nIncludeSpecial == SCAFlags::NONE ) && ( m_nIncludeDatabase == DAFlags::NONE )
+ && ( m_nIncludeEvents == EAFlags::NONE ) && ( m_nIncludeBindings == BAFlags::NONE),
+ "OControlExport::examine: called me twice? Not initialized?" );
+
+ // get the class id to decide which kind of element we need in the XML stream
+ m_nClassId = FormComponentType::CONTROL;
+ DBG_CHECK_PROPERTY( PROPERTY_CLASSID, sal_Int16 );
+ m_xProps->getPropertyValue(PROPERTY_CLASSID) >>= m_nClassId;
+ bool knownType = false;
+ switch (m_nClassId)
+ {
+ case FormComponentType::DATEFIELD:
+ m_eType = DATE;
+ knownType = true;
+ [[fallthrough]];
+ case FormComponentType::TIMEFIELD:
+ if ( !knownType )
+ {
+ m_eType = TIME;
+ knownType = true;
+ }
+ m_nIncludeSpecial |= SCAFlags::Validation;
+ [[fallthrough]];
+ case FormComponentType::NUMERICFIELD:
+ case FormComponentType::CURRENCYFIELD:
+ case FormComponentType::PATTERNFIELD:
+ if ( !knownType )
+ {
+ m_eType = FORMATTED_TEXT;
+ knownType = true;
+ }
+ [[fallthrough]];
+ case FormComponentType::TEXTFIELD:
+ { // it's some kind of edit. To know which type we need further investigation
+
+ if ( !knownType )
+ {
+ // check if it's a formatted field
+ if (m_xPropertyInfo->hasPropertyByName(PROPERTY_FORMATKEY))
+ {
+ m_eType = FORMATTED_TEXT;
+ }
+ else
+ {
+ // all other controls are represented by an ordinary edit control, but which XML control type
+ // it is depends on the current values of some properties
+
+ // if the EchoChar string is not empty, it is a password field
+ sal_Int16 nEchoChar = 0;
+ if (m_xPropertyInfo->hasPropertyByName(PROPERTY_ECHOCHAR))
+ // grid columns do not have this property...
+ m_xProps->getPropertyValue(PROPERTY_ECHOCHAR) >>= nEchoChar;
+ if (nEchoChar)
+ {
+ m_eType = PASSWORD;
+ m_nIncludeSpecial |= SCAFlags::EchoChar;
+ }
+ else
+ {
+ // if the MultiLine property is sal_True, it is a TextArea
+ bool bMultiLine = false;
+ if (m_xPropertyInfo->hasPropertyByName(PROPERTY_MULTILINE))
+ // grid columns do not have this property...
+ bMultiLine = ::cppu::any2bool(m_xProps->getPropertyValue(PROPERTY_MULTILINE));
+
+ if ( bMultiLine )
+ m_eType = TEXT_AREA;
+ else
+ // the only case left is represented by a Text element
+ m_eType = TEXT;
+ }
+ }
+ }
+
+ // attributes which are common to all the types:
+ // common attributes
+ m_nIncludeCommon =
+ CCAFlags::Name | CCAFlags::ServiceName | CCAFlags::Disabled |
+ CCAFlags::Printable | CCAFlags::TabIndex | CCAFlags::TabStop | CCAFlags::Title;
+
+ if ( ( m_nClassId != FormComponentType::DATEFIELD )
+ && ( m_nClassId != FormComponentType::TIMEFIELD )
+ )
+ // date and time field values are handled differently nowadays
+ m_nIncludeCommon |= CCAFlags::Value;
+
+ // database attributes
+ m_nIncludeDatabase = DAFlags::DataField | DAFlags::InputRequired;
+
+ // event attributes
+ m_nIncludeEvents = EAFlags::ControlEvents | EAFlags::OnChange | EAFlags::OnSelect;
+
+ // only text and pattern fields have a ConvertEmptyToNull property
+ if ( ( m_nClassId == FormComponentType::TEXTFIELD )
+ || ( m_nClassId == FormComponentType::PATTERNFIELD )
+ )
+ m_nIncludeDatabase |= DAFlags::ConvertEmpty;
+
+ // all controls but the file control fields have a readonly property
+ if ( m_nClassId != FormComponentType::FILECONTROL )
+ m_nIncludeCommon |= CCAFlags::ReadOnly;
+
+ // a text field has a max text len
+ if ( m_nClassId == FormComponentType::TEXTFIELD )
+ m_nIncludeCommon |= CCAFlags::MaxLength;
+
+ // max and min values and validation:
+ if (FORMATTED_TEXT == m_eType)
+ { // in general all controls represented as formatted-text have these props
+ if ( FormComponentType::PATTERNFIELD != m_nClassId ) // except the PatternField
+ m_nIncludeSpecial |= SCAFlags::MaxValue | SCAFlags::MinValue;
+
+ if (FormComponentType::TEXTFIELD != m_nClassId)
+ // and the FormattedField does not have a validation flag
+ m_nIncludeSpecial |= SCAFlags::Validation;
+ }
+
+ // if it's not a password field or rich text control, the CurrentValue needs to be stored, too
+ if ( ( PASSWORD != m_eType )
+ && ( DATE != m_eType )
+ && ( TIME != m_eType )
+ )
+ {
+ m_nIncludeCommon |= CCAFlags::CurrentValue;
+ }
+ }
+ break;
+
+ case FormComponentType::FILECONTROL:
+ m_eType = FILE;
+ m_nIncludeCommon =
+ CCAFlags::Name | CCAFlags::ServiceName | CCAFlags::CurrentValue | CCAFlags::Disabled |
+ CCAFlags::Printable | CCAFlags::TabIndex | CCAFlags::TabStop | CCAFlags::Title |
+ CCAFlags::Value;
+ m_nIncludeEvents = EAFlags::ControlEvents | EAFlags::OnChange | EAFlags::OnSelect;
+ break;
+
+ case FormComponentType::FIXEDTEXT:
+ m_eType = FIXED_TEXT;
+ m_nIncludeCommon =
+ CCAFlags::Name | CCAFlags::ServiceName | CCAFlags::Disabled | CCAFlags::Label |
+ CCAFlags::Printable | CCAFlags::Title | CCAFlags::For;
+ m_nIncludeSpecial = SCAFlags::MultiLine;
+ m_nIncludeEvents = EAFlags::ControlEvents;
+ break;
+
+ case FormComponentType::COMBOBOX:
+ m_eType = COMBOBOX;
+ m_nIncludeCommon =
+ CCAFlags::Name | CCAFlags::ServiceName | CCAFlags::CurrentValue |
+ CCAFlags::Disabled | CCAFlags::Dropdown | CCAFlags::MaxLength | CCAFlags::Printable | CCAFlags::ReadOnly | CCAFlags::Size |
+ CCAFlags::TabIndex | CCAFlags::TabStop | CCAFlags::Title | CCAFlags::Value;
+ m_nIncludeSpecial = SCAFlags::AutoCompletion;
+ m_nIncludeDatabase = DAFlags::ConvertEmpty | DAFlags::DataField | DAFlags::InputRequired | DAFlags::ListSource | DAFlags::ListSource_TYPE;
+ m_nIncludeEvents = EAFlags::ControlEvents | EAFlags::OnChange | EAFlags::OnSelect;
+ break;
+
+ case FormComponentType::LISTBOX:
+ m_eType = LISTBOX;
+ m_nIncludeCommon =
+ CCAFlags::Name | CCAFlags::ServiceName | CCAFlags::Disabled | CCAFlags::Dropdown |
+ CCAFlags::Printable | CCAFlags::Size | CCAFlags::TabIndex | CCAFlags::TabStop | CCAFlags::Title;
+ m_nIncludeSpecial = SCAFlags::Multiple;
+ m_nIncludeDatabase = DAFlags::BoundColumn | DAFlags::DataField | DAFlags::InputRequired | DAFlags::ListSource_TYPE;
+ m_nIncludeEvents = EAFlags::ControlEvents | EAFlags::OnChange | EAFlags::OnClick | EAFlags::OnDoubleClick;
+ // check if we need to export the ListSource as attribute
+ {
+ // for a list box, if the ListSourceType is VALUE_LIST, no ListSource is stored, but instead
+ // a sequence of pairs which is build from the StringItemList and the ValueList
+ ListSourceType eListSourceType = ListSourceType_VALUELIST;
+ bool bSuccess =
+ m_xProps->getPropertyValue(PROPERTY_LISTSOURCETYPE) >>= eListSourceType;
+ OSL_ENSURE(bSuccess, "OControlExport::examineControl: could not retrieve the ListSourceType!");
+ if (ListSourceType_VALUELIST != eListSourceType)
+ {
+ m_nIncludeDatabase |= DAFlags::ListSource;
+ }
+ }
+
+ break;
+
+ case FormComponentType::COMMANDBUTTON:
+ m_eType = BUTTON;
+ m_nIncludeCommon |= CCAFlags::TabStop | CCAFlags::Label;
+ m_nIncludeSpecial = SCAFlags::DefaultButton | SCAFlags::Toggle | SCAFlags::FocusOnClick | SCAFlags::ImagePosition | SCAFlags::RepeatDelay;
+ [[fallthrough]];
+ case FormComponentType::IMAGEBUTTON:
+ if (BUTTON != m_eType)
+ {
+ // not coming from the previous case
+ m_eType = IMAGE;
+ }
+ m_nIncludeCommon |=
+ CCAFlags::Name | CCAFlags::ServiceName | CCAFlags::ButtonType | CCAFlags::Disabled |
+ CCAFlags::ImageData | CCAFlags::Printable | CCAFlags::TabIndex | CCAFlags::TargetFrame |
+ CCAFlags::TargetLocation | CCAFlags::Title;
+ m_nIncludeEvents = EAFlags::ControlEvents | EAFlags::OnClick | EAFlags::OnDoubleClick;
+ break;
+
+ case FormComponentType::CHECKBOX:
+ m_eType = CHECKBOX;
+ m_nIncludeSpecial = SCAFlags::CurrentState | SCAFlags::IsTristate | SCAFlags::State;
+ [[fallthrough]];
+ case FormComponentType::RADIOBUTTON:
+ m_nIncludeCommon =
+ CCAFlags::Name | CCAFlags::ServiceName | CCAFlags::Disabled | CCAFlags::Label | CCAFlags::Printable |
+ CCAFlags::TabIndex | CCAFlags::TabStop | CCAFlags::Title | CCAFlags::Value | CCAFlags::VisualEffect;
+ if (CHECKBOX != m_eType)
+ { // not coming from the previous case
+ m_eType = RADIO;
+ m_nIncludeCommon |= CCAFlags::CurrentSelected | CCAFlags::Selected;
+ }
+ if ( m_xPropertyInfo->hasPropertyByName( PROPERTY_IMAGE_POSITION ) )
+ m_nIncludeSpecial |= SCAFlags::ImagePosition;
+ if ( m_xPropertyInfo->hasPropertyByName( PROPERTY_GROUP_NAME ) )
+ m_nIncludeSpecial |= SCAFlags::GroupName;
+ m_nIncludeDatabase = DAFlags::DataField | DAFlags::InputRequired;
+ m_nIncludeEvents = EAFlags::ControlEvents | EAFlags::OnChange;
+ break;
+
+ case FormComponentType::GROUPBOX:
+ m_eType = FRAME;
+ m_nIncludeCommon =
+ CCAFlags::Name | CCAFlags::ServiceName | CCAFlags::Disabled | CCAFlags::Label |
+ CCAFlags::Printable | CCAFlags::Title | CCAFlags::For;
+ m_nIncludeEvents = EAFlags::ControlEvents;
+ break;
+
+ case FormComponentType::IMAGECONTROL:
+ m_eType = IMAGE_FRAME;
+ m_nIncludeCommon =
+ CCAFlags::Name | CCAFlags::ServiceName | CCAFlags::Disabled | CCAFlags::ImageData |
+ CCAFlags::Printable | CCAFlags::ReadOnly | CCAFlags::Title;
+ m_nIncludeDatabase = DAFlags::DataField | DAFlags::InputRequired;
+ m_nIncludeEvents = EAFlags::ControlEvents;
+ break;
+
+ case FormComponentType::HIDDENCONTROL:
+ m_eType = HIDDEN;
+ m_nIncludeCommon =
+ CCAFlags::Name | CCAFlags::ServiceName | CCAFlags::Value;
+ break;
+
+ case FormComponentType::GRIDCONTROL:
+ m_eType = GRID;
+ m_nIncludeCommon =
+ CCAFlags::Name | CCAFlags::ServiceName | CCAFlags::Disabled | CCAFlags::Printable |
+ CCAFlags::TabIndex | CCAFlags::TabStop | CCAFlags::Title;
+ m_nIncludeEvents = EAFlags::ControlEvents;
+ break;
+
+ case FormComponentType::SCROLLBAR:
+ case FormComponentType::SPINBUTTON:
+ m_eType = VALUERANGE;
+ m_nIncludeCommon =
+ CCAFlags::Name | CCAFlags::ServiceName | CCAFlags::Disabled | CCAFlags::Printable |
+ CCAFlags::Title | CCAFlags::CurrentValue | CCAFlags::Value | CCAFlags::Orientation;
+ m_nIncludeSpecial = SCAFlags::MaxValue | SCAFlags::StepSize | SCAFlags::MinValue | SCAFlags::RepeatDelay;
+
+ if ( m_nClassId == FormComponentType::SCROLLBAR )
+ m_nIncludeSpecial |= SCAFlags::PageStepSize ;
+
+ m_nIncludeEvents = EAFlags::ControlEvents;
+ break;
+
+ default:
+ OSL_FAIL("OControlExport::examineControl: unknown control type (class id)!");
+ [[fallthrough]];
+
+ case FormComponentType::NAVIGATIONBAR:
+ // TODO: should we have an own file format for this?
+ // NO break
+
+ case FormComponentType::CONTROL:
+ m_eType = GENERIC_CONTROL;
+ // unknown control type
+ m_nIncludeCommon = CCAFlags::Name | CCAFlags::ServiceName;
+ // at least a name should be there, 'cause without a name the control could never have been
+ // inserted into its parent container
+ // In addition, the service name is absolutely necessary to create the control upon reading.
+ m_nIncludeEvents = EAFlags::ControlEvents;
+ // we always should be able to export events - this is not control type dependent
+ break;
+ }
+
+ // in general, all control types need to export the control id
+ m_nIncludeCommon |= CCAFlags::ControlId;
+
+ // is it a control bound to a calc cell?
+ if ( FormCellBindingHelper::livesInSpreadsheetDocument( m_xProps ) )
+ {
+ FormCellBindingHelper aHelper( m_xProps, nullptr );
+ {
+ if ( FormCellBindingHelper::isCellBinding( aHelper.getCurrentBinding( ) ) )
+ {
+ m_nIncludeBindings |= BAFlags::LinkedCell;
+ if ( m_nClassId == FormComponentType::LISTBOX )
+ m_nIncludeBindings |= BAFlags::ListLinkingType;
+ }
+ }
+
+ // is it a list-like control which uses a calc cell range as list source?
+ {
+ if ( FormCellBindingHelper::isCellRangeListSource( aHelper.getCurrentListSource( ) ) )
+ m_nIncludeBindings |= BAFlags::ListCellRange;
+ }
+ }
+
+ // is control bound to XForms?
+ if( !getXFormsBindName( m_xProps ).isEmpty() )
+ {
+ m_nIncludeBindings |= BAFlags::XFormsBind;
+ }
+
+ // is (list-)control bound to XForms list?
+ if( !getXFormsListBindName( m_xProps ).isEmpty() )
+ {
+ m_nIncludeBindings |= BAFlags::XFormsListBind;
+ }
+
+ // does the control have an XForms submission?
+ if( !getXFormsSubmissionName( m_xProps ).isEmpty() )
+ {
+ m_nIncludeBindings |= BAFlags::XFormsSubmission;
+ }
+ }
+
+ void OControlExport::exportCellBindingAttributes( bool _bIncludeListLinkageType )
+ {
+ try
+ {
+ FormCellBindingHelper aHelper( m_xProps, nullptr );
+ Reference< XValueBinding > xBinding( aHelper.getCurrentBinding() );
+ OSL_ENSURE( xBinding.is(), "OControlExport::exportCellBindingAttributes: invalid bindable or invalid binding!" );
+ if ( xBinding.is() )
+ {
+ AddAttribute(
+ OAttributeMetaData::getBindingAttributeNamespace(),
+ OAttributeMetaData::getBindingAttributeName( BAFlags::LinkedCell ),
+ aHelper.getStringAddressFromCellBinding( xBinding )
+ );
+
+ if ( _bIncludeListLinkageType )
+ {
+ sal_Int16 nLinkageType = FormCellBindingHelper::isCellIntegerBinding( xBinding ) ? 1 : 0;
+
+ OUStringBuffer sBuffer;
+ SvXMLUnitConverter::convertEnum(
+ sBuffer,
+ nLinkageType,
+ aListLinkageMap
+ );
+
+ AddAttribute(
+ OAttributeMetaData::getBindingAttributeNamespace(),
+ OAttributeMetaData::getBindingAttributeName( BAFlags::ListLinkingType ),
+ sBuffer.makeStringAndClear()
+ );
+ }
+
+ }
+ }
+ catch( const Exception& )
+ {
+ TOOLS_WARN_EXCEPTION( "xmloff.forms", "OControlExport::exportCellBindingAttributes" );
+ }
+ }
+
+ void OControlExport::exportXFormsBindAttributes()
+ {
+ OUString sBindName = getXFormsBindName( m_xProps );
+ AddAttribute( XML_NAMESPACE_XFORMS, XML_BIND, sBindName );
+ }
+ void OControlExport::exportXFormsListAttributes()
+ {
+ OUString sBindName = getXFormsListBindName( m_xProps );
+ AddAttribute( XML_NAMESPACE_FORM, XML_XFORMS_LIST_SOURCE, sBindName );
+ }
+ void OControlExport::exportXFormsSubmissionAttributes()
+ {
+ OUString sSubmission = getXFormsSubmissionName( m_xProps );
+ AddAttribute( XML_NAMESPACE_FORM, XML_XFORMS_SUBMISSION, sSubmission );
+ }
+ void OControlExport::exportCellListSourceRange( )
+ {
+ try
+ {
+ Reference< XListEntrySink > xSink( m_xProps, UNO_QUERY );
+ Reference< XListEntrySource > xSource;
+ if ( xSink.is() )
+ xSource = xSink->getListEntrySource();
+ OSL_ENSURE( xSource.is(), "OControlExport::exportCellListSourceRange: list source or sink!" );
+ if ( xSource.is() )
+ {
+ FormCellBindingHelper aHelper( m_xProps, nullptr );
+
+ AddAttribute(
+ OAttributeMetaData::getBindingAttributeNamespace(),
+ OAttributeMetaData::getBindingAttributeName( BAFlags::ListCellRange ),
+ aHelper.getStringAddressFromCellListSource( xSource )
+ );
+ }
+ }
+ catch( const Exception& )
+ {
+ TOOLS_WARN_EXCEPTION( "xmloff.forms", "OControlExport::exportCellListSourceRange" );
+ }
+ }
+
+ void OControlExport::exportImagePositionAttributes()
+ {
+ try
+ {
+ sal_Int16 nImagePosition = ImagePosition::Centered;
+ OSL_VERIFY( m_xProps->getPropertyValue( PROPERTY_IMAGE_POSITION ) >>= nImagePosition );
+ OSL_ENSURE( ( nImagePosition >= ImagePosition::LeftTop ) && ( nImagePosition <= ImagePosition::Centered ),
+ "OControlExport::exportImagePositionAttributes: don't know this image position!" );
+
+ if ( ( nImagePosition < ImagePosition::LeftTop ) || ( nImagePosition > ImagePosition::Centered ) )
+ // this is important to prevent potential buffer overflows below, so don't optimize
+ nImagePosition = ImagePosition::Centered;
+
+ if ( nImagePosition == ImagePosition::Centered )
+ {
+ AddAttribute( XML_NAMESPACE_FORM, GetXMLToken( XML_IMAGE_POSITION ), GetXMLToken( XML_CENTER ) );
+ }
+ else
+ {
+ const XMLTokenEnum eXmlImagePositions[] =
+ {
+ XML_START, XML_END, XML_TOP, XML_BOTTOM
+ };
+ const XMLTokenEnum eXmlImageAligns[] =
+ {
+ XML_START, XML_CENTER, XML_END
+ };
+
+ XMLTokenEnum eXmlImagePosition = eXmlImagePositions[ nImagePosition / 3 ];
+ XMLTokenEnum eXmlImageAlign = eXmlImageAligns [ nImagePosition % 3 ];
+
+ AddAttribute( XML_NAMESPACE_FORM, GetXMLToken( XML_IMAGE_POSITION ), GetXMLToken( eXmlImagePosition ) );
+ AddAttribute( XML_NAMESPACE_FORM, GetXMLToken( XML_IMAGE_ALIGN ), GetXMLToken( eXmlImageAlign ) );
+ }
+
+ exportedProperty( PROPERTY_IMAGE_POSITION );
+ // some of the controls which have an ImagePosition also have an ImageAlign for compatibility
+ // reasons. Since the ImageAlign values simply represent a sub set of the ImagePosition values,
+ // we don't need to export ImageAlign anymore
+ exportedProperty( PROPERTY_IMAGE_ALIGN );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION("xmloff.forms");
+ }
+ }
+
+ bool OControlExport::controlHasActiveDataBinding() const
+ {
+ try
+ {
+ // currently exchanging the data with a database column?
+ OUString sBoundFieldPropertyName( "BoundField" );
+ if ( m_xPropertyInfo.is() && m_xPropertyInfo->hasPropertyByName( sBoundFieldPropertyName ) )
+ {
+ Reference< XPropertySet > xBoundField;
+ m_xProps->getPropertyValue( sBoundFieldPropertyName ) >>= xBoundField;
+ if ( xBoundField.is() )
+ return true;
+ }
+
+ // currently exchanging data with an external binding?
+ Reference< XBindableValue > xBindable( m_xProps, UNO_QUERY );
+ if ( xBindable.is() && xBindable->getValueBinding().is() )
+ return true;
+ }
+ catch( const Exception& )
+ {
+ TOOLS_WARN_EXCEPTION( "xmloff.forms", "OColumnExport::controlHasActiveDataBinding" );
+ }
+
+ return false;
+ }
+
+ bool OControlExport::controlHasUserSuppliedListEntries() const
+ {
+ try
+ {
+ // an external list source?
+ Reference< XListEntrySink > xEntrySink( m_xProps, UNO_QUERY );
+ if ( xEntrySink.is() && xEntrySink->getListEntrySource().is() )
+ return false;
+
+ if ( m_xPropertyInfo.is() && m_xPropertyInfo->hasPropertyByName( PROPERTY_LISTSOURCETYPE ) )
+ {
+ ListSourceType eListSourceType = ListSourceType_VALUELIST;
+ OSL_VERIFY( m_xProps->getPropertyValue( PROPERTY_LISTSOURCETYPE ) >>= eListSourceType );
+ if ( eListSourceType == ListSourceType_VALUELIST )
+ // for value lists, the list entries as entered by the user are used
+ return true;
+
+ // for every other type, the list entries are filled with some data obtained
+ // from a database - if and only if the ListSource property is not empty
+ return getScalarListSourceValue().isEmpty();
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION("xmloff.forms");
+ }
+
+ OSL_FAIL( "OControlExport::controlHasUserSuppliedListEntries: unreachable code!" );
+ // this method should be called for list and combo boxes only
+ return true;
+ }
+
+ //= OColumnExport
+ OColumnExport::OColumnExport(IFormsExportContext& _rContext, const Reference< XPropertySet >& _rxControl, const OUString& _rControlId,
+ const Sequence< ScriptEventDescriptor >& _rEvents)
+ :OControlExport(_rContext, _rxControl, _rControlId, OUString(), _rEvents)
+ {
+ }
+
+ OColumnExport::~OColumnExport()
+ {
+ }
+
+ void OColumnExport::exportServiceNameAttribute()
+ {
+ // the attribute "service name" (which has a slightly different meaning for columns
+ DBG_CHECK_PROPERTY( PROPERTY_COLUMNSERVICENAME, OUString );
+ OUString sColumnServiceName;
+ m_xProps->getPropertyValue(PROPERTY_COLUMNSERVICENAME) >>= sColumnServiceName;
+ // the service name is a full qualified one (i.e. com.sun.star.form.TextField), but the
+ // real service name for the column (for use with the XGridColumnFactory) is only the last
+ // token of this complete name.
+ sal_Int32 nLastSep = sColumnServiceName.lastIndexOf('.');
+ OSL_ENSURE(-1 != nLastSep, "OColumnExport::startExportElement: invalid service name!");
+ sColumnServiceName = sColumnServiceName.copy(nLastSep + 1);
+ sColumnServiceName =
+ m_rContext.getGlobalContext().GetNamespaceMap().GetQNameByKey(
+ XML_NAMESPACE_OOO, sColumnServiceName );
+ // add the attribute
+ AddAttribute( OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::ServiceName)
+ , OAttributeMetaData::getCommonControlAttributeName(CCAFlags::ServiceName)
+ , sColumnServiceName);
+ // flag the property as "handled"
+ exportedProperty(PROPERTY_COLUMNSERVICENAME);
+
+ }
+
+ const char* OColumnExport::getOuterXMLElementName() const
+ {
+ return "column";
+ }
+
+ void OColumnExport::exportAttributes()
+ {
+ OControlExport::exportAttributes();
+
+ // the attribute "label"
+ exportStringPropertyAttribute(
+ OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::Label),
+ OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Label),
+ PROPERTY_LABEL);
+
+ // the style attribute
+ OUString sStyleName = m_rContext.getObjectStyleName( m_xProps );
+ if ( !sStyleName.isEmpty() )
+ {
+ AddAttribute(
+ OAttributeMetaData::getSpecialAttributeNamespace( SCAFlags::ColumnStyleName ),
+ OAttributeMetaData::getSpecialAttributeName( SCAFlags::ColumnStyleName ),
+ sStyleName
+ );
+ }
+ }
+
+ void OColumnExport::examine()
+ {
+ OControlExport::examine();
+
+ // grid columns miss some properties of the controls they're representing
+ m_nIncludeCommon &= ~CCAFlags(CCAFlags::For | CCAFlags::Printable | CCAFlags::TabIndex | CCAFlags::TabStop | CCAFlags::Label);
+ m_nIncludeSpecial &= ~SCAFlags(SCAFlags::EchoChar | SCAFlags::AutoCompletion | SCAFlags::Multiple | SCAFlags::MultiLine);
+
+ if (FormComponentType::DATEFIELD != m_nClassId)
+ // except date fields, no column has the DropDown property
+ m_nIncludeCommon &= ~CCAFlags::Dropdown;
+ }
+
+ //= OFormExport
+ OFormExport::OFormExport(IFormsExportContext& _rContext, const Reference< XPropertySet >& _rxForm,
+ const Sequence< ScriptEventDescriptor >& _rEvents)
+ :OElementExport(_rContext, _rxForm, _rEvents)
+ ,m_bCreateConnectionResourceElement(false)
+ {
+ OSL_ENSURE(m_xProps.is(), "OFormExport::OFormExport: invalid arguments!");
+ }
+
+ const char* OFormExport::getXMLElementName() const
+ {
+ return "form";
+ }
+
+ void OFormExport::exportSubTags()
+ {
+ if ( m_bCreateConnectionResourceElement && m_xProps.is() )
+ {
+ m_rContext.getGlobalContext().ClearAttrList();
+ OUString sPropValue;
+ m_xProps->getPropertyValue( PROPERTY_DATASOURCENAME ) >>= sPropValue; // if set it is a file url
+ if ( sPropValue.isEmpty() )
+ m_xProps->getPropertyValue( PROPERTY_URL ) >>= sPropValue;
+ if ( !sPropValue.isEmpty() )
+ AddAttribute(
+ OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::TargetLocation),
+ OAttributeMetaData::getCommonControlAttributeName(CCAFlags::TargetLocation),
+ m_rContext.getGlobalContext().GetRelativeReference(sPropValue));
+ if ( m_rContext.getGlobalContext().GetAttrList().getLength() )
+ {
+ SvXMLElementExport aFormElement(m_rContext.getGlobalContext(), XML_NAMESPACE_FORM, xmloff::token::XML_CONNECTION_RESOURCE, true, true);
+ }
+ }
+
+ // let the base class export the remaining properties and the events
+ OElementExport::exportSubTags();
+ // loop through all children
+ Reference< XIndexAccess > xCollection(m_xProps, UNO_QUERY);
+ OSL_ENSURE(xCollection.is(), "OFormLayerXMLExport::implExportForm: a form which is not an index access? Suspicious!");
+
+ if (xCollection.is())
+ m_rContext.exportCollectionElements(xCollection);
+ }
+
+ void OFormExport::exportAttributes()
+ {
+ sal_Int32 i=0;
+
+ // the string properties
+ {
+ static const FormAttributes eStringPropertyIds[] =
+ {
+ faName, /*faAction,*/ faCommand, faFilter, faOrder
+ };
+ static const char * aStringPropertyNames[] =
+ {
+ PROPERTY_NAME, /*PROPERTY_TARGETURL,*/ PROPERTY_COMMAND, PROPERTY_FILTER, PROPERTY_ORDER
+ };
+ static const sal_Int32 nIdCount = SAL_N_ELEMENTS(eStringPropertyIds);
+ #if OSL_DEBUG_LEVEL > 0
+ static const sal_Int32 nNameCount = SAL_N_ELEMENTS(aStringPropertyNames);
+ OSL_ENSURE((nIdCount == nNameCount),
+ "OFormExport::exportAttributes: somebody tampered with the maps (1)!");
+ #endif
+ for (i=0; igetPropertyValue( PROPERTY_DATASOURCENAME ) >>= sPropValue;
+ m_bCreateConnectionResourceElement = sPropValue.isEmpty();
+ if ( !m_bCreateConnectionResourceElement )
+ {
+ INetURLObject aURL(sPropValue);
+ m_bCreateConnectionResourceElement = ( aURL.GetProtocol() == INetProtocol::File );
+ if ( !m_bCreateConnectionResourceElement )
+ exportStringPropertyAttribute(
+ OAttributeMetaData::getFormAttributeNamespace(faDatasource),
+ OAttributeMetaData::getFormAttributeName(faDatasource),
+ PROPERTY_DATASOURCENAME);
+ }
+ else
+ exportedProperty(PROPERTY_URL);
+ if ( m_bCreateConnectionResourceElement )
+ exportedProperty(PROPERTY_DATASOURCENAME);
+ }
+
+ // the boolean properties
+ {
+ static const FormAttributes eBooleanPropertyIds[] =
+ {
+ faAllowDeletes, faAllowInserts, faAllowUpdates, faApplyFilter, faEscapeProcessing, faIgnoreResult
+ };
+ static const char * pBooleanPropertyNames[] =
+ {
+ PROPERTY_ALLOWDELETES,
+ PROPERTY_ALLOWINSERTS,
+ PROPERTY_ALLOWUPDATES,
+ PROPERTY_APPLYFILTER,
+ PROPERTY_ESCAPEPROCESSING,
+ PROPERTY_IGNORERESULT
+ };
+ static const BoolAttrFlags nBooleanPropertyAttrFlags[] =
+ {
+ BoolAttrFlags::DefaultTrue, BoolAttrFlags::DefaultTrue, BoolAttrFlags::DefaultTrue, BoolAttrFlags::DefaultFalse, BoolAttrFlags::DefaultTrue, BoolAttrFlags::DefaultFalse
+ };
+ static const sal_Int32 nIdCount = SAL_N_ELEMENTS(eBooleanPropertyIds);
+ #if OSL_DEBUG_LEVEL > 0
+ static const sal_Int32 nNameCount = SAL_N_ELEMENTS(pBooleanPropertyNames);
+ static const sal_Int32 nFlagsCount = SAL_N_ELEMENTS(nBooleanPropertyAttrFlags);
+ OSL_ENSURE((nIdCount == nNameCount) && (nNameCount == nFlagsCount),
+ "OFormExport::exportAttributes: somebody tampered with the maps (2)!");
+ #endif
+ for (i=0; i
+
+#include
+#include
+
+#include
+#include
+#include
+#include "propertyexport.hxx"
+#include "callbacks.hxx"
+#include "controlelement.hxx"
+#include "valueproperties.hxx"
+
+class SvXMLElementExport;
+namespace xmloff
+{
+
+ //= OElementExport
+ class OElementExport : public OPropertyExport
+ {
+ protected:
+ css::uno::Sequence< css::script::ScriptEventDescriptor >
+ m_aEvents;
+
+ std::unique_ptr m_pXMLElement; // XML element doing the concrete startElement etc.
+
+ public:
+ OElementExport(IFormsExportContext& _rContext,
+ const css::uno::Reference< css::beans::XPropertySet >& _rxProps,
+ const css::uno::Sequence< css::script::ScriptEventDescriptor >& _rEvents);
+ virtual ~OElementExport();
+
+ void doExport();
+
+ protected:
+ /// get the name of the XML element
+ virtual const char* getXMLElementName() const = 0;
+ /// examine the element we're exporting
+ virtual void examine();
+ /// export the attributes
+ virtual void exportAttributes();
+ /// export any sub tags
+ virtual void exportSubTags();
+
+ /** exports the events (as script:events tag)
+ */
+ void exportEvents();
+
+ /** add the service-name attribute to the export context
+ */
+ virtual void exportServiceNameAttribute();
+
+ /// start the XML element
+ virtual void implStartElement(const char* _pName);
+
+ /// ends the XML element
+ virtual void implEndElement();
+ };
+
+ //= OControlExport
+ /** Helper class for handling xml elements representing a form control
+ */
+ class OControlExport
+ :public OControlElement
+ ,public OValuePropertiesMetaData
+ ,public OElementExport
+ {
+ protected:
+ typedef o3tl::sorted_vector Int16Set;
+ // used below
+
+ OUString m_sControlId; // the control id to use when exporting
+ OUString m_sReferringControls; // list of referring controls (i.e. their id's)
+ sal_Int16 m_nClassId; // class id of the control we're representing
+ ElementType m_eType; // (XML) type of the control we're representing
+ CCAFlags m_nIncludeCommon; // common control attributes to include
+ DAFlags m_nIncludeDatabase; // common database attributes to include
+ SCAFlags m_nIncludeSpecial; // special attributes to include
+ EAFlags m_nIncludeEvents; // events to include
+ BAFlags m_nIncludeBindings; // binding attributes to include
+
+ std::unique_ptr m_pOuterElement; // XML element doing the concrete startElement etc. for the outer element
+
+ public:
+ /** constructs an object capable of exporting controls
+
+ You need at least two pre-requisites from outside: The control to be exported needs to have a class id
+ assigned, and you need the list control-ids of all the controls referring to this one as LabelControl.
+ This information can't be collected when known only the control itself and not it's complete context.
+
+ @param _rControlId
+ the control id to use when exporting the control
+ @param _rReferringControls
+ the comma-separated list of control-ids of all the controls referring to this one as LabelControl
+ */
+ OControlExport(IFormsExportContext& _rContext,
+ const css::uno::Reference< css::beans::XPropertySet >& _rxControl,
+ const OUString& _rControlId,
+ const OUString& _rReferringControls,
+ const css::uno::Sequence< css::script::ScriptEventDescriptor >& _rxEvents);
+
+ protected:
+ /// start the XML element
+ virtual void implStartElement(const char* _pName) override;
+
+ /// ends the XML element
+ virtual void implEndElement() override;
+
+ /// get the name of the outer XML element
+ virtual const char* getOuterXMLElementName() const;
+
+ // get the name of the XML element
+ virtual const char* getXMLElementName() const override;
+
+ /** examine the control. Some kind of CtorImpl.
+ */
+ virtual void examine() override;
+
+ /// exports the attributes for the outer element
+ void exportOuterAttributes();
+
+ /// exports the attributes for the inner element
+ void exportInnerAttributes();
+
+ /// export the attributes
+ virtual void exportAttributes() override;
+
+ /** writes everything which needs to be represented as sub tag
+ */
+ void exportSubTags() override;
+
+ /** adds the attributes which are handled via generic IPropertyHandlers
+
+ In the future, this really should be *all* attributes, instead of this shitload of
+ hand-crafted code we have currently...
+ */
+ void exportGenericHandlerAttributes();
+
+ /** adds common control attributes to the XMLExport context given
+
+ The attribute list of the context is not cleared initially, this is the responsibility of the caller.
+ */
+ void exportCommonControlAttributes();
+
+ /** adds database attributes to the XMLExport context given
+
+ The attribute list of the context is not cleared initially, this is the responsibility of the caller.
+ */
+ void exportDatabaseAttributes();
+
+ /** adds the XML attributes which are related to binding controls to
+ external values and/or list sources
+ */
+ void exportBindingAttributes();
+
+ /** adds attributes which are special to a control type to the export context's attribute list
+ */
+ void exportSpecialAttributes();
+
+ /** exports the ListSource property of a control as attribute
+
+ The ListSource property may be exported in different ways: For a ComboBox, it is an attribute
+ of the form:combobox element.
+
+ For a ListBox, it's an attribute if the ListSourceType states that the ListBox does not
+ display a value list. In case of a value list, the ListSource is not exported, and the pairs of
+ StringItem/ValueItem are exported as sub-elements.
+
+ This method does the attribute part: It exports the ListSource property as attribute, not caring
+ about whether the object is a ComboBox or a ListBox.
+ */
+ void exportListSourceAsAttribute();
+
+ /** exports the ListSource property of a control as XML elements
+
+ @see exportListSourceAsAttribute
+ */
+ void exportListSourceAsElements();
+
+ /** gets a Sequence< sal_Int16 > property value as set of sal_Int16's
+ @param _rPropertyName
+ the property name to use
+ @param _rOut
+ out parameter. The set of integers.
+ */
+ void getSequenceInt16PropertyAsSet(const OUString& _rPropertyName, Int16Set& _rOut);
+
+ /** exports the attribute which descrives a cell value binding of a control
+ in a spreadsheet document
+ */
+ void exportCellBindingAttributes( bool _bIncludeListLinkageType );
+
+ /** exports the attribute(s) which bind this control to XForms */
+ void exportXFormsBindAttributes();
+
+ /** exports the attribute(s) which bind the list of a list
+ control to XForms */
+ void exportXFormsListAttributes();
+
+ /** exports the attribute(s) for an XForms submission */
+ void exportXFormsSubmissionAttributes();
+
+ /** exports the attribute which descrives a cell range which acts as list source for
+ a list-like control
+ */
+ void exportCellListSourceRange( );
+
+ /** exports the attribute(s) for the ImagePosition property
+ */
+ void exportImagePositionAttributes();
+
+ /** determines whether the control we're exporting has an active data binding.
+
+ Bindings which count here are:
+ - an established connection to a database field
+ - a binding to an external value supplier (XValueBinding)
+
+ */
+ bool controlHasActiveDataBinding() const;
+
+ /** retrieves the string specifying the ListSource of a list or combo box
+ */
+ OUString getScalarListSourceValue() const;
+
+ /** determines whether the list entries (of a combo or list box) are supplied by the user
+
+ List entries may be
+ - specified by the user
+ - specified by an external list source (XListEntrySource)
+ - obtained from a database query (in various ways)
+
+
+ In the latter two cases, this method will return
+ */
+ bool controlHasUserSuppliedListEntries() const;
+ };
+
+ //= OColumnExport
+ /** Helper class for exporting a grid column
+ */
+ class OColumnExport : public OControlExport
+ {
+ public:
+ /** ctor
+ @see OColumnExport::OColumnExport
+ */
+ OColumnExport(IFormsExportContext& _rContext,
+ const css::uno::Reference< css::beans::XPropertySet >& _rxControl,
+ const OUString& _rControlId,
+ const css::uno::Sequence< css::script::ScriptEventDescriptor >& _rxEvents);
+
+ virtual ~OColumnExport() override;
+
+ protected:
+ // OControlExport overridables
+ virtual const char* getOuterXMLElementName() const override;
+ virtual void exportServiceNameAttribute() override;
+ virtual void exportAttributes() override;
+
+ // OElementExport overridables
+ virtual void examine() override;
+ };
+
+ //= OFormExport
+ /** Helper class for handling xml elements representing a form
+
+ In opposite to the class OControlExport, OFormExport is unable to export a complete
+ form. Instead the client has to care for sub elements of the form itself.
+ */
+ class OFormExport
+ :public OControlElement
+ ,public OElementExport
+ {
+ bool m_bCreateConnectionResourceElement;
+ public:
+ /** constructs an object capable of exporting controls
+ */
+ OFormExport(IFormsExportContext& _rContext,
+ const css::uno::Reference< css::beans::XPropertySet >& _rxForm,
+ const css::uno::Sequence< css::script::ScriptEventDescriptor >& _rxEvents
+ );
+
+ protected:
+ virtual const char* getXMLElementName() const override;
+ virtual void exportSubTags() override;
+ virtual void exportAttributes() override;
+ };
+} // namespace xmloff
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/forms/elementimport.cxx b/xmloff/source/forms/elementimport.cxx
new file mode 100644
index 000000000..19f247aae
--- /dev/null
+++ b/xmloff/source/forms/elementimport.cxx
@@ -0,0 +1,2073 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "elementimport.hxx"
+#include
+#include
+#include "strings.hxx"
+#include "callbacks.hxx"
+#include
+#include "eventimport.hxx"
+#include
+#include "formenums.hxx"
+#include
+#include "gridcolumnproptranslator.hxx"
+#include "property_description.hxx"
+#include "property_meta_data.hxx"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+namespace xmloff
+{
+
+ using namespace ::xmloff::token;
+ using namespace ::com::sun::star;
+ using namespace ::com::sun::star::uno;
+ using namespace ::com::sun::star::awt;
+ using namespace ::com::sun::star::container;
+ using namespace ::com::sun::star::beans;
+ using namespace ::com::sun::star::script;
+ using namespace ::com::sun::star::lang;
+ using namespace ::com::sun::star::form;
+ using namespace ::com::sun::star::xml;
+ using namespace ::com::sun::star::xml::sax;
+ using namespace ::com::sun::star::util;
+ using namespace ::com::sun::star::text;
+ using namespace ::comphelper;
+ using ::com::sun::star::xml::sax::XAttributeList;
+
+#define PROPID_VALUE 1
+#define PROPID_CURRENT_VALUE 2
+#define PROPID_MIN_VALUE 3
+#define PROPID_MAX_VALUE 4
+
+ namespace {
+
+ struct PropertyValueLess
+ {
+ bool operator()(const PropertyValue& _rLeft, const PropertyValue& _rRight)
+ {
+ return _rLeft.Name < _rRight.Name;
+ }
+ };
+
+ }
+
+ //= OElementNameMap
+ std::map OElementNameMap::s_sElementTranslations2;
+
+ const OControlElement::ElementType& operator ++(OControlElement::ElementType& _e)
+ {
+ OControlElement::ElementType e = _e;
+ sal_Int32 nAsInt = static_cast(e);
+ _e = static_cast( ++nAsInt );
+ return _e;
+ }
+
+ OControlElement::ElementType OElementNameMap::getElementType(sal_Int32 nElement)
+ {
+ if ( s_sElementTranslations2.empty() )
+ { // initialize
+ for (ElementType eType=ElementType(0); eTypesecond;
+
+ return UNKNOWN;
+ }
+
+ //= OElementImport
+ OElementImport::OElementImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer)
+ :OPropertyImport(_rImport)
+ ,m_rFormImport(_rImport)
+ ,m_rEventManager(_rEventManager)
+ ,m_pStyleElement( nullptr )
+ ,m_xParentContainer(_rxParentContainer)
+ ,m_bImplicitGenericAttributeHandling( true )
+ {
+ OSL_ENSURE(m_xParentContainer.is(), "OElementImport::OElementImport: invalid parent container!");
+ }
+
+ OElementImport::~OElementImport()
+ {
+ }
+
+ OUString OElementImport::determineDefaultServiceName() const
+ {
+ return OUString();
+ }
+
+ void OElementImport::startFastElement(sal_Int32 nElement, const Reference< css::xml::sax::XFastAttributeList >& _rxAttrList)
+ {
+ ENTER_LOG_CONTEXT( "xmloff::OElementImport - importing one element" );
+
+ const OUString sControlImplementation = _rxAttrList->getOptionalValue( XML_ELEMENT(FORM, XML_CONTROL_IMPLEMENTATION) );
+
+ // retrieve the service name
+ if ( !sControlImplementation.isEmpty() )
+ {
+ OUString sOOoImplementationName;
+ const sal_uInt16 nImplPrefix = GetImport().GetNamespaceMap().GetKeyByAttrValueQName( sControlImplementation, &sOOoImplementationName );
+ m_sServiceName = ( nImplPrefix == XML_NAMESPACE_OOO ) ? sOOoImplementationName : sControlImplementation;
+ }
+
+ if ( m_sServiceName.isEmpty() )
+ m_sServiceName = determineDefaultServiceName();
+
+ // create the object *now*. This allows setting properties in the various handleAttribute methods.
+ // (Though currently not all code is migrated to this pattern, most attributes are still handled
+ // by remembering the value (via implPushBackPropertyValue), and setting the correct property value
+ // later (in OControlImport::StartElement).)
+ m_xElement = createElement();
+ if ( m_xElement.is() )
+ m_xInfo = m_xElement->getPropertySetInfo();
+
+ // call the base class
+ OPropertyImport::startFastElement( nElement, _rxAttrList );
+ }
+
+ css::uno::Reference< css::xml::sax::XFastContextHandler > OElementImport::createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& _rxAttrList )
+ {
+ if( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) )
+ return new OFormEventsImportContext(m_rFormImport.getGlobalContext(), *this);
+
+ return OPropertyImport::createFastChildContext(nElement, _rxAttrList);
+ }
+
+ void OElementImport::endFastElement(sal_Int32 )
+ {
+ OSL_ENSURE(m_xElement.is(), "OElementImport::EndElement: invalid element created!");
+ if (!m_xElement.is())
+ return;
+
+ // apply the non-generic properties
+ implApplySpecificProperties();
+
+ // set the generic properties
+ implApplyGenericProperties();
+
+ // set the style properties
+ if ( m_pStyleElement && m_xElement.is() )
+ {
+ Reference< XPropertySet > xPropTranslation =
+ new OGridColumnPropertyTranslator( Reference< XMultiPropertySet >( m_xElement, UNO_QUERY ) );
+ const_cast< XMLTextStyleContext* >( m_pStyleElement )->FillPropertySet( xPropTranslation );
+
+ const OUString sNumberStyleName = m_pStyleElement->GetDataStyleName( );
+ if ( !sNumberStyleName.isEmpty() )
+ // the style also has a number (sub) style
+ m_rContext.applyControlNumberStyle( m_xElement, sNumberStyleName );
+ }
+
+ // insert the element into the parent container
+ if (m_sName.isEmpty())
+ {
+ OSL_FAIL("OElementImport::EndElement: did not find a name attribute!");
+ m_sName = implGetDefaultName();
+ }
+
+ if (m_xParentContainer.is())
+ m_xParentContainer->insertByName(m_sName, Any(m_xElement));
+
+ LEAVE_LOG_CONTEXT( );
+ }
+
+ void OElementImport::implApplySpecificProperties()
+ {
+ if ( m_aValues.empty() )
+ return;
+
+ // set all the properties we collected
+#if OSL_DEBUG_LEVEL > 0
+ // check if the object has all the properties
+ // (We do this in the non-pro version only. Doing it all the time would be too much expensive)
+ if ( m_xInfo.is() )
+ {
+ for ( const auto& rCheck : m_aValues )
+ {
+ OSL_ENSURE(m_xInfo->hasPropertyByName(rCheck.Name),
+ OStringBuffer("OElementImport::implApplySpecificProperties: read a property (" +
+ OUStringToOString(rCheck.Name, RTL_TEXTENCODING_ASCII_US) +
+ ") which does not exist on the element!").getStr());
+ }
+ }
+#endif
+
+ // set the properties
+ const Reference< XMultiPropertySet > xMultiProps(m_xElement, UNO_QUERY);
+ bool bSuccess = false;
+ if (xMultiProps.is())
+ {
+ // translate our properties so that the XMultiPropertySet can handle them
+
+ // sort our property value array so that we can use it in a setPropertyValues
+ ::std::sort( m_aValues.begin(), m_aValues.end(), PropertyValueLess());
+
+ // the names
+ Sequence< OUString > aNames(m_aValues.size());
+ OUString* pNames = aNames.getArray();
+ // the values
+ Sequence< Any > aValues(m_aValues.size());
+ Any* pValues = aValues.getArray();
+ // copy
+
+ for ( const auto& rPropValues : m_aValues )
+ {
+ *pNames = rPropValues.Name;
+ *pValues = rPropValues.Value;
+ ++pNames;
+ ++pValues;
+ }
+
+ try
+ {
+ xMultiProps->setPropertyValues(aNames, aValues);
+ bSuccess = true;
+ }
+ catch(const Exception&)
+ {
+ DBG_UNHANDLED_EXCEPTION("xmloff.forms");
+ OSL_FAIL("OElementImport::implApplySpecificProperties: could not set the properties (using the XMultiPropertySet)!");
+ }
+ }
+
+ if (bSuccess)
+ return;
+
+ // no XMultiPropertySet or setting all properties at once failed
+ for ( const auto& rPropValues : m_aValues )
+ {
+ // this try/catch here is expensive, but because this is just a fallback which should normally not be
+ // used it's acceptable this way ...
+ try
+ {
+ m_xElement->setPropertyValue(rPropValues.Name, rPropValues.Value);
+ }
+ catch(const Exception&)
+ {
+ DBG_UNHANDLED_EXCEPTION("xmloff.forms");
+ OSL_FAIL(OStringBuffer("OElementImport::implApplySpecificProperties: could not set the property \"" +
+ OUStringToOString(rPropValues.Name, RTL_TEXTENCODING_ASCII_US) +
+ "\"!").getStr());
+ }
+ }
+ }
+
+ void OElementImport::implApplyGenericProperties()
+ {
+ if ( m_aGenericValues.empty() )
+ return;
+
+ Reference< XPropertyContainer > xDynamicProperties( m_xElement, UNO_QUERY );
+
+ // PropertyValueArray::iterator aEnd = m_aGenericValues.end();
+ for ( auto& rPropValues : m_aGenericValues )
+ {
+ // check property type for numeric types before setting
+ // the property
+ try
+ {
+ // if such a property does not yet exist at the element, create it if necessary
+ const bool bExistentProperty = m_xInfo->hasPropertyByName( rPropValues.Name );
+ if ( !bExistentProperty )
+ {
+ if ( !xDynamicProperties.is() )
+ {
+ SAL_WARN( "xmloff", "OElementImport::implApplyGenericProperties: encountered an unknown property ("
+ << rPropValues.Name << "), but component is no PropertyBag!");
+ continue;
+ }
+
+ xDynamicProperties->addProperty(
+ rPropValues.Name,
+ PropertyAttribute::BOUND | PropertyAttribute::REMOVABLE,
+ rPropValues.Value
+ );
+
+ // re-fetch the PropertySetInfo
+ m_xInfo = m_xElement->getPropertySetInfo();
+ }
+
+ // determine the type of the value (source for the following conversion)
+ TypeClass eValueTypeClass = rPropValues.Value.getValueTypeClass();
+ const bool bValueIsSequence = TypeClass_SEQUENCE == eValueTypeClass;
+ if ( bValueIsSequence )
+ {
+ uno::Type aSimpleType( getSequenceElementType( rPropValues.Value.getValueType() ) );
+ eValueTypeClass = aSimpleType.getTypeClass();
+ }
+
+ // determine the type of the property (target for the following conversion)
+ const Property aProperty( m_xInfo->getPropertyByName( rPropValues.Name ) );
+ TypeClass ePropTypeClass = aProperty.Type.getTypeClass();
+ const bool bPropIsSequence = TypeClass_SEQUENCE == ePropTypeClass;
+ if( bPropIsSequence )
+ {
+ uno::Type aSimpleType( ::comphelper::getSequenceElementType( aProperty.Type ) );
+ ePropTypeClass = aSimpleType.getTypeClass();
+ }
+
+ if ( bPropIsSequence != bValueIsSequence )
+ {
+ OSL_FAIL( "OElementImport::implImportGenericProperties: either both value and property should be a sequence, or none of them!" );
+ continue;
+ }
+
+ if ( bValueIsSequence )
+ {
+ Sequence< Any > aXMLValueList;
+ rPropValues.Value >>= aXMLValueList;
+ // just skip this part if empty sequence
+ if (!aXMLValueList.getLength())
+ continue;
+
+ Sequence< sal_Int16 > aPropertyValueList( aXMLValueList.getLength() );
+
+ SAL_WARN_IF( eValueTypeClass != TypeClass_ANY, "xmloff",
+ "OElementImport::implApplyGenericProperties: only ANYs should have been imported as generic list property!" );
+ // (OPropertyImport should produce only Sequencer< Any >, since it cannot know the real type
+
+ SAL_WARN_IF( ePropTypeClass != TypeClass_SHORT, "xmloff",
+ "OElementImport::implApplyGenericProperties: conversion to sequences other than 'sequence< short >' not implemented, yet!" );
+
+
+ std::transform(std::cbegin(aXMLValueList), std::cend(aXMLValueList), aPropertyValueList.getArray(),
+ [](const Any& rXMLValue) -> sal_Int16 {
+ // only value sequences of numeric types implemented so far.
+ double nVal( 0 );
+ OSL_VERIFY( rXMLValue >>= nVal );
+ return static_cast< sal_Int16 >( nVal );
+ });
+
+ rPropValues.Value <<= aPropertyValueList;
+ }
+ else if ( ePropTypeClass != eValueTypeClass )
+ {
+ switch ( eValueTypeClass )
+ {
+ case TypeClass_DOUBLE:
+ {
+ double nVal = 0;
+ rPropValues.Value >>= nVal;
+ switch( ePropTypeClass )
+ {
+ case TypeClass_BYTE:
+ rPropValues.Value <<= static_cast< sal_Int8 >( nVal );
+ break;
+ case TypeClass_SHORT:
+ rPropValues.Value <<= static_cast< sal_Int16 >( nVal );
+ break;
+ case TypeClass_UNSIGNED_SHORT:
+ rPropValues.Value <<= static_cast< sal_uInt16 >( nVal );
+ break;
+ case TypeClass_LONG:
+ case TypeClass_ENUM:
+ rPropValues.Value <<= static_cast< sal_Int32 >( nVal );
+ break;
+ case TypeClass_UNSIGNED_LONG:
+ rPropValues.Value <<= static_cast< sal_uInt32 >( nVal );
+ break;
+ case TypeClass_UNSIGNED_HYPER:
+ rPropValues.Value <<= static_cast< sal_uInt64 >( nVal );
+ break;
+ case TypeClass_HYPER:
+ rPropValues.Value <<= static_cast< sal_Int64 >( nVal );
+ break;
+ default:
+ OSL_FAIL( "OElementImport::implImportGenericProperties: unsupported value type!" );
+ break;
+ }
+ }
+ break;
+ default:
+ OSL_FAIL( "OElementImport::implImportGenericProperties: non-double values not supported!" );
+ break;
+ }
+ }
+
+ m_xElement->setPropertyValue( rPropValues.Name, rPropValues.Value );
+ }
+ catch(const Exception&)
+ {
+ DBG_UNHANDLED_EXCEPTION("xmloff.forms");
+ OSL_FAIL(OStringBuffer("OElementImport::EndElement: could not set the property \"" +
+ OUStringToOString(rPropValues.Name, RTL_TEXTENCODING_ASCII_US) +
+ "\"!").getStr());
+ }
+ }
+ }
+
+ OUString OElementImport::implGetDefaultName() const
+ {
+ // no optimization here. If this method gets called, the XML stream did not contain a name for the
+ // element, which is a heavy error. So in this case we don't care for performance
+ static constexpr OUStringLiteral sUnnamedName = u"unnamed";
+ OSL_ENSURE(m_xParentContainer.is(), "OElementImport::implGetDefaultName: no parent container!");
+ if (!m_xParentContainer.is())
+ return sUnnamedName;
+ Sequence< OUString > aNames = m_xParentContainer->getElementNames();
+
+ for (sal_Int32 i=0; i<32768; ++i) // the limit is nearly arbitrary...
+ {
+ // assemble the new name (suggestion)
+ OUString sReturn = sUnnamedName + OUString::number(i);
+ // check the existence (this is the bad performance part...)
+ if (comphelper::findValue(aNames, sReturn) == -1)
+ // not found the name
+ return sReturn;
+ }
+ OSL_FAIL("OElementImport::implGetDefaultName: did not find a free name!");
+ return sUnnamedName;
+ }
+
+ PropertyGroups::const_iterator OElementImport::impl_matchPropertyGroup( const PropertyGroups& i_propertyGroups ) const
+ {
+ ENSURE_OR_RETURN( m_xInfo.is(), "OElementImport::impl_matchPropertyGroup: no property set info!", i_propertyGroups.end() );
+
+ return std::find_if(i_propertyGroups.cbegin(), i_propertyGroups.cend(), [&](const PropertyDescriptionList& rGroup) {
+ return std::all_of(rGroup.cbegin(), rGroup.cend(), [&](const PropertyDescription* prop) {
+ return m_xInfo->hasPropertyByName( prop->propertyName );
+ });
+ });
+ }
+
+ bool OElementImport::tryGenericAttribute( sal_Int32 nElement, const OUString& _rValue )
+ {
+ // the generic approach (which I hope all props will be migrated to, on the medium term): property handlers
+ const AttributeDescription attribute( metadata::getAttributeDescription( nElement ) );
+ if ( attribute.attributeToken != XML_TOKEN_INVALID )
+ {
+ PropertyGroups propertyGroups;
+ metadata::getPropertyGroupList( attribute, propertyGroups );
+ const PropertyGroups::const_iterator pos = impl_matchPropertyGroup( propertyGroups );
+ if ( pos == propertyGroups.end() )
+ return false;
+
+ do
+ {
+ const PropertyDescriptionList& rProperties( *pos );
+ const PropertyDescription* first = *rProperties.begin();
+ if ( !first )
+ {
+ SAL_WARN( "xmloff.forms", "OElementImport::handleAttribute: invalid property description!" );
+ break;
+ }
+
+ const PPropertyHandler handler = (*first->factory)( first->propertyId );
+ if ( !handler )
+ {
+ SAL_WARN( "xmloff.forms", "OElementImport::handleAttribute: invalid property handler!" );
+ break;
+ }
+
+ PropertyValues aValues;
+ for ( const auto& propDesc : rProperties )
+ {
+ aValues[ propDesc->propertyId ] = Any();
+ }
+ if ( handler->getPropertyValues( _rValue, aValues ) )
+ {
+ for ( const auto& propDesc : rProperties )
+ {
+ implPushBackPropertyValue( propDesc->propertyName, aValues[ propDesc->propertyId ] );
+ }
+ }
+ }
+ while ( false );
+
+ // handled
+ return true;
+ }
+ return false;
+ }
+
+ bool OElementImport::handleAttribute(sal_Int32 nElement, const OUString& _rValue)
+ {
+ auto nLocal = nElement & TOKEN_MASK;
+ if ( nLocal == XML_CONTROL_IMPLEMENTATION )
+ // ignore this, it has already been handled in OElementImport::StartElement
+ return true;
+
+ if ( nLocal == XML_NAME )
+ {
+ if ( m_sName.isEmpty() )
+ // remember the name for later use in EndElement
+ m_sName = _rValue;
+ return true;
+ }
+
+ // maybe it's the style attribute?
+ if ( nLocal == XML_TEXT_STYLE_NAME )
+ {
+ const SvXMLStyleContext* pStyleContext = m_rContext.getStyleElement( _rValue );
+ OSL_ENSURE( pStyleContext, "OElementImport::handleAttribute: do not know the style!" );
+ // remember the element for later usage.
+ m_pStyleElement = dynamic_cast( pStyleContext );
+ return true;
+ }
+
+ if ( m_bImplicitGenericAttributeHandling )
+ if ( tryGenericAttribute( nElement, _rValue ) )
+ return true;
+
+ // let the base class handle it
+ return OPropertyImport::handleAttribute( nElement, _rValue);
+ }
+
+ Reference< XPropertySet > OElementImport::createElement()
+ {
+ Reference< XPropertySet > xReturn;
+ if (!m_sServiceName.isEmpty())
+ {
+ Reference< XComponentContext > xContext = m_rFormImport.getGlobalContext().GetComponentContext();
+ Reference< XInterface > xPure = xContext->getServiceManager()->createInstanceWithContext(m_sServiceName, xContext);
+ OSL_ENSURE(xPure.is(),
+ OStringBuffer("OElementImport::createElement: service factory gave me no object (service name: " +
+ OUStringToOString(m_sServiceName, RTL_TEXTENCODING_ASCII_US) +
+ ")!").getStr());
+ xReturn.set(xPure, UNO_QUERY);
+ }
+ else
+ OSL_FAIL("OElementImport::createElement: no service name to create an element!");
+
+ return xReturn;
+ }
+
+ void OElementImport::registerEvents(const Sequence< ScriptEventDescriptor >& _rEvents)
+ {
+ OSL_ENSURE(m_xElement.is(), "OElementImport::registerEvents: no element to register events for!");
+ m_rEventManager.registerEvents(m_xElement, _rEvents);
+ }
+
+ void OElementImport::simulateDefaultedAttribute(sal_Int32 nElement, const OUString& _rPropertyName, const char* _pAttributeDefault)
+ {
+ OSL_ENSURE( m_xInfo.is(), "OPropertyImport::simulateDefaultedAttribute: the component should be more gossipy about it's properties!" );
+
+ if ( !m_xInfo.is() || m_xInfo->hasPropertyByName( _rPropertyName ) )
+ {
+ if ( !encounteredAttribute( nElement ) )
+ OSL_VERIFY( handleAttribute( XML_ELEMENT(FORM, (nElement & TOKEN_MASK)), OUString::createFromAscii( _pAttributeDefault ) ) );
+ }
+ }
+
+ //= OControlImport
+ OControlImport::OControlImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer)
+ :OElementImport(_rImport, _rEventManager, _rxParentContainer)
+ ,m_eElementType(OControlElement::UNKNOWN)
+ {
+ disableImplicitGenericAttributeHandling();
+ }
+
+ OControlImport::OControlImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer, OControlElement::ElementType _eType)
+ :OElementImport(_rImport, _rEventManager, _rxParentContainer)
+ ,m_eElementType(_eType)
+ {
+ disableImplicitGenericAttributeHandling();
+ }
+
+ OUString OControlImport::determineDefaultServiceName() const
+ {
+ const char* pServiceName = nullptr;
+ switch ( m_eElementType )
+ {
+ case OControlElement::TEXT:
+ case OControlElement::TEXT_AREA:
+ case OControlElement::PASSWORD: pServiceName = "com.sun.star.form.component.TextField"; break;
+ case OControlElement::FILE: pServiceName = "com.sun.star.form.component.FileControl"; break;
+ case OControlElement::FORMATTED_TEXT: pServiceName = "com.sun.star.form.component.FormattedField"; break;
+ case OControlElement::FIXED_TEXT: pServiceName = "com.sun.star.form.component.FixedText"; break;
+ case OControlElement::COMBOBOX: pServiceName = "com.sun.star.form.component.ComboBox"; break;
+ case OControlElement::LISTBOX: pServiceName = "com.sun.star.form.component.ListBox"; break;
+ case OControlElement::BUTTON: pServiceName = "com.sun.star.form.component.CommandButton"; break;
+ case OControlElement::IMAGE: pServiceName = "com.sun.star.form.component.ImageButton"; break;
+ case OControlElement::CHECKBOX: pServiceName = "com.sun.star.form.component.CheckBox"; break;
+ case OControlElement::RADIO: pServiceName = "com.sun.star.form.component.RadioButton"; break;
+ case OControlElement::FRAME: pServiceName = "com.sun.star.form.component.GroupBox"; break;
+ case OControlElement::IMAGE_FRAME: pServiceName = "com.sun.star.form.component.DatabaseImageControl"; break;
+ case OControlElement::HIDDEN: pServiceName = "com.sun.star.form.component.HiddenControl"; break;
+ case OControlElement::GRID: pServiceName = "com.sun.star.form.component.GridControl"; break;
+ case OControlElement::VALUERANGE: pServiceName = "com.sun.star.form.component.ScrollBar"; break;
+ case OControlElement::TIME: pServiceName = "com.sun.star.form.component.TimeField"; break;
+ case OControlElement::DATE: pServiceName = "com.sun.star.form.component.DateField"; break;
+ default: break;
+ }
+ if ( pServiceName != nullptr )
+ return OUString::createFromAscii( pServiceName );
+ return OUString();
+ }
+
+ void OControlImport::addOuterAttributes(const Reference< XFastAttributeList >& _rxOuterAttribs)
+ {
+ OSL_ENSURE(!m_xOuterAttributes.is(), "OControlImport::addOuterAttributes: already have these attributes!");
+ m_xOuterAttributes = _rxOuterAttribs;
+ }
+
+ bool OControlImport::handleAttribute(sal_Int32 nElement, const OUString& _rValue)
+ {
+ static sal_Int32 nLinkedCellAttributeName = OAttributeMetaData::getBindingAttributeToken(BAFlags::LinkedCell);
+
+ if ((nElement & TOKEN_MASK) == XML_ID)
+ { // it's the control id
+ if (IsTokenInNamespace(nElement, XML_NAMESPACE_XML))
+ {
+ m_sControlId = _rValue;
+ }
+ else if (IsTokenInNamespace(nElement, XML_NAMESPACE_FORM))
+ {
+ if (m_sControlId.isEmpty())
+ {
+ m_sControlId = _rValue;
+ }
+ }
+ return true;
+ }
+
+ if ( (nElement & TOKEN_MASK) == nLinkedCellAttributeName )
+ { // it's the address of a spreadsheet cell
+ m_sBoundCellAddress = _rValue;
+ return true;
+ }
+
+ if ( nElement == XML_ELEMENT(XFORMS, XML_BIND ) )
+ {
+ m_sBindingID = _rValue;
+ return true;
+ }
+
+ if ( nElement == XML_ELEMENT(FORM, XML_XFORMS_LIST_SOURCE) )
+ {
+ m_sListBindingID = _rValue;
+ return true;
+ }
+
+ if ( nElement == XML_ELEMENT(FORM, XML_XFORMS_SUBMISSION)
+ || nElement == XML_ELEMENT(XFORMS, XML_SUBMISSION) )
+ {
+ m_sSubmissionID = _rValue;
+ return true;
+ }
+
+ if ( OElementImport::tryGenericAttribute( nElement, _rValue ) )
+ return true;
+
+ static const sal_Int32 nValueAttributeName = OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Value);
+ static const sal_Int32 nCurrentValueAttributeName = OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::CurrentValue);
+ static const sal_Int32 nMinValueAttributeName = OAttributeMetaData::getSpecialAttributeToken(SCAFlags::MinValue);
+ static const sal_Int32 nMaxValueAttributeName = OAttributeMetaData::getSpecialAttributeToken(SCAFlags::MaxValue);
+ static const sal_Int32 nRepeatDelayAttributeName = OAttributeMetaData::getSpecialAttributeToken( SCAFlags::RepeatDelay );
+
+ sal_Int32 nHandle = -1;
+ if ( (nElement & TOKEN_MASK) == nValueAttributeName )
+ nHandle = PROPID_VALUE;
+ else if ( (nElement & TOKEN_MASK) == nCurrentValueAttributeName )
+ nHandle = PROPID_CURRENT_VALUE;
+ else if ( (nElement & TOKEN_MASK) == nMinValueAttributeName )
+ nHandle = PROPID_MIN_VALUE;
+ else if ( (nElement & TOKEN_MASK) == nMaxValueAttributeName )
+ nHandle = PROPID_MAX_VALUE;
+ if ( nHandle != -1 )
+ {
+ // for the moment, simply remember the name and the value
+ PropertyValue aProp;
+ aProp.Name = SvXMLImport::getNameFromToken(nElement);
+ aProp.Handle = nHandle;
+ aProp.Value <<= _rValue;
+ m_aValueProperties.push_back(aProp);
+ return true;
+ }
+
+ if ( (nElement & TOKEN_MASK) == nRepeatDelayAttributeName )
+ {
+ util::Duration aDuration;
+ if (::sax::Converter::convertDuration(aDuration, _rValue))
+ {
+ PropertyValue aProp;
+ aProp.Name = PROPERTY_REPEAT_DELAY;
+ sal_Int32 const nMS =
+ ((aDuration.Hours * 60 + aDuration.Minutes) * 60
+ + aDuration.Seconds) * 1000 + aDuration.NanoSeconds/1000000;
+ aProp.Value <<= nMS;
+
+ implPushBackPropertyValue(aProp);
+ }
+ return true;
+ }
+
+ return OElementImport::handleAttribute( nElement, _rValue );
+ }
+
+ void OControlImport::startFastElement(sal_Int32 nElement, const Reference< css::xml::sax::XFastAttributeList >& _rxAttrList)
+ {
+ css::uno::Reference< css::xml::sax::XFastAttributeList > xMergedAttributes;
+ if( m_xOuterAttributes.is() )
+ {
+ // merge the attribute lists, our own one
+ rtl::Reference xMerger(new sax_fastparser::FastAttributeList(_rxAttrList));
+ // and the ones of our enclosing element
+ xMerger->add(m_xOuterAttributes);
+ xMergedAttributes = xMerger.get();
+ }
+ else
+ {
+ xMergedAttributes = _rxAttrList;
+ }
+
+ // let the base class handle all the attributes
+ OElementImport::startFastElement(nElement, xMergedAttributes);
+
+ if ( m_aValueProperties.empty() || !m_xElement.is())
+ return;
+
+ // get the property set info
+ if (!m_xInfo.is())
+ {
+ OSL_FAIL("OControlImport::StartElement: no PropertySetInfo!");
+ return;
+ }
+
+ const char* pValueProperty = nullptr;
+ const char* pCurrentValueProperty = nullptr;
+ const char* pMinValueProperty = nullptr;
+ const char* pMaxValueProperty = nullptr;
+
+ bool bRetrievedValues = false;
+ bool bRetrievedValueLimits = false;
+
+ // get the class id of our element
+ sal_Int16 nClassId = FormComponentType::CONTROL;
+ m_xElement->getPropertyValue(PROPERTY_CLASSID) >>= nClassId;
+
+ // translate the value properties we collected in handleAttributes
+ for ( auto& rValueProps : m_aValueProperties )
+ {
+ bool bSuccess = false;
+ switch (rValueProps.Handle)
+ {
+ case PROPID_VALUE:
+ case PROPID_CURRENT_VALUE:
+ {
+ // get the property names
+ if (!bRetrievedValues)
+ {
+ getValuePropertyNames(m_eElementType, nClassId, pCurrentValueProperty, pValueProperty);
+ if ( !pCurrentValueProperty && !pValueProperty )
+ {
+ SAL_WARN( "xmloff.forms", "OControlImport::StartElement: illegal value property names!" );
+ break;
+ }
+
+ bRetrievedValues = true;
+ }
+ if ( PROPID_VALUE == rValueProps.Handle && !pValueProperty )
+ {
+ SAL_WARN( "xmloff.forms", "OControlImport::StartElement: the control does not have a value property!");
+ break;
+ }
+
+ if ( PROPID_CURRENT_VALUE == rValueProps.Handle && !pCurrentValueProperty )
+ {
+ SAL_WARN( "xmloff.forms", "OControlImport::StartElement: the control does not have a current-value property!");
+ break;
+ }
+
+ // transfer the name
+ if (PROPID_VALUE == rValueProps.Handle)
+ rValueProps.Name = OUString::createFromAscii(pValueProperty);
+ else
+ rValueProps.Name = OUString::createFromAscii(pCurrentValueProperty);
+ bSuccess = true;
+ }
+ break;
+ case PROPID_MIN_VALUE:
+ case PROPID_MAX_VALUE:
+ {
+ // get the property names
+ if (!bRetrievedValueLimits)
+ {
+ getValueLimitPropertyNames(nClassId, pMinValueProperty, pMaxValueProperty);
+ if ( !pMinValueProperty || !pMaxValueProperty )
+ {
+ SAL_WARN( "xmloff.forms", "OControlImport::StartElement: illegal value limit property names!" );
+ break;
+ }
+
+ bRetrievedValueLimits = true;
+ }
+ OSL_ENSURE((PROPID_MIN_VALUE != rValueProps.Handle) || pMinValueProperty,
+ "OControlImport::StartElement: the control does not have a value property!");
+ OSL_ENSURE((PROPID_MAX_VALUE != rValueProps.Handle) || pMaxValueProperty,
+ "OControlImport::StartElement: the control does not have a current-value property!");
+
+ // transfer the name
+ if (PROPID_MIN_VALUE == rValueProps.Handle)
+ rValueProps.Name = OUString::createFromAscii(pMinValueProperty);
+ else
+ rValueProps.Name = OUString::createFromAscii(pMaxValueProperty);
+ bSuccess = true;
+ }
+ break;
+ }
+
+ if ( !bSuccess )
+ continue;
+
+ // translate the value
+ implTranslateValueProperty(m_xInfo, rValueProps);
+ // add the property to the base class' array
+ implPushBackPropertyValue(rValueProps);
+ }
+
+ }
+
+ void OControlImport::implTranslateValueProperty(const Reference< XPropertySetInfo >& _rxPropInfo,
+ PropertyValue& _rPropValue)
+ {
+ OSL_ENSURE(_rxPropInfo->hasPropertyByName(_rPropValue.Name),
+ "OControlImport::implTranslateValueProperty: invalid property name!");
+
+ // retrieve the type of the property
+ Property aProp = _rxPropInfo->getPropertyByName(_rPropValue.Name);
+ // the untranslated string value as read in handleAttribute
+ OUString sValue;
+ bool bSuccess = _rPropValue.Value >>= sValue;
+ OSL_ENSURE(bSuccess, "OControlImport::implTranslateValueProperty: supposed to be called with non-translated string values!");
+
+ if (TypeClass_ANY == aProp.Type.getTypeClass())
+ {
+ // we have exactly 2 properties where this type class is allowed:
+ SAL_WARN_IF(
+ _rPropValue.Name != PROPERTY_EFFECTIVE_VALUE
+ && _rPropValue.Name != PROPERTY_EFFECTIVE_DEFAULT, "xmloff",
+ "OControlImport::implTranslateValueProperty: invalid property type/name combination, Any and " << _rPropValue.Name);
+
+ // Both properties are allowed to have a double or a string value,
+ // so first try to convert the string into a number
+ double nValue;
+ if (::sax::Converter::convertDouble(nValue, sValue))
+ _rPropValue.Value <<= nValue;
+ else
+ _rPropValue.Value <<= sValue;
+ }
+ else
+ _rPropValue.Value = PropertyConversion::convertString(aProp.Type, sValue);
+ }
+
+ void OControlImport::endFastElement(sal_Int32 nElement)
+ {
+ OSL_ENSURE(m_xElement.is(), "OControlImport::EndElement: invalid control!");
+ if ( !m_xElement.is() )
+ return;
+
+ // register our control with its id
+ if (!m_sControlId.isEmpty())
+ m_rFormImport.registerControlId(m_xElement, m_sControlId);
+ // it's allowed to have no control id. In this case we're importing a column
+
+ // one more pre-work to do:
+ // when we set default values, then by definition the respective value is set
+ // to this default value, too. This means if the sequence contains for example
+ // a DefaultText value, then the Text will be affected by this, too.
+ // In case the Text is not part of the property sequence (or occurs _before_
+ // the DefaultText, which can happen for other value/default-value property names),
+ // this means that the Text (the value property) is incorrectly imported.
+
+ bool bRestoreValuePropertyValue = false;
+ Any aValuePropertyValue;
+
+ sal_Int16 nClassId = FormComponentType::CONTROL;
+ try
+ {
+ // get the class id of our element
+ m_xElement->getPropertyValue(PROPERTY_CLASSID) >>= nClassId;
+ }
+ catch( const Exception& )
+ {
+ TOOLS_WARN_EXCEPTION("xmloff.forms",
+ "caught an exception while retrieving the class id!");
+ }
+
+ const char* pValueProperty = nullptr;
+ const char* pDefaultValueProperty = nullptr;
+ getRuntimeValuePropertyNames(m_eElementType, nClassId, pValueProperty, pDefaultValueProperty);
+ if ( pDefaultValueProperty && pValueProperty )
+ {
+ bool bNonDefaultValuePropertyValue = false;
+ // is the "value property" part of the sequence?
+
+ // look up this property in our sequence
+ for ( const auto& rCheck : m_aValues )
+ {
+ if ( rCheck.Name.equalsAscii( pDefaultValueProperty ) )
+ bRestoreValuePropertyValue = true;
+ else if ( rCheck.Name.equalsAscii( pValueProperty ) )
+ {
+ bNonDefaultValuePropertyValue = true;
+ // we need to restore the value property we found here, nothing else
+ aValuePropertyValue = rCheck.Value;
+ }
+ }
+
+ if ( bRestoreValuePropertyValue && !bNonDefaultValuePropertyValue )
+ {
+ // found it -> need to remember (and restore) the "value property value", which is not set explicitly
+ try
+ {
+ aValuePropertyValue = m_xElement->getPropertyValue( OUString::createFromAscii( pValueProperty ) );
+ }
+ catch( const Exception& )
+ {
+ TOOLS_WARN_EXCEPTION(
+ "xmloff.forms",
+ "caught an exception while retrieving the current value property!");
+ }
+ }
+ }
+
+ // let the base class set all the values
+ OElementImport::endFastElement(nElement);
+
+ // restore the "value property value", if necessary
+ if ( bRestoreValuePropertyValue && pValueProperty )
+ {
+ try
+ {
+ m_xElement->setPropertyValue( OUString::createFromAscii( pValueProperty ), aValuePropertyValue );
+ }
+ catch( const Exception& )
+ {
+ TOOLS_WARN_EXCEPTION("xmloff.forms",
+ "caught an exception while restoring the value property!");
+ }
+ }
+
+ // the external cell binding, if applicable
+ if ( m_xElement.is() && !m_sBoundCellAddress.isEmpty() )
+ doRegisterCellValueBinding( m_sBoundCellAddress );
+
+ // XForms binding, if applicable
+ if ( m_xElement.is() && !m_sBindingID.isEmpty() )
+ doRegisterXFormsValueBinding( m_sBindingID );
+
+ // XForms list binding, if applicable
+ if ( m_xElement.is() && !m_sListBindingID.isEmpty() )
+ doRegisterXFormsListBinding( m_sListBindingID );
+
+ // XForms submission, if applicable
+ if ( m_xElement.is() && !m_sSubmissionID.isEmpty() )
+ doRegisterXFormsSubmission( m_sSubmissionID );
+ }
+
+ void OControlImport::doRegisterCellValueBinding( const OUString& _rBoundCellAddress )
+ {
+ OSL_PRECOND( m_xElement.is(), "OControlImport::doRegisterCellValueBinding: invalid element!" );
+ OSL_PRECOND( !_rBoundCellAddress.isEmpty(),
+ "OControlImport::doRegisterCellValueBinding: invalid address!" );
+
+ m_rContext.registerCellValueBinding( m_xElement, _rBoundCellAddress );
+ }
+
+ void OControlImport::doRegisterXFormsValueBinding( const OUString& _rBindingID )
+ {
+ OSL_PRECOND( m_xElement.is(), "need element" );
+ OSL_PRECOND( !_rBindingID.isEmpty(), "binding ID is not valid" );
+
+ m_rContext.registerXFormsValueBinding( m_xElement, _rBindingID );
+ }
+
+ void OControlImport::doRegisterXFormsListBinding( const OUString& _rBindingID )
+ {
+ OSL_PRECOND( m_xElement.is(), "need element" );
+ OSL_PRECOND( !_rBindingID.isEmpty(), "binding ID is not valid" );
+
+ m_rContext.registerXFormsListBinding( m_xElement, _rBindingID );
+ }
+
+ void OControlImport::doRegisterXFormsSubmission( const OUString& _rSubmissionID )
+ {
+ OSL_PRECOND( m_xElement.is(), "need element" );
+ OSL_PRECOND( !_rSubmissionID.isEmpty(), "binding ID is not valid" );
+
+ m_rContext.registerXFormsSubmission( m_xElement, _rSubmissionID );
+ }
+
+ Reference< XPropertySet > OControlImport::createElement()
+ {
+ const Reference xPropSet = OElementImport::createElement();
+ if ( xPropSet.is() )
+ {
+ m_xInfo = xPropSet->getPropertySetInfo();
+ if ( m_xInfo.is() && m_xInfo->hasPropertyByName(PROPERTY_ALIGN) )
+ {
+ Any aValue;
+ xPropSet->setPropertyValue(PROPERTY_ALIGN,aValue);
+ }
+ }
+ return xPropSet;
+ }
+
+ //= OImagePositionImport
+ OImagePositionImport::OImagePositionImport( OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer,
+ OControlElement::ElementType _eType )
+ :OControlImport( _rImport, _rEventManager, _rxParentContainer, _eType )
+ ,m_nImagePosition( -1 )
+ ,m_nImageAlign( 0 )
+ ,m_bHaveImagePosition( false )
+ {
+ }
+
+ bool OImagePositionImport::handleAttribute( sal_Int32 nElement,
+ const OUString& _rValue )
+ {
+ static const sal_Int32 s_nImageDataAttributeName = OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::ImageData);
+
+ if ( (nElement & TOKEN_MASK) == s_nImageDataAttributeName)
+ {
+ m_xGraphic = m_rContext.getGlobalContext().loadGraphicByURL(_rValue);
+ return true;
+ }
+ else if ( (nElement & TOKEN_MASK) == XML_IMAGE_POSITION )
+ {
+ OSL_VERIFY( PropertyConversion::convertString(
+ cppu::UnoType::get(),
+ _rValue, aImagePositionMap
+ ) >>= m_nImagePosition );
+ m_bHaveImagePosition = true;
+ return true;
+ }
+ else if ( (nElement & TOKEN_MASK) == XML_IMAGE_ALIGN )
+ {
+ OSL_VERIFY( PropertyConversion::convertString(
+ cppu::UnoType::get(),
+ _rValue, aImageAlignMap
+ ) >>= m_nImageAlign );
+ return true;
+ }
+
+ return OControlImport::handleAttribute( nElement, _rValue );
+ }
+
+ void OImagePositionImport::startFastElement(sal_Int32 nElement, const Reference< XFastAttributeList >& _rxAttrList)
+ {
+ OControlImport::startFastElement( nElement, _rxAttrList );
+
+ if (m_xGraphic.is())
+ {
+ PropertyValue aGraphicProperty;
+ aGraphicProperty.Name = PROPERTY_GRAPHIC;
+ aGraphicProperty.Value <<= m_xGraphic;
+ implPushBackPropertyValue(aGraphicProperty);
+ }
+ if ( !m_bHaveImagePosition )
+ return;
+
+ sal_Int16 nUnoImagePosition = ImagePosition::Centered;
+ if ( m_nImagePosition >= 0 )
+ {
+ OSL_ENSURE( ( m_nImagePosition <= 3 ) && ( m_nImageAlign >= 0 ) && ( m_nImageAlign < 3 ),
+ "OImagePositionImport::StartElement: unknown image align and/or position!" );
+ nUnoImagePosition = m_nImagePosition * 3 + m_nImageAlign;
+ }
+
+ PropertyValue aImagePosition;
+ aImagePosition.Name = PROPERTY_IMAGE_POSITION;
+ aImagePosition.Value <<= nUnoImagePosition;
+ implPushBackPropertyValue( aImagePosition );
+ }
+
+ //= OReferredControlImport
+ OReferredControlImport::OReferredControlImport(
+ OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer )
+ :OControlImport(_rImport, _rEventManager, _rxParentContainer)
+ {
+ }
+
+ void OReferredControlImport::startFastElement(sal_Int32 nElement, const Reference< XFastAttributeList >& _rxAttrList)
+ {
+ OControlImport::startFastElement(nElement, _rxAttrList);
+
+ // the base class should have created the control, so we can register it
+ if ( !m_sReferringControls.isEmpty() )
+ m_rFormImport.registerControlReferences(m_xElement, m_sReferringControls);
+ }
+
+ bool OReferredControlImport::handleAttribute(sal_Int32 nElement,
+ const OUString& _rValue)
+ {
+ static const sal_Int32 s_nReferenceAttributeName = OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::For);
+ if ((nElement & TOKEN_MASK) == s_nReferenceAttributeName)
+ {
+ m_sReferringControls = _rValue;
+ return true;
+ }
+ return OControlImport::handleAttribute(nElement, _rValue);
+ }
+
+ //= OPasswordImport
+ OPasswordImport::OPasswordImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer, OControlElement::ElementType _eType)
+ :OControlImport(_rImport, _rEventManager, _rxParentContainer, _eType)
+ {
+ }
+
+ bool OPasswordImport::handleAttribute(sal_Int32 nElement, const OUString& _rValue)
+ {
+ static const sal_Int32 s_nEchoCharAttributeName = OAttributeMetaData::getSpecialAttributeToken(SCAFlags::EchoChar);
+ if ((nElement & TOKEN_MASK) == s_nEchoCharAttributeName)
+ {
+ // need a special handling for the EchoChar property
+ PropertyValue aEchoChar;
+ aEchoChar.Name = PROPERTY_ECHOCHAR;
+ OSL_ENSURE(_rValue.getLength() == 1, "OPasswordImport::handleAttribute: invalid echo char attribute!");
+ // we ourself should not have written values other than of length 1
+ if (_rValue.getLength() >= 1)
+ aEchoChar.Value <<= static_cast(_rValue[0]);
+ else
+ aEchoChar.Value <<= sal_Int16(0);
+ implPushBackPropertyValue(aEchoChar);
+ return true;
+ }
+ return OControlImport::handleAttribute(nElement, _rValue);
+ }
+
+ //= ORadioImport
+ ORadioImport::ORadioImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer, OControlElement::ElementType _eType)
+ :OImagePositionImport( _rImport, _rEventManager, _rxParentContainer, _eType )
+ {
+ }
+
+ bool ORadioImport::handleAttribute(sal_Int32 nElement, const OUString& _rValue)
+ {
+ // need special handling for the State & CurrentState properties:
+ // they're stored as booleans, but expected to be int16 properties
+ static const sal_Int32 nCurrentSelectedAttributeName = OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::CurrentSelected);
+ static const sal_Int32 nSelectedAttributeName = OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Selected);
+ if ( (nElement & TOKEN_MASK) == nCurrentSelectedAttributeName
+ || (nElement & TOKEN_MASK) == nSelectedAttributeName
+ )
+ {
+ const OAttribute2Property::AttributeAssignment* pProperty = m_rContext.getAttributeMap().getAttributeTranslation(nElement & TOKEN_MASK);
+ assert(pProperty && "ORadioImport::handleAttribute: invalid property map!");
+ if (pProperty)
+ {
+ const Any aBooleanValue( PropertyConversion::convertString(pProperty->aPropertyType, _rValue, pProperty->pEnumMap) );
+
+ // create and store a new PropertyValue
+ PropertyValue aNewValue;
+ aNewValue.Name = pProperty->sPropertyName;
+ aNewValue.Value <<= static_cast(::cppu::any2bool(aBooleanValue));
+
+ implPushBackPropertyValue(aNewValue);
+ }
+ return true;
+ }
+ return OImagePositionImport::handleAttribute( nElement, _rValue );
+ }
+
+ //= OURLReferenceImport
+ OURLReferenceImport::OURLReferenceImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer,
+ OControlElement::ElementType _eType)
+ :OImagePositionImport(_rImport, _rEventManager, _rxParentContainer, _eType)
+ {
+ }
+
+ bool OURLReferenceImport::handleAttribute(sal_Int32 nElement, const OUString& _rValue)
+ {
+ static const sal_Int32 s_nTargetLocationAttributeName = OAttributeMetaData::getCommonControlAttributeToken( CCAFlags::TargetLocation );
+ static const sal_Int32 s_nImageDataAttributeName = OAttributeMetaData::getCommonControlAttributeToken( CCAFlags::ImageData );
+
+ // need to make the URL absolute if
+ // * it's the image-data attribute
+ // * it's the target-location attribute, and we're dealing with an object which has the respective property
+ bool bMakeAbsolute =
+ (nElement & TOKEN_MASK) == s_nImageDataAttributeName
+ || ( (nElement & TOKEN_MASK) == s_nTargetLocationAttributeName
+ && ( ( OControlElement::BUTTON == m_eElementType )
+ || ( OControlElement::IMAGE == m_eElementType )
+ )
+ );
+
+ if (bMakeAbsolute && !_rValue.isEmpty())
+ {
+ OUString sAdjustedValue = _rValue;
+ if ((nElement & TOKEN_MASK) != s_nImageDataAttributeName)
+ sAdjustedValue = m_rContext.getGlobalContext().GetAbsoluteReference( _rValue );
+ return OImagePositionImport::handleAttribute( nElement, sAdjustedValue );
+ }
+
+ return OImagePositionImport::handleAttribute( nElement, _rValue );
+ }
+
+ //= OButtonImport
+ OButtonImport::OButtonImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer,
+ OControlElement::ElementType _eType)
+ :OURLReferenceImport(_rImport, _rEventManager, _rxParentContainer, _eType)
+ {
+ enableTrackAttributes();
+ }
+
+ void OButtonImport::startFastElement(sal_Int32 nElement, const Reference< XFastAttributeList >& _rxAttrList)
+ {
+ OURLReferenceImport::startFastElement(nElement, _rxAttrList);
+
+ // handle the target-frame attribute
+ simulateDefaultedAttribute(OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::TargetFrame), PROPERTY_TARGETFRAME, "_blank");
+ }
+
+ //= OValueRangeImport
+ OValueRangeImport::OValueRangeImport( OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer, OControlElement::ElementType _eType )
+ :OControlImport( _rImport, _rEventManager, _rxParentContainer, _eType )
+ ,m_nStepSizeValue( 1 )
+ {
+
+ }
+
+ bool OValueRangeImport::handleAttribute( sal_Int32 nElement, const OUString& _rValue )
+ {
+ if ( (nElement & TOKEN_MASK) == OAttributeMetaData::getSpecialAttributeToken( SCAFlags::StepSize ) )
+ {
+ ::sax::Converter::convertNumber( m_nStepSizeValue, _rValue );
+ return true;
+ }
+ return OControlImport::handleAttribute( nElement, _rValue );
+ }
+
+ void OValueRangeImport::startFastElement( sal_Int32 nElement, const Reference< XFastAttributeList >& _rxAttrList )
+ {
+ OControlImport::startFastElement( nElement, _rxAttrList );
+
+ if ( m_xInfo.is() )
+ {
+ if ( m_xInfo->hasPropertyByName( PROPERTY_SPIN_INCREMENT ) )
+ m_xElement->setPropertyValue( PROPERTY_SPIN_INCREMENT, Any( m_nStepSizeValue ) );
+ else if ( m_xInfo->hasPropertyByName( PROPERTY_LINE_INCREMENT ) )
+ m_xElement->setPropertyValue( PROPERTY_LINE_INCREMENT, Any( m_nStepSizeValue ) );
+ }
+ }
+
+ //= OTextLikeImport
+ OTextLikeImport::OTextLikeImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer,
+ OControlElement::ElementType _eType)
+ :OControlImport(_rImport, _rEventManager, _rxParentContainer, _eType)
+ ,m_bEncounteredTextPara( false )
+ {
+ enableTrackAttributes();
+ }
+
+ css::uno::Reference< css::xml::sax::XFastContextHandler > OTextLikeImport::createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
+ {
+ if ( nElement == XML_ELEMENT(TEXT, XML_P) )
+ {
+ OSL_ENSURE( m_eElementType == OControlElement::TEXT_AREA,
+ "OTextLikeImport::CreateChildContext: text paragraphs in a non-text-area?" );
+
+ if ( m_eElementType == OControlElement::TEXT_AREA )
+ {
+ Reference< XText > xTextElement( m_xElement, UNO_QUERY );
+ if ( xTextElement.is() )
+ {
+ rtl::Reference < XMLTextImportHelper > xTextImportHelper( m_rContext.getGlobalContext().GetTextImport() );
+
+ if ( !m_xCursor.is() )
+ {
+ m_xOldCursor = xTextImportHelper->GetCursor();
+ m_xCursor = xTextElement->createTextCursor();
+
+ if ( m_xCursor.is() )
+ xTextImportHelper->SetCursor( m_xCursor );
+ }
+ if ( m_xCursor.is() )
+ {
+ m_bEncounteredTextPara = true;
+ return xTextImportHelper->CreateTextChildContext( m_rContext.getGlobalContext(), nElement, xAttrList );
+ }
+ }
+ else
+ {
+ // in theory, we could accumulate all the text portions (without formatting),
+ // and set it as Text property at the model ...
+ }
+ }
+ }
+
+ return OControlImport::createFastChildContext( nElement, xAttrList );
+ }
+
+ void OTextLikeImport::startFastElement(sal_Int32 nElement, const Reference< css::xml::sax::XFastAttributeList >& _rxAttrList)
+ {
+ OControlImport::startFastElement(nElement, _rxAttrList);
+
+ // handle the convert-empty-to-null attribute, whose default is different from the property default
+ // unfortunately, different classes are imported by this class ('cause they're represented by the
+ // same XML element), though not all of them know this property.
+ // So we have to do a check ...
+ if (m_xElement.is() && m_xInfo.is() && m_xInfo->hasPropertyByName(PROPERTY_EMPTY_IS_NULL) )
+ simulateDefaultedAttribute(OAttributeMetaData::getDatabaseAttributeToken(DAFlags::ConvertEmpty), PROPERTY_EMPTY_IS_NULL, "false");
+ }
+
+ namespace {
+
+ struct EqualHandle
+ {
+ const sal_Int32 m_nHandle;
+ explicit EqualHandle( sal_Int32 _nHandle ) : m_nHandle( _nHandle ) { }
+
+ bool operator()( const PropertyValue& _rProp )
+ {
+ return _rProp.Handle == m_nHandle;
+ }
+ };
+
+ }
+
+ void OTextLikeImport::removeRedundantCurrentValue()
+ {
+ if ( !m_bEncounteredTextPara )
+ return;
+
+ // In case the text is written in the text:p elements, we need to ignore what we read as
+ // current-value attribute, since it's redundant.
+ // fortunately, OElementImport tagged the value property with the PROPID_CURRENT_VALUE
+ // handle, so we do not need to determine the name of our value property here
+ // (normally, it should be "Text", since no other controls than the edit field should
+ // have the text:p elements)
+ PropertyValueArray::iterator aValuePropertyPos = ::std::find_if(
+ m_aValues.begin(),
+ m_aValues.end(),
+ EqualHandle( PROPID_CURRENT_VALUE )
+ );
+ if ( aValuePropertyPos != m_aValues.end() )
+ {
+ OSL_ENSURE( aValuePropertyPos->Name == PROPERTY_TEXT, "OTextLikeImport::EndElement: text:p was present, but our value property is *not* 'Text'!" );
+ if ( aValuePropertyPos->Name == PROPERTY_TEXT )
+ {
+ m_aValues.erase(aValuePropertyPos);
+ }
+ }
+
+ // additionally, we need to set the "RichText" property of our element to sal_True
+ // (the presence of the text:p is used as indicator for the value of the RichText property)
+ bool bHasRichTextProperty = false;
+ if ( m_xInfo.is() )
+ bHasRichTextProperty = m_xInfo->hasPropertyByName( PROPERTY_RICH_TEXT );
+ OSL_ENSURE( bHasRichTextProperty, "OTextLikeImport::EndElement: text:p, but no rich text control?" );
+ if ( bHasRichTextProperty )
+ m_xElement->setPropertyValue( PROPERTY_RICH_TEXT, Any( true ) );
+ // Note that we do *not* set the RichText property (in case our element has one) to sal_False here
+ // since this is the default of this property, anyway.
+ }
+
+ namespace {
+
+ struct EqualName
+ {
+ const OUString & m_sName;
+ explicit EqualName( const OUString& _rName ) : m_sName( _rName ) { }
+
+ bool operator()( const PropertyValue& _rProp )
+ {
+ return _rProp.Name == m_sName;
+ }
+ };
+
+ }
+
+ void OTextLikeImport::adjustDefaultControlProperty()
+ {
+ // In OpenOffice.org 2.0, we changed the implementation of the css.form.component.TextField (the model of a text field control),
+ // so that it now uses another default control. So if we encounter a text field where the *old* default
+ // control property is writing, we are not allowed to use it
+ PropertyValueArray::iterator aDefaultControlPropertyPos = ::std::find_if(
+ m_aValues.begin(),
+ m_aValues.end(),
+ EqualName( "DefaultControl" )
+ );
+ if ( aDefaultControlPropertyPos != m_aValues.end() )
+ {
+ OUString sDefaultControl;
+ OSL_VERIFY( aDefaultControlPropertyPos->Value >>= sDefaultControl );
+ if ( sDefaultControl == "stardiv.one.form.control.Edit" )
+ {
+ // complete remove this property value from the array. Today's "default value" of the "DefaultControl"
+ // property is sufficient
+ m_aValues.erase(aDefaultControlPropertyPos);
+ }
+ }
+ }
+
+ void OTextLikeImport::endFastElement(sal_Int32 nElement)
+ {
+ removeRedundantCurrentValue();
+ adjustDefaultControlProperty();
+
+ // let the base class do the stuff
+ OControlImport::endFastElement(nElement);
+
+ // some cleanups
+ rtl::Reference < XMLTextImportHelper > xTextImportHelper( m_rContext.getGlobalContext().GetTextImport() );
+ if ( m_xCursor.is() )
+ {
+ // delete the newline which has been imported erroneously
+ // TODO (fs): stole this code somewhere - why don't we fix the text import??
+ m_xCursor->gotoEnd( false );
+ m_xCursor->goLeft( 1, true );
+ m_xCursor->setString( OUString() );
+
+ // reset cursor
+ xTextImportHelper->ResetCursor();
+ }
+
+ if ( m_xOldCursor.is() )
+ xTextImportHelper->SetCursor( m_xOldCursor );
+
+ }
+
+ //= OListAndComboImport
+ OListAndComboImport::OListAndComboImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer,
+ OControlElement::ElementType _eType)
+ :OControlImport(_rImport, _rEventManager, _rxParentContainer, _eType)
+ ,m_nEmptyListItems( 0 )
+ ,m_nEmptyValueItems( 0 )
+ ,m_bEncounteredLSAttrib( false )
+ ,m_bLinkWithIndexes( false )
+ {
+ if (OControlElement::COMBOBOX == m_eElementType)
+ enableTrackAttributes();
+ }
+
+ css::uno::Reference< css::xml::sax::XFastContextHandler > OListAndComboImport::createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& _rxAttrList )
+ {
+ // is it the "option" sub tag of a listbox ?
+ if ((nElement & TOKEN_MASK) == XML_OPTION)
+ return new OListOptionImport(GetImport(), this);
+
+ // is it the "item" sub tag of a combobox ?
+ if ((nElement & TOKEN_MASK) == XML_ITEM)
+ return new OComboItemImport(GetImport(), this);
+
+ // everything else
+ return OControlImport::createFastChildContext(nElement, _rxAttrList);
+ }
+
+ void OListAndComboImport::startFastElement(sal_Int32 nElement, const Reference< XFastAttributeList >& _rxAttrList)
+ {
+ m_bLinkWithIndexes = false;
+
+ OControlImport::startFastElement(nElement, _rxAttrList);
+
+ if (OControlElement::COMBOBOX == m_eElementType)
+ {
+ // for the auto-completion
+ // the attribute default does not equal the property default, so in case we did not read this attribute,
+ // we have to simulate it
+ simulateDefaultedAttribute( OAttributeMetaData::getSpecialAttributeToken( SCAFlags::AutoCompletion ), PROPERTY_AUTOCOMPLETE, "false");
+
+ // same for the convert-empty-to-null attribute, which's default is different from the property default
+ simulateDefaultedAttribute( OAttributeMetaData::getDatabaseAttributeToken( DAFlags::ConvertEmpty ), PROPERTY_EMPTY_IS_NULL, "false");
+ }
+ }
+
+ void OListAndComboImport::endFastElement(sal_Int32 nElement)
+ {
+ // append the list source property the properties sequence of our importer
+ // the string item list
+ PropertyValue aItemList;
+ aItemList.Name = PROPERTY_STRING_ITEM_LIST;
+ aItemList.Value <<= comphelper::containerToSequence(m_aListSource);
+ implPushBackPropertyValue(aItemList);
+
+ if (OControlElement::LISTBOX == m_eElementType)
+ {
+ OSL_ENSURE((m_aListSource.size() + m_nEmptyListItems) == (m_aValueList.size() + m_nEmptyValueItems),
+ "OListAndComboImport::EndElement: inconsistence between labels and values!");
+
+ if ( !m_bEncounteredLSAttrib )
+ {
+ // the value sequence
+ PropertyValue aValueList;
+ aValueList.Name = PROPERTY_LISTSOURCE;
+ aValueList.Value <<= comphelper::containerToSequence(m_aValueList);
+ implPushBackPropertyValue(aValueList);
+ }
+
+ // the select sequence
+ PropertyValue aSelected;
+ aSelected.Name = PROPERTY_SELECT_SEQ;
+ aSelected.Value <<= comphelper::containerToSequence(m_aSelectedSeq);
+ implPushBackPropertyValue(aSelected);
+
+ // the default select sequence
+ PropertyValue aDefaultSelected;
+ aDefaultSelected.Name = PROPERTY_DEFAULT_SELECT_SEQ;
+ aDefaultSelected.Value <<= comphelper::containerToSequence(m_aDefaultSelectedSeq);
+ implPushBackPropertyValue(aDefaultSelected);
+ }
+
+ OControlImport::endFastElement(nElement);
+
+ // the external list source, if applicable
+ if ( m_xElement.is() && !m_sCellListSource.isEmpty() )
+ m_rContext.registerCellRangeListSource( m_xElement, m_sCellListSource );
+ }
+
+ void OListAndComboImport::doRegisterCellValueBinding( const OUString& _rBoundCellAddress )
+ {
+ OUString sBoundCellAddress( _rBoundCellAddress );
+ if ( m_bLinkWithIndexes )
+ {
+ // This is a HACK. We register a string which is no valid address, but allows
+ // (somewhere else) to determine that a non-standard binding should be created.
+ // This hack is acceptable for OOo 1.1.1, since the file format for value
+ // bindings of form controls is to be changed afterwards, anyway.
+ sBoundCellAddress += ":index";
+ }
+
+ OControlImport::doRegisterCellValueBinding( sBoundCellAddress );
+ }
+
+ bool OListAndComboImport::handleAttribute(sal_Int32 nElement, const OUString& _rValue)
+ {
+ static const sal_Int32 nListSourceAttributeName = OAttributeMetaData::getDatabaseAttributeToken(DAFlags::ListSource);
+ if ( (nElement & TOKEN_MASK) == nListSourceAttributeName )
+ {
+ PropertyValue aListSource;
+ aListSource.Name = PROPERTY_LISTSOURCE;
+
+ // it's the ListSource attribute
+ m_bEncounteredLSAttrib = true;
+ if ( OControlElement::COMBOBOX == m_eElementType )
+ {
+ aListSource.Value <<= _rValue;
+ }
+ else
+ {
+ // a listbox which has a list-source attribute must have a list-source-type of something
+ // not equal to ValueList.
+ // In this case, the list-source value is simply the one and only element of the ListSource property.
+ Sequence aListSourcePropValue { _rValue };
+ aListSource.Value <<= aListSourcePropValue;
+ }
+
+ implPushBackPropertyValue( aListSource );
+ return true;
+ }
+
+ if ( (nElement & TOKEN_MASK) == OAttributeMetaData::getBindingAttributeToken( BAFlags::ListCellRange ) )
+ {
+ m_sCellListSource = _rValue;
+ return true;
+ }
+
+ if ( (nElement & TOKEN_MASK) == OAttributeMetaData::getBindingAttributeToken( BAFlags::ListLinkingType ) )
+ {
+ sal_Int16 nLinkageType = 0;
+ PropertyConversion::convertString(
+ ::cppu::UnoType::get(),
+ _rValue,
+ aListLinkageMap
+ ) >>= nLinkageType;
+
+ m_bLinkWithIndexes = ( nLinkageType != 0 );
+ return true;
+ }
+
+ return OControlImport::handleAttribute(nElement, _rValue);
+ }
+
+ void OListAndComboImport::implPushBackLabel(const OUString& _rLabel)
+ {
+ OSL_ENSURE(!m_nEmptyListItems, "OListAndComboImport::implPushBackValue: label list is already done!");
+ if (!m_nEmptyListItems)
+ m_aListSource.push_back(_rLabel);
+ }
+
+ void OListAndComboImport::implPushBackValue(const OUString& _rValue)
+ {
+ OSL_ENSURE(!m_nEmptyValueItems, "OListAndComboImport::implPushBackValue: value list is already done!");
+ if (!m_nEmptyValueItems)
+ {
+ OSL_ENSURE( !m_bEncounteredLSAttrib, "OListAndComboImport::implPushBackValue: invalid structure! Did you save this document with a version prior SRC641 m?" );
+ // We already had the list-source attribute, which means that the ListSourceType is
+ // not ValueList, which means that the ListSource should contain only one string in
+ // the first element of the sequence
+ // All other values in the file are invalid
+
+ m_aValueList.push_back( _rValue );
+ }
+ }
+
+ void OListAndComboImport::implEmptyLabelFound()
+ {
+ ++m_nEmptyListItems;
+ }
+
+ void OListAndComboImport::implEmptyValueFound()
+ {
+ ++m_nEmptyValueItems;
+ }
+
+ void OListAndComboImport::implSelectCurrentItem()
+ {
+ OSL_ENSURE((m_aListSource.size() + m_nEmptyListItems) == (m_aValueList.size() + m_nEmptyValueItems),
+ "OListAndComboImport::implSelectCurrentItem: inconsistence between labels and values!");
+
+ sal_Int16 nItemNumber = static_cast(m_aListSource.size() - 1 + m_nEmptyListItems);
+ m_aSelectedSeq.push_back(nItemNumber);
+ }
+
+ void OListAndComboImport::implDefaultSelectCurrentItem()
+ {
+ OSL_ENSURE((m_aListSource.size() + m_nEmptyListItems) == (m_aValueList.size() + m_nEmptyValueItems),
+ "OListAndComboImport::implDefaultSelectCurrentItem: inconsistence between labels and values!");
+
+ sal_Int16 nItemNumber = static_cast(m_aListSource.size() - 1 + m_nEmptyListItems);
+ m_aDefaultSelectedSeq.push_back(nItemNumber);
+ }
+
+ //= OListOptionImport
+ OListOptionImport::OListOptionImport(SvXMLImport& _rImport,
+ const OListAndComboImportRef& _rListBox)
+ :SvXMLImportContext(_rImport)
+ ,m_xListBoxImport(_rListBox)
+ {
+ }
+
+ void OListOptionImport::startFastElement(sal_Int32 nElement, const Reference< XFastAttributeList >& _rxAttrList)
+ {
+ // the label and the value
+ const sal_Int32 nLabelAttribute = (nElement & ~TOKEN_MASK) | XML_LABEL;
+ const sal_Int32 nValueAttribute = (nElement & ~TOKEN_MASK) | XML_VALUE;
+
+ // the label attribute
+ OUString sValue = _rxAttrList->getOptionalValue(nLabelAttribute);
+ bool bNonexistentAttribute = !_rxAttrList->hasAttribute(nLabelAttribute);
+
+ if (bNonexistentAttribute)
+ m_xListBoxImport->implEmptyLabelFound();
+ else
+ m_xListBoxImport->implPushBackLabel( sValue );
+
+ // the value attribute
+ sValue = _rxAttrList->getOptionalValue(nValueAttribute);
+ bNonexistentAttribute = !_rxAttrList->hasAttribute(nValueAttribute);
+
+ if (bNonexistentAttribute)
+ m_xListBoxImport->implEmptyValueFound();
+ else
+ m_xListBoxImport->implPushBackValue( sValue );
+
+ // the current-selected and selected
+ const sal_Int32 nSelectedAttribute = (nElement & ~TOKEN_MASK) | OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::CurrentSelected);
+ const sal_Int32 nDefaultSelectedAttribute = (nElement & ~TOKEN_MASK) | OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Selected);
+
+ // propagate the selected flag
+ bool bSelected(false);
+ (void)::sax::Converter::convertBool(bSelected,
+ _rxAttrList->getOptionalValue(nSelectedAttribute));
+ if (bSelected)
+ m_xListBoxImport->implSelectCurrentItem();
+
+ // same for the default selected
+ bool bDefaultSelected(false);
+ (void)::sax::Converter::convertBool(bDefaultSelected,
+ _rxAttrList->getOptionalValue(nDefaultSelectedAttribute));
+ if (bDefaultSelected)
+ m_xListBoxImport->implDefaultSelectCurrentItem();
+ }
+
+ //= OComboItemImport
+ OComboItemImport::OComboItemImport(SvXMLImport& _rImport,
+ const OListAndComboImportRef& _rListBox)
+ :SvXMLImportContext(_rImport)
+ ,m_xListBoxImport(_rListBox)
+ {
+ }
+
+ void OComboItemImport::startFastElement(sal_Int32 nElement, const Reference< XFastAttributeList >& _rxAttrList)
+ {
+ const sal_Int32 nLabelAttributeName = (nElement & ~TOKEN_MASK) |
+ OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Label);
+ m_xListBoxImport->implPushBackLabel(_rxAttrList->getOptionalValue(nLabelAttributeName));
+ }
+
+ //= OColumnWrapperImport
+ OColumnWrapperImport::OColumnWrapperImport(OFormLayerXMLImport_Impl& _rImport,
+ IEventAttacherManager& _rEventManager, sal_Int32 /*nElement*/,
+ const Reference< XNameContainer >& _rxParentContainer)
+ :SvXMLImportContext(_rImport.getGlobalContext())
+ ,m_xParentContainer(_rxParentContainer)
+ ,m_rFormImport(_rImport)
+ ,m_rEventManager(_rEventManager)
+ {
+ }
+ css::uno::Reference< css::xml::sax::XFastContextHandler > OColumnWrapperImport::createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
+ {
+ OControlImport* pReturn = implCreateChildContext(nElement, OElementNameMap::getElementType(nElement & TOKEN_MASK));
+ if (pReturn)
+ {
+ OSL_ENSURE(m_xOwnAttributes.is(), "OColumnWrapperImport::CreateChildContext: had no form:column element!");
+ pReturn->addOuterAttributes(m_xOwnAttributes);
+ }
+ return pReturn;
+ }
+ void OColumnWrapperImport::startFastElement(sal_Int32 /*nElement*/, const Reference< XFastAttributeList >& _rxAttrList)
+ {
+ OSL_ENSURE(!m_xOwnAttributes.is(), "OColumnWrapperImport::StartElement: already have the cloned list!");
+
+ // clone the attributes
+ Reference< XCloneable > xCloneList(_rxAttrList, UNO_QUERY_THROW);
+ m_xOwnAttributes.set(xCloneList->createClone(), UNO_QUERY_THROW);
+ }
+
+ OControlImport* OColumnWrapperImport::implCreateChildContext(
+ sal_Int32 /*nElement*/,
+ OControlElement::ElementType _eType)
+ {
+ OSL_ENSURE( (OControlElement::TEXT == _eType)
+ || (OControlElement::TEXT_AREA == _eType)
+ || (OControlElement::FORMATTED_TEXT == _eType)
+ || (OControlElement::CHECKBOX == _eType)
+ || (OControlElement::LISTBOX == _eType)
+ || (OControlElement::COMBOBOX == _eType)
+ || (OControlElement::TIME == _eType)
+ || (OControlElement::DATE == _eType),
+ "OColumnWrapperImport::implCreateChildContext: invalid or unrecognized sub element!");
+
+ switch (_eType)
+ {
+ case OControlElement::COMBOBOX:
+ case OControlElement::LISTBOX:
+ return new OColumnImport(m_rFormImport, m_rEventManager, m_xParentContainer, _eType );
+
+ case OControlElement::PASSWORD:
+ return new OColumnImport(m_rFormImport, m_rEventManager, m_xParentContainer, _eType );
+
+ case OControlElement::TEXT:
+ case OControlElement::TEXT_AREA:
+ case OControlElement::FORMATTED_TEXT:
+ return new OColumnImport< OTextLikeImport >( m_rFormImport, m_rEventManager, m_xParentContainer, _eType );
+
+ default:
+ return new OColumnImport(m_rFormImport, m_rEventManager, m_xParentContainer, _eType );
+ }
+ }
+
+ //= OGridImport
+ OGridImport::OGridImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer,
+ OControlElement::ElementType _eType)
+ :OControlImport(_rImport, _rEventManager, _rxParentContainer)
+ {
+ setElementType(_eType);
+ }
+
+ css::uno::Reference< css::xml::sax::XFastContextHandler > OGridImport::createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
+ {
+ // maybe it's a sub control
+ if ((nElement & TOKEN_MASK) == XML_COLUMN)
+ {
+ if (m_xMeAsContainer.is())
+ return new OColumnWrapperImport(m_rFormImport, *this, nElement, m_xMeAsContainer);
+ else
+ {
+ OSL_FAIL("OGridImport::CreateChildContext: don't have an element!");
+ return nullptr;
+ }
+ }
+
+ return OControlImport::createFastChildContext(nElement, xAttrList);
+ }
+
+ void OGridImport::endFastElement(sal_Int32 nElement)
+ {
+ OControlImport::endFastElement(nElement);
+
+ // now that we have all children, attach the events
+ css::uno::Reference< css::container::XIndexAccess > xIndexContainer(m_xMeAsContainer, css::uno::UNO_QUERY);
+ if (xIndexContainer.is())
+ ODefaultEventAttacherManager::setEvents(xIndexContainer);
+ }
+
+ css::uno::Reference< css::beans::XPropertySet > OGridImport::createElement()
+ {
+ // let the base class create the object
+ css::uno::Reference< css::beans::XPropertySet > xReturn = OControlImport::createElement();
+ if (!xReturn.is())
+ return xReturn;
+
+ // ensure that the object is a XNameContainer (we strongly need this for inserting child elements)
+ m_xMeAsContainer.set(xReturn, css::uno::UNO_QUERY);
+ if (!m_xMeAsContainer.is())
+ {
+ OSL_FAIL("OContainerImport::createElement: invalid element (no XNameContainer) created!");
+ xReturn.clear();
+ }
+
+ return xReturn;
+ }
+
+ //= OFormImport
+ OFormImport::OFormImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const Reference< XNameContainer >& _rxParentContainer)
+ :OElementImport(_rImport, _rEventManager, _rxParentContainer)
+ {
+ enableTrackAttributes();
+ }
+
+ css::uno::Reference< css::xml::sax::XFastContextHandler > OFormImport::createFastChildContext(
+ sal_Int32 nElement,
+ const uno::Reference< xml::sax::XFastAttributeList>& _rxAttrList )
+ {
+ auto nToken = (nElement & TOKEN_MASK);
+ if( nToken == XML_FORM )
+ return new OFormImport( m_rFormImport, *this, m_xMeAsContainer);
+ else if ( nToken == XML_CONNECTION_RESOURCE )
+ return new OXMLDataSourceImport(GetImport(), _rxAttrList, m_xElement);
+ else if( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) ||
+ nToken == XML_PROPERTIES )
+ return OElementImport::createFastChildContext( nElement, _rxAttrList );
+ else
+ {
+ OControlElement::ElementType eType = OElementNameMap::getElementType(nToken);
+ switch (eType)
+ {
+ case OControlElement::TEXT:
+ case OControlElement::TEXT_AREA:
+ case OControlElement::FORMATTED_TEXT:
+ return new OTextLikeImport(m_rFormImport, *this, m_xMeAsContainer, eType);
+ case OControlElement::GRID:
+ return new OGridImport(m_rFormImport, *this, m_xMeAsContainer, eType);
+ case OControlElement::COMBOBOX:
+ case OControlElement::LISTBOX:
+ return new OListAndComboImport(m_rFormImport, *this, m_xMeAsContainer, eType);
+ case OControlElement::PASSWORD:
+ return new OPasswordImport(m_rFormImport, *this, m_xMeAsContainer, eType);
+ case OControlElement::BUTTON:
+ case OControlElement::IMAGE:
+ case OControlElement::IMAGE_FRAME:
+ return new OButtonImport( m_rFormImport, *this, m_xMeAsContainer, eType );
+ case OControlElement::RADIO:
+ return new ORadioImport(m_rFormImport, *this, m_xMeAsContainer, eType);
+ case OControlElement::CHECKBOX:
+ return new OImagePositionImport(m_rFormImport, *this, m_xMeAsContainer, eType);
+ case OControlElement::FRAME:
+ case OControlElement::FIXED_TEXT:
+ return new OReferredControlImport(m_rFormImport, *this, m_xMeAsContainer);
+ case OControlElement::VALUERANGE:
+ return new OValueRangeImport( m_rFormImport, *this, m_xMeAsContainer, eType );
+ default:
+ return new OControlImport(m_rFormImport, *this, m_xMeAsContainer, eType);
+ }
+ }
+ }
+
+ void OFormImport::startFastElement(sal_Int32 nElement, const Reference< XFastAttributeList >& _rxAttrList)
+ {
+ m_rFormImport.enterEventContext();
+ OElementImport::startFastElement(nElement, _rxAttrList);
+
+ // handle the target-frame attribute
+ simulateDefaultedAttribute(OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::TargetFrame), PROPERTY_TARGETFRAME, "_blank");
+ }
+
+ void OFormImport::endFastElement(sal_Int32 nElement)
+ {
+ OElementImport::endFastElement(nElement);
+
+ // now that we have all children, attach the events
+ css::uno::Reference< css::container::XIndexAccess > xIndexContainer(m_xMeAsContainer, css::uno::UNO_QUERY);
+ if (xIndexContainer.is())
+ ODefaultEventAttacherManager::setEvents(xIndexContainer);
+
+ m_rFormImport.leaveEventContext();
+ }
+
+ css::uno::Reference< css::beans::XPropertySet > OFormImport::createElement()
+ {
+ // let the base class create the object
+ css::uno::Reference< css::beans::XPropertySet > xReturn = OElementImport::createElement();
+ if (!xReturn.is())
+ return xReturn;
+
+ // ensure that the object is a XNameContainer (we strongly need this for inserting child elements)
+ m_xMeAsContainer.set(xReturn, css::uno::UNO_QUERY);
+ if (!m_xMeAsContainer.is())
+ {
+ OSL_FAIL("OContainerImport::createElement: invalid element (no XNameContainer) created!");
+ xReturn.clear();
+ }
+
+ return xReturn;
+ }
+
+ bool OFormImport::handleAttribute(sal_Int32 nElement, const OUString& _rValue)
+ {
+ // handle the master/details field attributes (they're way too special to let the OPropertyImport handle them)
+ static const sal_Int32 s_nMasterFieldsAttributeName = OAttributeMetaData::getFormAttributeToken(faMasterFields);
+ static const sal_Int32 s_nDetailFieldsAttributeName = OAttributeMetaData::getFormAttributeToken(faDetailFields);
+
+ if ( (nElement & TOKEN_MASK) == s_nMasterFieldsAttributeName)
+ {
+ implTranslateStringListProperty(PROPERTY_MASTERFIELDS, _rValue);
+ return true;
+ }
+
+ if ( (nElement & TOKEN_MASK) == s_nDetailFieldsAttributeName)
+ {
+ implTranslateStringListProperty(PROPERTY_DETAILFIELDS, _rValue);
+ return true;
+ }
+
+ return OElementImport::handleAttribute(nElement, _rValue);
+ }
+
+ void OFormImport::implTranslateStringListProperty(const OUString& _rPropertyName, const OUString& _rValue)
+ {
+ PropertyValue aProp;
+ aProp.Name = _rPropertyName;
+
+ Sequence< OUString > aList;
+
+ // split up the value string
+ if (!_rValue.isEmpty())
+ {
+ // For the moment, we build a vector instead of a Sequence. It's easier to handle because of its
+ // push_back method
+ ::std::vector< OUString > aElements;
+ // estimate the number of tokens
+ sal_Int32 nEstimate = 0, nLength = _rValue.getLength();
+ const sal_Unicode* pChars = _rValue.getStr();
+ for (sal_Int32 i=0; i(aElements.data(), aElements.size());
+ }
+ else
+ {
+ OSL_FAIL("OFormImport::implTranslateStringListProperty: invalid value (empty)!");
+ }
+
+ aProp.Value <<= aList;
+
+ // add the property to the base class' array
+ implPushBackPropertyValue(aProp);
+ }
+ //= OXMLDataSourceImport
+ OXMLDataSourceImport::OXMLDataSourceImport(
+ SvXMLImport& _rImport
+ ,const Reference< css::xml::sax::XFastAttributeList > & _xAttrList
+ ,const css::uno::Reference< css::beans::XPropertySet >& _xElement) :
+ SvXMLImportContext( _rImport)
+ {
+ for( auto& aIter : sax_fastparser::castToFastAttributeList(_xAttrList) )
+ {
+ if ( aIter.getToken() ==
+ XML_ELEMENT(XLINK, OAttributeMetaData::getCommonControlAttributeToken( CCAFlags::TargetLocation ) ) )
+ {
+ OUString sValue = aIter.toString();
+ sValue = _rImport.GetAbsoluteReference(sValue);
+ INetURLObject aURL(sValue);
+ if ( aURL.GetProtocol() == INetProtocol::File )
+ _xElement->setPropertyValue(PROPERTY_DATASOURCENAME,Any(sValue));
+ else
+ _xElement->setPropertyValue(PROPERTY_URL,Any(sValue)); // the url is the "sdbc:" string
+ break;
+ }
+ else
+ SAL_WARN("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << aIter.toString());
+ }
+ }
+
+ OUString OFormImport::determineDefaultServiceName() const
+ {
+ return "com.sun.star.form.component.Form";
+ }
+
+} // namespace xmloff
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/forms/elementimport.hxx b/xmloff/source/forms/elementimport.hxx
new file mode 100644
index 000000000..dcf4a6043
--- /dev/null
+++ b/xmloff/source/forms/elementimport.hxx
@@ -0,0 +1,674 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include
+
+#include "propertyimport.hxx"
+#include "controlelement.hxx"
+#include "valueproperties.hxx"
+#include "eventimport.hxx"
+#include "logging.hxx"
+#include "property_description.hxx"
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+ */
+ class OTextLikeImport : public OControlImport
+ {
+ private:
+ css::uno::Reference< css::text::XTextCursor > m_xCursor;
+ css::uno::Reference< css::text::XTextCursor > m_xOldCursor;
+ bool m_bEncounteredTextPara;
+
+ public:
+ OTextLikeImport(
+ OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const css::uno::Reference< css::container::XNameContainer >& _rxParentContainer,
+ OControlElement::ElementType _eType
+ );
+
+ // SvXMLImportContext overridables
+ virtual void SAL_CALL startFastElement(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& _rxAttrList) override;
+ virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
+ virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
+
+ private:
+ void adjustDefaultControlProperty();
+ void removeRedundantCurrentValue();
+ };
+
+ //= OListAndComboImport
+ /** A specialized version of the OControlImport class, which handles
+ attributes / sub elements which are special to list and combo boxes
+ */
+ class OListAndComboImport : public OControlImport
+ {
+ friend class OListOptionImport;
+ friend class OComboItemImport;
+
+ protected:
+ std::vector
+ m_aListSource;
+ std::vector< OUString >
+ m_aValueList;
+
+ std::vector< sal_Int16 >
+ m_aSelectedSeq;
+ std::vector< sal_Int16 >
+ m_aDefaultSelectedSeq;
+
+ OUString m_sCellListSource; /// the cell range which acts as list source for the control
+
+ sal_Int32 m_nEmptyListItems; /// number of empty list items encountered during reading
+ sal_Int32 m_nEmptyValueItems; /// number of empty value items encountered during reading
+
+ bool m_bEncounteredLSAttrib;
+ bool m_bLinkWithIndexes; /** if and only if we should use a cell value binding
+ which exchanges the selection index (instead of the selection text
+ */
+
+ public:
+ OListAndComboImport(
+ OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const css::uno::Reference< css::container::XNameContainer >& _rxParentContainer,
+ OControlElement::ElementType _eType
+ );
+
+ // SvXMLImportContext overridables
+ virtual void SAL_CALL startFastElement( sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override;
+ virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
+ virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
+
+ // OPropertyImport overridables
+ virtual bool handleAttribute(sal_Int32 nElement, const OUString& _rValue) override;
+
+ // OControlImport overridables
+ virtual void doRegisterCellValueBinding( const OUString& _rBoundCellAddress ) override;
+
+ protected:
+ void implPushBackLabel(const OUString& _rLabel);
+ void implPushBackValue(const OUString& _rValue);
+
+ void implEmptyLabelFound();
+ void implEmptyValueFound();
+
+ void implSelectCurrentItem();
+ void implDefaultSelectCurrentItem();
+ };
+ typedef rtl::Reference OListAndComboImportRef;
+
+ //= OListOptionImport
+ /** helper class for importing a single <form:option> element.
+ */
+ class OListOptionImport
+ :public SvXMLImportContext
+ {
+ OListAndComboImportRef m_xListBoxImport;
+
+ public:
+ OListOptionImport(SvXMLImport& _rImport,
+ const OListAndComboImportRef& _rListBox);
+
+ virtual void SAL_CALL startFastElement( sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override;
+ };
+
+ //= OComboItemImport
+ /** helper class for importing a single <form:item> element.
+ */
+ class OComboItemImport
+ :public SvXMLImportContext
+ {
+ OListAndComboImportRef m_xListBoxImport;
+
+ public:
+ OComboItemImport(SvXMLImport& _rImport,
+ const OListAndComboImportRef& _rListBox);
+
+ protected:
+ // SvXMLImportContext overridables
+ virtual void SAL_CALL startFastElement( sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override;
+ };
+
+
+ //= OColumnImport
+ /** helper class importing a single grid column (without the <form:column> element wrapping
+ the column).
+
+ BASE (the template argument) must be a derivee of OControlImport
+ */
+ template
+ class OColumnImport : public BASE
+ {
+ css::uno::Reference< css::form::XGridColumnFactory >
+ m_xColumnFactory;
+
+ public:
+ OColumnImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const css::uno::Reference< css::container::XNameContainer >& _rxParentContainer,
+ OControlElement::ElementType _eType);
+
+ protected:
+ // OElementImport overridables
+ virtual css::uno::Reference< css::beans::XPropertySet >
+ createElement() override;
+ };
+
+ //= OColumnWrapperImport
+ class OColumnWrapperImport : public SvXMLImportContext
+ {
+ css::uno::Reference< css::xml::sax::XFastAttributeList >
+ m_xOwnAttributes;
+ css::uno::Reference< css::container::XNameContainer >
+ m_xParentContainer;
+ OFormLayerXMLImport_Impl& m_rFormImport;
+ IEventAttacherManager& m_rEventManager;
+
+ public:
+ OColumnWrapperImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ sal_Int32 nElement,
+ const css::uno::Reference< css::container::XNameContainer >& _rxParentContainer);
+
+ // SvXMLImportContext overridables
+ virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
+ virtual void SAL_CALL startFastElement(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& _rxAttrList) override;
+ private:
+ OControlImport* implCreateChildContext(
+ sal_Int32 nElement,
+ OControlElement::ElementType _eType);
+ };
+
+ /** helper class importing a single <form:grid> element
+ */
+ class OGridImport : public OControlImport, public ODefaultEventAttacherManager
+ {
+ public:
+ OGridImport(
+ OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const css::uno::Reference< css::container::XNameContainer >& _rxParentContainer,
+ OControlElement::ElementType _eType);
+
+ // SvXMLImportContext overridables
+ virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
+ virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
+
+ private:
+ // OElementImport overridables
+ virtual css::uno::Reference< css::beans::XPropertySet > createElement() override;
+
+ css::uno::Reference< css::container::XNameContainer > m_xMeAsContainer;
+ };
+
+ /** helper class importing a single <form:form> element
+ */
+ class OFormImport : public OElementImport, public ODefaultEventAttacherManager
+ {
+ public:
+ OFormImport(
+ OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager,
+ const css::uno::Reference< css::container::XNameContainer >& _rxParentContainer
+ );
+
+ private:
+ // SvXMLImportContext overridables
+ virtual void SAL_CALL startFastElement(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList) override;
+ virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
+
+ virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+ sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
+
+ // OPropertyImport overridables
+ virtual bool handleAttribute(sal_Int32 nElement, const OUString& _rValue) override;
+
+ // OElementImport overridables
+ virtual css::uno::Reference< css::beans::XPropertySet >
+ createElement() override;
+
+ virtual OUString determineDefaultServiceName() const override;
+ void implTranslateStringListProperty(const OUString& _rPropertyName, const OUString& _rValue);
+
+ css::uno::Reference< css::container::XNameContainer > m_xMeAsContainer;
+ };
+
+ //= OXMLDataSourceImport
+ class OXMLDataSourceImport : public SvXMLImportContext
+ {
+ public:
+ OXMLDataSourceImport( SvXMLImport& _rImport
+ ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList
+ ,const css::uno::Reference< css::beans::XPropertySet >& _xElement);
+ };
+
+ //= OColumnImport
+ template
+ OColumnImport< BASE >::OColumnImport(OFormLayerXMLImport_Impl& _rImport,
+ IEventAttacherManager& _rEventManager,
+ const css::uno::Reference< css::container::XNameContainer >& _rxParentContainer,
+ OControlElement::ElementType _eType)
+ :BASE(_rImport, _rEventManager, _rxParentContainer, _eType)
+ ,m_xColumnFactory(_rxParentContainer, css::uno::UNO_QUERY)
+ {
+ OSL_ENSURE(m_xColumnFactory.is(), "OColumnImport::OColumnImport: invalid parent container (no factory)!");
+ }
+
+ // OElementImport overridables
+ template
+ css::uno::Reference< css::beans::XPropertySet > OColumnImport< BASE >::createElement()
+ {
+ css::uno::Reference< css::beans::XPropertySet > xReturn;
+ // no call to the base class' method. We have to use the grid column factory
+ if (m_xColumnFactory.is())
+ {
+ // create the column
+ xReturn = m_xColumnFactory->createColumn(this->m_sServiceName);
+ OSL_ENSURE(xReturn.is(), "OColumnImport::createElement: the factory returned an invalid object!");
+ }
+ return xReturn;
+ }
+
+} // namespace xmloff
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/forms/eventexport.cxx b/xmloff/source/forms/eventexport.cxx
new file mode 100644
index 000000000..25548fb0a
--- /dev/null
+++ b/xmloff/source/forms/eventexport.cxx
@@ -0,0 +1,126 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "eventexport.hxx"
+#include "strings.hxx"
+#include
+#include
+
+namespace xmloff
+{
+
+ using namespace ::com::sun::star::uno;
+ using namespace ::com::sun::star::script;
+ using namespace ::com::sun::star::container;
+ using namespace ::com::sun::star::beans;
+ using namespace ::com::sun::star::lang;
+
+ //= OEventDescriptorMapper
+ OEventDescriptorMapper::OEventDescriptorMapper(const Sequence< ScriptEventDescriptor >& _rEvents)
+ {
+ // translate the events
+ OUString sLibrary, sLocalMacroName;
+ for (const auto& rEvent : _rEvents)
+ {
+ // the name of the event is build from listener interface and listener method name
+ OUString sName = rEvent.ListenerType
+ + EVENT_NAME_SEPARATOR
+ + rEvent.EventMethod;
+
+ Sequence< PropertyValue >& rMappedEvent = m_aMappedEvents[sName];
+
+ sLocalMacroName = rEvent.ScriptCode;
+ sLibrary.clear();
+ if (rEvent.ScriptType == EVENT_STARBASIC)
+ { // for StarBasic, the library name is part of the ScriptCode
+ sal_Int32 nPrefixLen = sLocalMacroName.indexOf( ':' );
+ SAL_WARN_IF( 0 > nPrefixLen, "xmloff", "OEventDescriptorMapper::OEventDescriptorMapper: invalid script code prefix!" );
+ if ( 0 <= nPrefixLen )
+ {
+ // the export handler for StarBasic expects "StarOffice", not "application" for application modules ...
+ sLibrary = sLocalMacroName.copy( 0, nPrefixLen );
+ if (sLibrary == EVENT_APPLICATION)
+ sLibrary = EVENT_STAROFFICE;
+
+ sLocalMacroName = sLocalMacroName.copy( nPrefixLen + 1 );
+ }
+ // tree property values to describe one event ...
+ rMappedEvent.realloc( sLibrary.isEmpty() ? 2 : 3 );
+ auto pMappedEvent = rMappedEvent.getArray();
+
+ // ... the type
+ pMappedEvent[0] = PropertyValue(EVENT_TYPE, -1, Any(rEvent.ScriptType), PropertyState_DIRECT_VALUE);
+
+ // and the macro name
+ pMappedEvent[1] = PropertyValue(EVENT_LOCALMACRONAME, -1, Any(sLocalMacroName), PropertyState_DIRECT_VALUE);
+
+ // the library
+ if ( !sLibrary.isEmpty() )
+ pMappedEvent[2] = PropertyValue(EVENT_LIBRARY, -1, Any(sLibrary), PropertyState_DIRECT_VALUE);
+ }
+ else
+ {
+ rMappedEvent = { PropertyValue(EVENT_TYPE, -1, Any(rEvent.ScriptType), PropertyState_DIRECT_VALUE),
+ // and the macro name
+ PropertyValue(EVENT_SCRIPTURL, -1, Any(rEvent.ScriptCode), PropertyState_DIRECT_VALUE) };
+ }
+ }
+ }
+
+ void SAL_CALL OEventDescriptorMapper::replaceByName( const OUString&, const Any& )
+ {
+ throw IllegalArgumentException(
+ "replacing is not implemented for this wrapper class.", static_cast< ::cppu::OWeakObject* >(this), 1);
+ }
+
+ Any SAL_CALL OEventDescriptorMapper::getByName( const OUString& _rName )
+ {
+ MapString2PropertyValueSequence::const_iterator aPos = m_aMappedEvents.find(_rName);
+ if (m_aMappedEvents.end() == aPos)
+ throw NoSuchElementException(
+ "There is no element named " + _rName,
+ static_cast< ::cppu::OWeakObject* >(this));
+
+ return Any(aPos->second);
+ }
+
+ Sequence< OUString > SAL_CALL OEventDescriptorMapper::getElementNames( )
+ {
+ return comphelper::mapKeysToSequence(m_aMappedEvents);
+ }
+
+ sal_Bool SAL_CALL OEventDescriptorMapper::hasByName( const OUString& _rName )
+ {
+ MapString2PropertyValueSequence::const_iterator aPos = m_aMappedEvents.find(_rName);
+ return m_aMappedEvents.end() != aPos;
+ }
+
+ Type SAL_CALL OEventDescriptorMapper::getElementType( )
+ {
+ return ::cppu::UnoType::get();
+ }
+
+ sal_Bool SAL_CALL OEventDescriptorMapper::hasElements( )
+ {
+ return !m_aMappedEvents.empty();
+ }
+
+} // namespace xmloff
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/forms/eventexport.hxx b/xmloff/source/forms/eventexport.hxx
new file mode 100644
index 000000000..c4bb752c4
--- /dev/null
+++ b/xmloff/source/forms/eventexport.hxx
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include
+
+#include