bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / form / fmpgeimp.cxx
blobeebc4aba574987093b6d0326225a4e6069994e6c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "svx/svxerr.hxx"
22 #include "fmpgeimp.hxx"
23 #include "fmundo.hxx"
24 #include "svx/fmtools.hxx"
25 #include "fmprop.hrc"
26 #include "fmservs.hxx"
27 #include "fmobj.hxx"
28 #include "formcontrolfactory.hxx"
29 #include "svx/svditer.hxx"
30 #include "svx/fmresids.hrc"
31 #include "svx/dbtoolsclient.hxx"
32 #include "treevisitor.hxx"
34 #include <com/sun/star/sdb/CommandType.hpp>
35 #include <com/sun/star/util/XCloneable.hpp>
36 #include <com/sun/star/container/EnumerableMap.hpp>
37 #include <com/sun/star/drawing/XControlShape.hpp>
38 #include <com/sun/star/form/Forms.hpp>
40 #include <sfx2/objsh.hxx>
41 #include <svx/fmglob.hxx>
42 #include <svx/fmpage.hxx>
43 #include <svx/fmmodel.hxx>
44 #include <tools/resid.hxx>
45 #include <tools/diagnose_ex.h>
46 #include <tools/shl.hxx>
47 #include <vcl/stdtext.hxx>
48 #include <svx/dialmgr.hxx>
49 #include <comphelper/processfactory.hxx>
50 #include <comphelper/uno3.hxx>
51 #include <comphelper/types.hxx>
52 #include <unotools/streamwrap.hxx>
53 #include <rtl/logfile.hxx>
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::sdbc;
58 using namespace ::com::sun::star::sdb;
59 using namespace ::com::sun::star::container;
60 using namespace ::com::sun::star::beans;
61 using namespace ::com::sun::star::form;
62 using ::com::sun::star::util::XCloneable;
63 using ::com::sun::star::awt::XControlModel;
64 using ::com::sun::star::container::XMap;
65 using ::com::sun::star::container::EnumerableMap;
66 using ::com::sun::star::drawing::XControlShape;
67 using namespace ::svxform;
69 DBG_NAME(FmFormPageImpl)
70 //------------------------------------------------------------------------------
71 FmFormPageImpl::FmFormPageImpl( FmFormPage& _rPage )
72 :m_rPage( _rPage )
73 ,m_bFirstActivation( sal_True )
74 ,m_bAttemptedFormCreation( false )
75 ,m_bInFind( false )
77 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPageImpl::FmFormPageImpl" );
78 DBG_CTOR(FmFormPageImpl,NULL);
81 //------------------------------------------------------------------------------
82 namespace
84 typedef Reference< XInterface > FormComponent;
86 class FormComponentInfo
88 public:
89 size_t childCount( const FormComponent& _component ) const
91 Reference< XIndexAccess > xContainer( _component, UNO_QUERY );
92 if ( xContainer.is() )
93 return xContainer->getCount();
94 return 0;
97 FormComponent getChild( const FormComponent& _component, size_t _index ) const
99 Reference< XIndexAccess > xContainer( _component, UNO_QUERY_THROW );
100 return FormComponent( xContainer->getByIndex( _index ), UNO_QUERY );
104 typedef ::std::pair< FormComponent, FormComponent > FormComponentPair;
106 class FormHierarchyComparator
108 public:
109 FormHierarchyComparator()
113 size_t childCount( const FormComponentPair& _components ) const
115 size_t lhsCount = m_aComponentInfo.childCount( _components.first );
116 size_t rhsCount = m_aComponentInfo.childCount( _components.second );
117 if ( lhsCount != rhsCount )
118 throw RuntimeException( OUString( "Found inconsistent form component hierarchies (1)!" ), NULL );
119 return lhsCount;
122 FormComponentPair getChild( const FormComponentPair& _components, size_t _index ) const
124 return FormComponentPair(
125 m_aComponentInfo.getChild( _components.first, _index ),
126 m_aComponentInfo.getChild( _components.second, _index )
129 private:
130 FormComponentInfo m_aComponentInfo;
133 typedef ::std::map< Reference< XControlModel >, Reference< XControlModel >, ::comphelper::OInterfaceCompare< XControlModel > > MapControlModels;
135 class FormComponentAssignment
137 public:
138 FormComponentAssignment( MapControlModels& _out_controlModelMap )
139 :m_rControlModelMap( _out_controlModelMap )
143 void process( const FormComponentPair& _component )
145 Reference< XControlModel > lhsControlModel( _component.first, UNO_QUERY );
146 Reference< XControlModel > rhsControlModel( _component.second, UNO_QUERY );
147 if ( lhsControlModel.is() != rhsControlModel.is() )
148 throw RuntimeException( OUString( "Found inconsistent form component hierarchies (2)!" ), NULL );
150 if ( lhsControlModel.is() )
151 m_rControlModelMap[ lhsControlModel ] = rhsControlModel;
154 private:
155 MapControlModels& m_rControlModelMap;
159 //------------------------------------------------------------------------------
160 void FmFormPageImpl::initFrom( FmFormPageImpl& i_foreignImpl )
162 // clone the Forms collection
163 const Reference< css::form::XForms > xForeignForms( const_cast< FmFormPageImpl& >( i_foreignImpl ).getForms( false ) );
165 if ( !xForeignForms.is() )
166 return;
170 m_xForms.set( xForeignForms->createClone(), UNO_QUERY_THROW );
172 // create a mapping between the original control models and their clones
173 MapControlModels aModelAssignment;
175 typedef TreeVisitor< FormComponentPair, FormHierarchyComparator, FormComponentAssignment > FormComponentVisitor;
176 FormComponentVisitor aVisitor = FormComponentVisitor( FormHierarchyComparator() );
178 FormComponentAssignment aAssignmentProcessor( aModelAssignment );
179 aVisitor.process( FormComponentPair( xForeignForms, m_xForms ), aAssignmentProcessor );
181 // assign the cloned models to their SdrObjects
182 SdrObjListIter aForeignIter( i_foreignImpl.m_rPage );
183 SdrObjListIter aOwnIter( m_rPage );
185 OSL_ENSURE( aForeignIter.IsMore() == aOwnIter.IsMore(), "FmFormPageImpl::FmFormPageImpl: inconsistent number of objects (1)!" );
186 while ( aForeignIter.IsMore() && aOwnIter.IsMore() )
188 FmFormObj* pForeignObj = dynamic_cast< FmFormObj* >( aForeignIter.Next() );
189 FmFormObj* pOwnObj = dynamic_cast< FmFormObj* >( aOwnIter.Next() );
191 bool bForeignIsForm = pForeignObj && ( pForeignObj->GetObjInventor() == FmFormInventor );
192 bool bOwnIsForm = pOwnObj && ( pOwnObj->GetObjInventor() == FmFormInventor );
194 if ( bForeignIsForm != bOwnIsForm )
196 // if this fires, don't attempt to do further assignments, something's completely messed up
197 SAL_WARN( "svx.form", "FmFormPageImpl::FmFormPageImpl: inconsistent ordering of objects!" );
198 break;
201 if ( !bForeignIsForm )
202 // no form control -> next round
203 continue;
205 Reference< XControlModel > xForeignModel( pForeignObj->GetUnoControlModel() );
206 if ( !xForeignModel.is() )
208 // if this fires, the SdrObject does not have a UNO Control Model. This is pathological, but well ...
209 // So the cloned SdrObject will also not have a UNO Control Model.
210 SAL_WARN( "svx.form", "FmFormPageImpl::FmFormPageImpl: control shape without control!" );
211 continue;
214 MapControlModels::const_iterator assignment = aModelAssignment.find( xForeignModel );
215 if ( assignment == aModelAssignment.end() )
217 // if this fires, the source SdrObject has a model, but it is not part of the model hierarchy in
218 // i_foreignImpl.getForms().
219 // Pathological, too ...
220 SAL_WARN( "svx.form", "FmFormPageImpl::FmFormPageImpl: no clone found for this model!" );
221 continue;
224 pOwnObj->SetUnoControlModel( assignment->second );
226 OSL_ENSURE( aForeignIter.IsMore() == aOwnIter.IsMore(), "FmFormPageImpl::FmFormPageImpl: inconsistent number of objects (2)!" );
228 catch( const Exception& )
230 DBG_UNHANDLED_EXCEPTION();
234 //------------------------------------------------------------------------------
235 Reference< XMap > FmFormPageImpl::getControlToShapeMap()
237 Reference< XMap > xControlShapeMap( m_aControlShapeMap.get(), UNO_QUERY );
238 if ( xControlShapeMap.is() )
239 return xControlShapeMap;
241 xControlShapeMap = impl_createControlShapeMap_nothrow();
242 m_aControlShapeMap = xControlShapeMap;
243 return xControlShapeMap;
246 //------------------------------------------------------------------------------
247 namespace
249 static void lcl_insertFormObject_throw( const FmFormObj& _object, const Reference< XMap >& _map )
251 // the control model
252 Reference< XControlModel > xControlModel( _object.GetUnoControlModel(), UNO_QUERY );
253 OSL_ENSURE( xControlModel.is(), "lcl_insertFormObject_throw: suspicious: no control model!" );
254 if ( !xControlModel.is() )
255 return;
257 Reference< XControlShape > xControlShape( const_cast< FmFormObj& >( _object ).getUnoShape(), UNO_QUERY );
258 OSL_ENSURE( xControlShape.is(), "lcl_insertFormObject_throw: suspicious: no control shape!" );
259 if ( !xControlShape.is() )
260 return;
262 _map->put( makeAny( xControlModel ), makeAny( xControlShape ) );
265 static void lcl_removeFormObject_throw( const FmFormObj& _object, const Reference< XMap >& _map, bool i_ignoreNonExistence = false )
267 // the control model
268 Reference< XControlModel > xControlModel( _object.GetUnoControlModel(), UNO_QUERY );
269 OSL_ENSURE( xControlModel.is(), "lcl_removeFormObject: suspicious: no control model!" );
270 if ( !xControlModel.is() )
271 return;
273 #if OSL_DEBUG_LEVEL > 0
274 Any aOldAssignment =
275 #endif
276 _map->remove( makeAny( xControlModel ) );
277 #if OSL_DEBUG_LEVEL > 0
278 (void)aOldAssignment;
279 #endif
280 OSL_ENSURE( !i_ignoreNonExistence ||
281 ( aOldAssignment == makeAny( Reference< XControlShape >( const_cast< FmFormObj& >( _object ).getUnoShape(), UNO_QUERY ) ) ),
282 "lcl_removeFormObject: map was inconsistent!" );
283 (void)i_ignoreNonExistence;
287 //------------------------------------------------------------------------------
288 Reference< XMap > FmFormPageImpl::impl_createControlShapeMap_nothrow()
290 Reference< XMap > xMap;
294 xMap.set( EnumerableMap::create( comphelper::getProcessComponentContext(),
295 ::cppu::UnoType< XControlModel >::get(),
296 ::cppu::UnoType< XControlShape >::get()
297 ).get(), UNO_SET_THROW );
299 SdrObjListIter aPageIter( m_rPage );
300 while ( aPageIter.IsMore() )
302 // only FmFormObjs are what we're interested in
303 FmFormObj* pCurrent = FmFormObj::GetFormObject( aPageIter.Next() );
304 if ( !pCurrent )
305 continue;
307 lcl_insertFormObject_throw( *pCurrent, xMap );
310 catch( const Exception& )
312 DBG_UNHANDLED_EXCEPTION();
314 return xMap;
317 //------------------------------------------------------------------------------
318 const Reference< css::form::XForms >& FmFormPageImpl::getForms( bool _bForceCreate )
320 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPageImpl::getForms" );
321 if ( m_xForms.is() || !_bForceCreate )
322 return m_xForms;
324 if ( !m_bAttemptedFormCreation )
326 m_bAttemptedFormCreation = true;
328 Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
329 m_xForms = css::form::Forms::create( xContext );
331 if ( m_aFormsCreationHdl.IsSet() )
333 m_aFormsCreationHdl.Call( this );
336 FmFormModel* pFormsModel = PTR_CAST( FmFormModel, m_rPage.GetModel() );
338 // give the newly created collection a place in the universe
339 SfxObjectShell* pObjShell = pFormsModel ? pFormsModel->GetObjectShell() : NULL;
340 if ( pObjShell )
341 m_xForms->setParent( pObjShell->GetModel() );
343 // tell the UNDO environment that we have a new forms collection
344 if ( pFormsModel )
345 pFormsModel->GetUndoEnv().AddForms( Reference<XNameContainer>(m_xForms,UNO_QUERY_THROW) );
347 return m_xForms;
350 //------------------------------------------------------------------------------
351 FmFormPageImpl::~FmFormPageImpl()
353 xCurrentForm = NULL;
355 ::comphelper::disposeComponent( m_xForms );
356 DBG_DTOR(FmFormPageImpl,NULL);
359 //------------------------------------------------------------------------------
360 bool FmFormPageImpl::validateCurForm()
362 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPageImpl::validateCurForm" );
363 if ( !xCurrentForm.is() )
364 return false;
366 Reference< XChild > xAsChild( xCurrentForm, UNO_QUERY );
367 DBG_ASSERT( xAsChild.is(), "FmFormPageImpl::validateCurForm: a form which is no child??" );
368 if ( !xAsChild.is() || !xAsChild->getParent().is() )
369 xCurrentForm.clear();
371 return xCurrentForm.is();
374 //------------------------------------------------------------------------------
375 void FmFormPageImpl::setCurForm(Reference< ::com::sun::star::form::XForm > xForm)
377 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPageImpl::setCurForm" );
378 xCurrentForm = xForm;
381 //------------------------------------------------------------------------------
382 Reference< XForm > FmFormPageImpl::getDefaultForm()
384 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPageImpl::getDefaultForm" );
385 Reference< XForm > xForm;
387 Reference< XForms > xForms( getForms() );
389 // by default, we use our "current form"
390 if ( !validateCurForm() )
392 // check whether there is a "standard" form
393 if ( Reference<XNameAccess>(xForms,UNO_QUERY_THROW)->hasElements() )
395 // suche die Standardform
396 OUString sStandardFormname = String( SVX_RES( RID_STR_STDFORMNAME ) );
400 if ( xForms->hasByName( sStandardFormname ) )
401 xForm.set( xForms->getByName( sStandardFormname ), UNO_QUERY_THROW );
402 else
404 xForm.set( xForms->getByIndex(0), UNO_QUERY_THROW );
407 catch( const Exception& )
409 DBG_UNHANDLED_EXCEPTION();
413 else
415 xForm = xCurrentForm;
418 // did not find an existing suitable form -> create a new one
419 if ( !xForm.is() )
421 SdrModel* pModel = m_rPage.GetModel();
423 if( pModel->IsUndoEnabled() )
425 XubString aStr(SVX_RES(RID_STR_FORM));
426 XubString aUndoStr(SVX_RES(RID_STR_UNDO_CONTAINER_INSERT));
427 aUndoStr.SearchAndReplace(OUString('#'), aStr);
428 pModel->BegUndo(aUndoStr);
433 xForm.set( ::comphelper::getProcessServiceFactory()->createInstance( FM_SUN_COMPONENT_FORM ), UNO_QUERY );
435 // a form should always have the command type table as default
436 Reference< XPropertySet > xFormProps( xForm, UNO_QUERY_THROW );
437 xFormProps->setPropertyValue( FM_PROP_COMMANDTYPE, makeAny( sal_Int32( CommandType::TABLE ) ) );
439 // and the "Standard" name
440 OUString sName = String( SVX_RES( RID_STR_STDFORMNAME ) );
441 xFormProps->setPropertyValue( FM_PROP_NAME, makeAny( sName ) );
443 Reference< XIndexContainer > xContainer( xForms, UNO_QUERY );
444 if( pModel->IsUndoEnabled() )
446 pModel->AddUndo(new FmUndoContainerAction(*(FmFormModel*)pModel,
447 FmUndoContainerAction::Inserted,
448 xContainer,
449 xForm,
450 xContainer->getCount()));
452 xForms->insertByName( sName, makeAny( xForm ) );
453 xCurrentForm = xForm;
455 catch( const Exception& )
457 DBG_UNHANDLED_EXCEPTION();
458 xForm.clear();
461 if( pModel->IsUndoEnabled() )
462 pModel->EndUndo();
465 return xForm;
468 //------------------------------------------------------------------------------
469 Reference< ::com::sun::star::form::XForm > FmFormPageImpl::findPlaceInFormComponentHierarchy(
470 const Reference< XFormComponent > & rContent, const Reference< XDataSource > & rDatabase,
471 const OUString& rDBTitle, const OUString& rCursorSource, sal_Int32 nCommandType )
473 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPageImpl::findPlaceInFormComponentHierarchy" );
474 // if the control already is child of a form, don't do anything
475 if (!rContent.is() || rContent->getParent().is())
476 return NULL;
478 Reference< XForm > xForm;
480 // Wenn Datenbank und CursorSource gesetzt sind, dann wird
481 // die Form anhand dieser Kriterien gesucht, ansonsten nur aktuelle
482 // und die StandardForm
483 if (rDatabase.is() && !rCursorSource.isEmpty())
485 validateCurForm();
487 // erst in der aktuellen form suchen
488 xForm = findFormForDataSource( xCurrentForm, rDatabase, rCursorSource, nCommandType );
490 Reference< ::com::sun::star::container::XIndexAccess > xFormsByIndex( getForms(), UNO_QUERY );
491 DBG_ASSERT(xFormsByIndex.is(), "FmFormPageImpl::findPlaceInFormComponentHierarchy : no index access for my forms collection !");
492 sal_Int32 nCount = xFormsByIndex->getCount();
493 for (sal_Int32 i = 0; !xForm.is() && i < nCount; i++)
495 Reference< ::com::sun::star::form::XForm > xToSearch;
496 xFormsByIndex->getByIndex(i) >>= xToSearch;
497 xForm = findFormForDataSource( xToSearch, rDatabase, rCursorSource, nCommandType );
500 // wenn keine ::com::sun::star::form gefunden, dann eine neue erzeugen
501 if (!xForm.is())
503 SdrModel* pModel = m_rPage.GetModel();
505 const bool bUndo = pModel->IsUndoEnabled();
507 if( bUndo )
509 XubString aStr(SVX_RES(RID_STR_FORM));
510 XubString aUndoStr(SVX_RES(RID_STR_UNDO_CONTAINER_INSERT));
511 aUndoStr.SearchAndReplace(OUString('#'), aStr);
512 pModel->BegUndo(aUndoStr);
515 xForm = Reference< ::com::sun::star::form::XForm >(::comphelper::getProcessServiceFactory()->createInstance(FM_SUN_COMPONENT_FORM), UNO_QUERY);
516 // a form should always have the command type table as default
517 Reference< ::com::sun::star::beans::XPropertySet > xFormProps(xForm, UNO_QUERY);
518 try { xFormProps->setPropertyValue(FM_PROP_COMMANDTYPE, makeAny(sal_Int32(CommandType::TABLE))); }
519 catch(Exception&) { }
521 if (!rDBTitle.isEmpty())
522 xFormProps->setPropertyValue(FM_PROP_DATASOURCE,makeAny(rDBTitle));
523 else
525 Reference< ::com::sun::star::beans::XPropertySet > xDatabaseProps(rDatabase, UNO_QUERY);
526 Any aDatabaseUrl = xDatabaseProps->getPropertyValue(FM_PROP_URL);
527 xFormProps->setPropertyValue(FM_PROP_DATASOURCE, aDatabaseUrl);
530 xFormProps->setPropertyValue(FM_PROP_COMMAND,makeAny(rCursorSource));
531 xFormProps->setPropertyValue(FM_PROP_COMMANDTYPE, makeAny(nCommandType));
533 Reference< ::com::sun::star::container::XNameAccess > xNamedSet( getForms(), UNO_QUERY );
535 const bool bTableOrQuery = ( CommandType::TABLE == nCommandType ) || ( CommandType::QUERY == nCommandType );
536 OUString sName = FormControlFactory::getUniqueName( xNamedSet,
537 bTableOrQuery ? rCursorSource : OUString( String( SVX_RES( RID_STR_STDFORMNAME ) ) ) );
539 xFormProps->setPropertyValue( FM_PROP_NAME, makeAny( sName ) );
541 if( bUndo )
543 Reference< ::com::sun::star::container::XIndexContainer > xContainer( getForms(), UNO_QUERY );
544 pModel->AddUndo(new FmUndoContainerAction(*(FmFormModel*)pModel,
545 FmUndoContainerAction::Inserted,
546 xContainer,
547 xForm,
548 xContainer->getCount()));
551 getForms()->insertByName( sName, makeAny( xForm ) );
553 if( bUndo )
554 pModel->EndUndo();
556 xCurrentForm = xForm;
559 xForm = getDefaultForm();
560 return xForm;
563 //------------------------------------------------------------------------------
564 Reference< XForm > FmFormPageImpl::findFormForDataSource(
565 const Reference< XForm > & rForm, const Reference< XDataSource > & _rxDatabase,
566 const OUString& _rCursorSource, sal_Int32 nCommandType)
568 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmFormPageImpl::findFormForDataSource" );
569 Reference< XForm > xResultForm;
570 Reference< XRowSet > xDBForm(rForm, UNO_QUERY);
571 Reference< XPropertySet > xFormProps(rForm, UNO_QUERY);
572 if (!xDBForm.is() || !xFormProps.is())
573 return xResultForm;
575 OSL_ENSURE(_rxDatabase.is(), "FmFormPageImpl::findFormForDataSource: invalid data source!");
576 OUString sLookupName; // the name of the data source we're looking for
577 OUString sFormDataSourceName; // the name of the data source the current connection in the form is based on
580 Reference< XPropertySet > xDSProps(_rxDatabase, UNO_QUERY);
581 if (xDSProps.is())
582 xDSProps->getPropertyValue(FM_PROP_NAME) >>= sLookupName;
584 xFormProps->getPropertyValue(FM_PROP_DATASOURCE) >>= sFormDataSourceName;
585 // if there's no DataSourceName set at the form, check whether we can deduce one from its
586 // ActiveConnection
587 if (sFormDataSourceName.isEmpty())
589 Reference< XConnection > xFormConnection;
590 xFormProps->getPropertyValue( FM_PROP_ACTIVE_CONNECTION ) >>= xFormConnection;
591 if ( !xFormConnection.is() )
592 OStaticDataAccessTools().isEmbeddedInDatabase( xFormProps, xFormConnection );
593 if (xFormConnection.is())
595 Reference< XChild > xConnAsChild(xFormConnection, UNO_QUERY);
596 if (xConnAsChild.is())
598 Reference< XDataSource > xFormDS(xConnAsChild->getParent(), UNO_QUERY);
599 if (xFormDS.is())
601 xDSProps = xDSProps.query(xFormDS);
602 if (xDSProps.is())
603 xDSProps->getPropertyValue(FM_PROP_NAME) >>= sFormDataSourceName;
609 catch(const Exception& e)
611 (void)e;
612 OSL_FAIL("FmFormPageImpl::findFormForDataSource: caught an exception!");
615 if (sLookupName == sFormDataSourceName)
617 // jetzt noch ueberpruefen ob CursorSource und Type uebereinstimmen
618 OUString aCursorSource = ::comphelper::getString(xFormProps->getPropertyValue(FM_PROP_COMMAND));
619 sal_Int32 nType = ::comphelper::getINT32(xFormProps->getPropertyValue(FM_PROP_COMMANDTYPE));
620 if (aCursorSource.isEmpty() || ((nType == nCommandType) && (aCursorSource == _rCursorSource))) // found the form
622 xResultForm = rForm;
623 // Ist noch keine Datenquelle gesetzt, wird dieses hier nachgeholt
624 if (aCursorSource.isEmpty())
626 xFormProps->setPropertyValue(FM_PROP_COMMAND, makeAny(_rCursorSource));
627 xFormProps->setPropertyValue(FM_PROP_COMMANDTYPE, makeAny((sal_Int32)nCommandType));
632 // as long as xResultForm is NULL, search the child forms of rForm
633 Reference< XIndexAccess > xComponents(rForm, UNO_QUERY);
634 sal_Int32 nCount = xComponents->getCount();
635 for (sal_Int32 i = 0; !xResultForm.is() && i < nCount; ++i)
637 Reference< ::com::sun::star::form::XForm > xSearchForm;
638 xComponents->getByIndex(i) >>= xSearchForm;
639 // continue searching in the sub form
640 if (xSearchForm.is())
641 xResultForm = findFormForDataSource( xSearchForm, _rxDatabase, _rCursorSource, nCommandType );
643 return xResultForm;
646 //------------------------------------------------------------------------------
647 OUString FmFormPageImpl::setUniqueName(const Reference< XFormComponent > & xFormComponent, const Reference< XForm > & xControls)
649 #if OSL_DEBUG_LEVEL > 0
652 Reference< XChild > xChild( xFormComponent, UNO_QUERY_THROW );
653 OSL_ENSURE( !xChild->getParent().is(), "FmFormPageImpl::setUniqueName: to be called before insertion!" );
655 catch( const Exception& )
657 DBG_UNHANDLED_EXCEPTION();
659 #endif
660 OUString sName;
661 Reference< ::com::sun::star::beans::XPropertySet > xSet(xFormComponent, UNO_QUERY);
662 if (xSet.is())
664 sName = ::comphelper::getString( xSet->getPropertyValue( FM_PROP_NAME ) );
665 Reference< ::com::sun::star::container::XNameAccess > xNameAcc(xControls, UNO_QUERY);
667 if (sName.isEmpty() || xNameAcc->hasByName(sName))
669 // setzen eines default Namens ueber die ClassId
670 sal_Int16 nClassId( FormComponentType::CONTROL );
671 xSet->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId;
673 OUString sDefaultName = FormControlFactory::getDefaultUniqueName_ByComponentType(
674 Reference< XNameAccess >( xControls, UNO_QUERY ), xSet );
676 // bei Radiobuttons, die einen Namen haben, diesen nicht ueberschreiben!
677 if (sName.isEmpty() || nClassId != ::com::sun::star::form::FormComponentType::RADIOBUTTON)
679 xSet->setPropertyValue(FM_PROP_NAME, makeAny(sDefaultName));
682 sName = sDefaultName;
685 return sName;
688 //----------------------------------------------------------------------------------------------------------------------
689 void FmFormPageImpl::formModelAssigned( const FmFormObj& _object )
691 Reference< XMap > xControlShapeMap( m_aControlShapeMap.get(), UNO_QUERY );
692 if ( !xControlShapeMap.is() )
693 // our map does not exist -> not interested in this event
694 return;
698 lcl_removeFormObject_throw( _object, xControlShapeMap, false );
699 lcl_insertFormObject_throw( _object, xControlShapeMap );
701 catch( const Exception& )
703 DBG_UNHANDLED_EXCEPTION();
707 //----------------------------------------------------------------------------------------------------------------------
708 void FmFormPageImpl::formObjectInserted( const FmFormObj& _object )
710 Reference< XMap > xControlShapeMap( m_aControlShapeMap.get(), UNO_QUERY );
711 if ( !xControlShapeMap.is() )
712 // our map does not exist -> not interested in this event
713 return;
717 lcl_insertFormObject_throw( _object, xControlShapeMap );
719 catch( const Exception& )
721 DBG_UNHANDLED_EXCEPTION();
725 //----------------------------------------------------------------------------------------------------------------------
726 void FmFormPageImpl::formObjectRemoved( const FmFormObj& _object )
728 Reference< XMap > xControlShapeMap( m_aControlShapeMap.get(), UNO_QUERY );
729 if ( !xControlShapeMap.is() )
730 // our map does not exist -> not interested in this event
731 return;
735 lcl_removeFormObject_throw( _object, xControlShapeMap );
737 catch( const Exception& )
739 DBG_UNHANDLED_EXCEPTION();
743 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */