/* -*- 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 .
*/
if ( bForeignIsForm != bOwnIsForm )
{ // if this fires, don't attempt to do further assignments, something's completely messed up
SAL_WARN( "svx.form", "FmFormPageImpl::FmFormPageImpl: inconsistent ordering of objects!" ); break;
}
if ( !bForeignIsForm ) // no form control -> next round continue;
Reference< XControlModel > xForeignModel( pForeignObj->GetUnoControlModel() ); if ( !xForeignModel.is() )
{ // if this fires, the SdrObject does not have a UNO Control Model. This is pathological, but well ... // So the cloned SdrObject will also not have a UNO Control Model.
SAL_WARN( "svx.form", "FmFormPageImpl::FmFormPageImpl: control shape without control!" ); continue;
}
MapControlModels::const_iterator assignment = aModelAssignment.find( xForeignModel ); if ( assignment == aModelAssignment.end() )
{ // if this fires, the source SdrObject has a model, but it is not part of the model hierarchy in // i_foreignImpl.getForms(). // Pathological, too ...
SAL_WARN( "svx.form", "FmFormPageImpl::FmFormPageImpl: no clone found for this model!" ); continue;
}
SdrObjListIter aPageIter( &m_rPage ); while ( aPageIter.IsMore() )
{ // only FmFormObjs are what we're interested in
FmFormObj* pCurrent = FmFormObj::GetFormObject( aPageIter.Next() ); if ( !pCurrent ) continue;
// give the newly created collection a place in the universe
SfxObjectShell* pObjShell(rFmFormModel.GetObjectShell()); if ( pObjShell )
m_xForms->setParent( pObjShell->GetModel() );
// tell the UNDO environment that we have a new forms collection
rFmFormModel.GetUndoEnv().AddForms( Reference<XNameContainer>(m_xForms,UNO_QUERY_THROW) );
} return m_xForms;
}
// by default, we use our "current form" if ( !validateCurForm() )
{ // check whether there is a "standard" form if ( Reference<XNameAccess>(xForms,UNO_QUERY_THROW)->hasElements() )
{ // find the standard form
OUString sStandardFormname = SvxResId(RID_STR_STDFORMNAME);
// a form should always have the command type table as default
Reference< XPropertySet > xFormProps( xForm, UNO_QUERY_THROW );
xFormProps->setPropertyValue( FM_PROP_COMMANDTYPE, Any( sal_Int32( CommandType::TABLE ) ) );
// and the "Standard" name
OUString sName = SvxResId(RID_STR_STDFORMNAME);
xFormProps->setPropertyValue( FM_PROP_NAME, Any( sName ) );
Reference< css::form::XForm > FmFormPageImpl::findPlaceInFormComponentHierarchy( const Reference< XFormComponent > & rContent, const Reference< XDataSource > & rDatabase, const OUString& rDBTitle, const OUString& rCursorSource, sal_Int32 nCommandType )
{ // if the control already is child of a form, don't do anything if (!rContent.is() || rContent->getParent().is()) return nullptr;
Reference< XForm > xForm;
// If database and CursorSource are set, the form is searched for using // these criteria, otherwise only current and the DefaultForm. if (rDatabase.is() && !rCursorSource.isEmpty())
{
validateCurForm();
// first search in the current form
xForm = findFormForDataSource( xCurrentForm, rDatabase, rCursorSource, nCommandType );
Reference< css::container::XIndexAccess > xFormsByIndex = getForms();
DBG_ASSERT(xFormsByIndex.is(), "FmFormPageImpl::findPlaceInFormComponentHierarchy : no index access for my forms collection !");
sal_Int32 nCount = xFormsByIndex->getCount(); for (sal_Int32 i = 0; !xForm.is() && i < nCount; i++)
{
Reference< css::form::XForm > xToSearch;
xFormsByIndex->getByIndex(i) >>= xToSearch;
xForm = findFormForDataSource( xToSearch, rDatabase, rCursorSource, nCommandType );
}
// If no css::form found, then create a new one if (!xForm.is())
{
SdrModel& rModel(m_rPage.getSdrModelFromSdrPage()); constbool bUndo(rModel.IsUndoEnabled());
xForm.set(::comphelper::getProcessServiceFactory()->createInstance(FM_SUN_COMPONENT_FORM), UNO_QUERY); // a form should always have the command type table as default
Reference< css::beans::XPropertySet > xFormProps(xForm, UNO_QUERY); try { xFormProps->setPropertyValue(FM_PROP_COMMANDTYPE, Any(sal_Int32(CommandType::TABLE))); } catch(Exception&) { }
if (!rDBTitle.isEmpty())
xFormProps->setPropertyValue(FM_PROP_DATASOURCE,Any(rDBTitle)); else
{
Reference< css::beans::XPropertySet > xDatabaseProps(rDatabase, UNO_QUERY);
Any aDatabaseUrl = xDatabaseProps->getPropertyValue(FM_PROP_URL);
xFormProps->setPropertyValue(FM_PROP_URL, aDatabaseUrl);
}
OSL_ENSURE(_rxDatabase.is(), "FmFormPageImpl::findFormForDataSource: invalid data source!");
OUString sLookupName; // the name of the data source we're looking for
OUString sFormDataSourceName; // the name of the data source the current connection in the form is based on try
{
Reference< XPropertySet > xDSProps(_rxDatabase, UNO_QUERY); if (xDSProps.is())
xDSProps->getPropertyValue(FM_PROP_NAME) >>= sLookupName;
xFormProps->getPropertyValue(FM_PROP_DATASOURCE) >>= sFormDataSourceName; // if there's no DataSourceName set at the form, check whether we can deduce one from its // ActiveConnection if (sFormDataSourceName.isEmpty())
{
Reference< XConnection > xFormConnection;
xFormProps->getPropertyValue( FM_PROP_ACTIVE_CONNECTION ) >>= xFormConnection; if ( !xFormConnection.is() )
isEmbeddedInDatabase( xFormProps, xFormConnection ); if (xFormConnection.is())
{
Reference< XChild > xConnAsChild(xFormConnection, UNO_QUERY); if (xConnAsChild.is())
{
Reference< XDataSource > xFormDS(xConnAsChild->getParent(), UNO_QUERY); if (xFormDS.is())
{
xDSProps.set(xFormDS, css::uno::UNO_QUERY); if (xDSProps.is())
xDSProps->getPropertyValue(FM_PROP_NAME) >>= sFormDataSourceName;
}
}
}
}
} catch(const Exception&)
{
TOOLS_WARN_EXCEPTION("svx", "FmFormPageImpl::findFormForDataSource");
}
if (sLookupName == sFormDataSourceName)
{ // now check whether CursorSource and type match
OUString aCursorSource = ::comphelper::getString(xFormProps->getPropertyValue(FM_PROP_COMMAND));
sal_Int32 nType = ::comphelper::getINT32(xFormProps->getPropertyValue(FM_PROP_COMMANDTYPE)); if (aCursorSource.isEmpty() || ((nType == nCommandType) && (aCursorSource == _rCursorSource))) // found the form
{
xResultForm = rForm; // if no data source is set yet, it is done here if (aCursorSource.isEmpty())
{
xFormProps->setPropertyValue(FM_PROP_COMMAND, Any(_rCursorSource));
xFormProps->setPropertyValue(FM_PROP_COMMANDTYPE, Any(nCommandType));
}
}
}
// as long as xResultForm is NULL, search the child forms of rForm
Reference< XIndexAccess > xComponents(rForm, UNO_QUERY);
sal_Int32 nCount = xComponents->getCount(); for (sal_Int32 i = 0; !xResultForm.is() && i < nCount; ++i)
{
Reference< css::form::XForm > xSearchForm;
xComponents->getByIndex(i) >>= xSearchForm; // continue searching in the sub form if (xSearchForm.is())
xResultForm = findFormForDataSource( xSearchForm, _rxDatabase, _rCursorSource, nCommandType );
} return xResultForm;
}
if (sName.isEmpty() || xNameAcc->hasByName(sName))
{ // set a default name via the ClassId
sal_Int16 nClassId( FormComponentType::CONTROL );
xSet->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId;
// do not overwrite the name of radio buttons that have it! if (sName.isEmpty() || nClassId != css::form::FormComponentType::RADIOBUTTON)
{
xSet->setPropertyValue(FM_PROP_NAME, Any(sDefaultName));
}
sName = sDefaultName;
}
} return sName;
}
void FmFormPageImpl::formModelAssigned( const FmFormObj& _object )
{
Reference< XMap > xControlShapeMap( m_aControlShapeMap.get(), UNO_QUERY ); if ( !xControlShapeMap.is() ) // our map does not exist -> not interested in this event return;
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.