/* -*- 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 .
*/
// properties not added because they're already present in another form
OSL_ENSURE(
OAttributeMetaData::getCommonControlAttributeName(CCAFlags::TargetLocation).equals(
OAttributeMetaData::getFormAttributeName(faAction)), "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (1)!"); // if this fails, we would have to add a translation from faAction->PROPERTY_TARGETURL // We did not because we already have one CCAFlags::TargetLocation->PROPERTY_TARGETURL, // and CCAFlags::TargetLocation and faAction should be represented by the same attribute
OSL_ENSURE(
OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Name).equals(
OAttributeMetaData::getFormAttributeName(faName)), "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (2)!"); // the same for faName, CCAFlags::Name and PROPERTY_NAME
void OFormLayerXMLImport_Impl::setAutoStyleContext(SvXMLStylesContext* _pNewContext)
{
OSL_ENSURE(!m_xAutoStyles.is(), "OFormLayerXMLImport_Impl::setAutoStyleContext: not to be called twice!");
m_xAutoStyles.set(_pNewContext);
}
OSL_ENSURE(m_xAutoStyles.is(), "OFormLayerXMLImport_Impl::applyControlNumberStyle: have no auto style context!"); if (!m_xAutoStyles.is())
{
m_xAutoStyles.set(m_rImporter.GetShapeImport()->GetAutoStylesContext());
}
// set this format at the control model try
{ // the models number format supplier and formats
Reference< XNumberFormatsSupplier > xFormatsSupplier;
_rxControlModel->getPropertyValue(PROPERTY_FORMATSSUPPLIER) >>= xFormatsSupplier;
Reference< XNumberFormats > xFormats; if (xFormatsSupplier.is())
xFormats = xFormatsSupplier->getNumberFormats();
OSL_ENSURE(xFormats.is(), "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain the controls number formats!");
// obtain a key if (xFormats.is())
{
sal_Int32 nFormatKey = const_cast<SvXMLNumFormatContext*>(pDataStyle)->CreateAndInsert( xFormatsSupplier );
OSL_ENSURE(-1 != nFormatKey, "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain a format key!");
// set the format on the control model
_rxControlModel->setPropertyValue(PROPERTY_FORMATKEY, Any(nFormatKey));
}
} catch(const Exception&)
{
OSL_FAIL("OFormLayerXMLImport_Impl::applyControlNumberStyle: couldn't set the format!");
}
} else
OSL_FAIL("OFormLayerXMLImport_Impl::applyControlNumberStyle: did not find the style with the given name!");
}
void OFormLayerXMLImport_Impl::registerCellRangeListSource( const Reference< XPropertySet >& _rxControlModel, const OUString& _rCellRangeAddress )
{
OSL_ENSURE( _rxControlModel.is() && !_rCellRangeAddress.isEmpty(), "OFormLayerXMLImport_Impl::registerCellRangeListSource: invalid arguments!" );
m_aCellRangeListSources.emplace_back( _rxControlModel, _rCellRangeAddress );
} const SvXMLStyleContext* OFormLayerXMLImport_Impl::getStyleElement(const OUString& _rStyleName) const
{
OSL_ENSURE( m_xAutoStyles.is(), "OFormLayerXMLImport_Impl::getStyleElement: have no auto style context!" ); // did you use setAutoStyleContext?
const SvXMLStyleContext* pControlStyle =
m_xAutoStyles.is() ? m_xAutoStyles->FindStyleChildContext( XmlStyleFamily::TEXT_PARAGRAPH, _rStyleName ) : nullptr;
OSL_ENSURE( pControlStyle || !m_xAutoStyles.is(),
OStringBuffer("OFormLayerXMLImport_Impl::getStyleElement: did not find the style named \"" +
OUStringToOString(_rStyleName, RTL_TEXTENCODING_ASCII_US) + "\"!").getStr() ); return pControlStyle;
}
void OFormLayerXMLImport_Impl::enterEventContext()
{ // install our own translation table. We need to disable the other tables because of name conflicts.
m_rImporter.GetEventImport().PushTranslationTable();
m_rImporter.GetEventImport().AddTranslationTable(g_pFormsEventTranslation);
}
void OFormLayerXMLImport_Impl::leaveEventContext()
{ // install the original event tables.
m_rImporter.GetEventImport().PopTranslationTable();
}
void OFormLayerXMLImport_Impl::registerControlId(const Reference< XPropertySet >& _rxControl, const OUString& _rId)
{
OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::registerControlId: no current page!");
OSL_ENSURE(!_rId.isEmpty(), "OFormLayerXMLImport_Impl::registerControlId: invalid (empty) control id!");
OSL_ENSURE(m_aCurrentPageIds->second.end() == m_aCurrentPageIds->second.find(_rId), "OFormLayerXMLImport_Impl::registerControlId: control id already used!");
m_aCurrentPageIds->second[_rId] = _rxControl;
}
OSL_ENSURE(_rxDrawPage.is(), "OFormLayerXMLImport_Impl::startPage: NULL page!");
m_xCurrentPageFormsSupp.set(_rxDrawPage, css::uno::UNO_QUERY);
OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::startPage: invalid draw page (no XFormsSupplier)!" ); if ( !m_xCurrentPageFormsSupp.is() ) return;
// add a new entry to our page map
::std::pair< MapDrawPage2Map::iterator, bool > aPagePosition = m_aControlIds.emplace(_rxDrawPage, MapString2PropertySet());
OSL_ENSURE(aPagePosition.second, "OFormLayerXMLImport_Impl::startPage: already imported this page!");
m_aCurrentPageIds = aPagePosition.first;
}
void OFormLayerXMLImport_Impl::endPage()
{
OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::endPage: sure you called startPage before?" );
// do some knittings for the controls which are referring to each other try
{ staticconst sal_Unicode s_nSeparator = ',';
OUString sCurrentReferring;
OUString sSeparator(&s_nSeparator, 1);
Reference< XPropertySet > xCurrentReferring;
sal_Int32 nSeparator, nPrevSep; for ( constauto& rReferences : m_aControlReferences )
{ // the list of control ids is comma separated
// in a list of n ids there are only n-1 separators ... have to catch this last id // -> normalize the list
OUString sReferring = rReferences.second + sSeparator;
nPrevSep = -1; while (-1 != (nSeparator = sReferring.indexOf(s_nSeparator, nPrevSep + 1)))
{
sCurrentReferring = sReferring.copy(nPrevSep + 1, nSeparator - nPrevSep - 1);
xCurrentReferring = lookupControlId(sCurrentReferring); if (xCurrentReferring.is()) // if this condition fails, this is an error, but lookupControlId should have asserted this ...
xCurrentReferring->setPropertyValue( PROPERTY_CONTROLLABEL, Any( rReferences.first ) );
nPrevSep = nSeparator;
}
}
} catch(Exception&)
{
TOOLS_WARN_EXCEPTION("xmloff.forms", "unable to knit the control references (caught an exception)!");
}
// now that we have all children of the forms collection, attach the events
Reference< XIndexAccess > xIndexContainer; if ( m_xCurrentPageFormsSupp.is() && m_xCurrentPageFormsSupp->hasForms() )
xIndexContainer.set(m_xCurrentPageFormsSupp->getForms(), css::uno::UNO_QUERY); if ( xIndexContainer.is() )
ODefaultEventAttacherManager::setEvents( xIndexContainer );
// clear the structures for the control references.
m_aControlReferences.clear();
// and no we have no current page anymore
m_aCurrentPageIds = m_aControlIds.end();
}
Reference< XPropertySet > OFormLayerXMLImport_Impl::lookupControlId(const OUString& _rControlId)
{
OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::lookupControlId: no current page!");
Reference< XPropertySet > xReturn; if (m_aCurrentPageIds != m_aControlIds.end())
{
MapString2PropertySet::const_iterator aPos = m_aCurrentPageIds->second.find(_rControlId); if (m_aCurrentPageIds->second.end() != aPos)
xReturn = aPos->second; else
SAL_WARN("xmloff", "unknown control id " << _rControlId);
} return xReturn;
}
// create (and bind) the spreadsheet cell bindings if ( !m_aCellValueBindings.empty()
&& FormCellBindingHelper::isCellBindingAllowed( rImport.GetModel() )
)
{ for ( constauto& rCellBindings : m_aCellValueBindings )
{ try
{
FormCellBindingHelper aHelper( rCellBindings.first, rImport.GetModel() );
OSL_ENSURE( aHelper.isCellBindingAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" ); if ( aHelper.isCellBindingAllowed() )
{ // There are special bindings for listboxes. See // OListAndComboImport::doRegisterCellValueBinding for a comment on this HACK.
OUString sBoundCellAddress( rCellBindings.second );
sal_Int32 nIndicator = sBoundCellAddress.lastIndexOf( ":index" );
aHelper.setBinding( aHelper.createCellBindingFromStringAddress( sBoundCellAddress, bUseIndexBinding ) );
}
} catch( const Exception& )
{
TOOLS_WARN_EXCEPTION("xmloff.forms", "caught an exception while binding to a cell!");
}
}
m_aCellValueBindings.clear();
}
// the same for the spreadsheet cell range list sources if ( !m_aCellRangeListSources.empty()
&& FormCellBindingHelper::isListCellRangeAllowed( rImport.GetModel() )
)
{ for ( constauto& rRangeBindings : m_aCellRangeListSources )
{ try
{
FormCellBindingHelper aHelper( rRangeBindings.first, rImport.GetModel() );
OSL_ENSURE( aHelper.isListCellRangeAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" ); if ( aHelper.isListCellRangeAllowed() )
{
aHelper.setListSource( aHelper.createCellListSourceFromStringAddress( rRangeBindings.second ) );
}
} catch( const Exception& )
{
TOOLS_WARN_EXCEPTION("xmloff.forms", "caught an exception while binding to a cell range!");
}
}
m_aCellRangeListSources.clear();
}
// process XForms-bindings; call registerXFormsValueBinding for each for (constauto& aXFormsValueBinding : m_aXFormsValueBindings)
bindXFormsValueBinding(rImport.GetModel(), aXFormsValueBinding); // same for list bindings for (constauto& aXFormsListBindings : m_aXFormsListBindings)
bindXFormsListBinding(rImport.GetModel(), aXFormsListBindings); // same for submissions for (constauto& aXFormsSubmission : m_aXFormsSubmissions)
bindXFormsSubmission(rImport.GetModel(), aXFormsSubmission);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.