bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / form / fmpgeimp.cxx
blob463ad07e6b09a253d10972b19bcf2a9f5df5b236
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 "treevisitor.hxx"
33 #include <com/sun/star/sdb/CommandType.hpp>
34 #include <com/sun/star/util/XCloneable.hpp>
35 #include <com/sun/star/container/EnumerableMap.hpp>
36 #include <com/sun/star/drawing/XControlShape.hpp>
37 #include <com/sun/star/form/Forms.hpp>
39 #include <sfx2/objsh.hxx>
40 #include <svx/fmglob.hxx>
41 #include <svx/fmpage.hxx>
42 #include <svx/fmmodel.hxx>
43 #include <tools/resid.hxx>
44 #include <tools/diagnose_ex.h>
45 #include <vcl/stdtext.hxx>
46 #include <svx/dialmgr.hxx>
47 #include <comphelper/processfactory.hxx>
48 #include <comphelper/uno3.hxx>
49 #include <comphelper/types.hxx>
50 #include <unotools/streamwrap.hxx>
51 #include <connectivity/dbtools.hxx>
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::lang;
55 using namespace ::com::sun::star::sdbc;
56 using namespace ::com::sun::star::sdb;
57 using namespace ::com::sun::star::container;
58 using namespace ::com::sun::star::beans;
59 using namespace ::com::sun::star::form;
60 using ::com::sun::star::util::XCloneable;
61 using ::com::sun::star::awt::XControlModel;
62 using ::com::sun::star::container::XMap;
63 using ::com::sun::star::container::EnumerableMap;
64 using ::com::sun::star::drawing::XControlShape;
65 using namespace ::svxform;
66 using namespace ::dbtools;
69 FmFormPageImpl::FmFormPageImpl( FmFormPage& _rPage )
70 :m_rPage( _rPage )
71 ,m_bFirstActivation( true )
72 ,m_bAttemptedFormCreation( false )
73 ,m_bInFind( false )
78 namespace
80 class FormComponentInfo
82 public:
83 static size_t childCount( const Reference< XInterface >& _component )
85 Reference< XIndexAccess > xContainer( _component, UNO_QUERY );
86 if ( xContainer.is() )
87 return xContainer->getCount();
88 return 0;
91 static Reference< XInterface > getChild( const Reference< XInterface >& _component, size_t _index )
93 Reference< XIndexAccess > xContainer( _component, UNO_QUERY_THROW );
94 return Reference< XInterface >( xContainer->getByIndex( _index ), UNO_QUERY );
98 typedef ::std::pair< Reference< XInterface >, Reference< XInterface > > FormComponentPair;
100 class FormHierarchyComparator
102 public:
103 FormHierarchyComparator()
107 static size_t childCount( const FormComponentPair& _components )
109 size_t lhsCount = FormComponentInfo::childCount( _components.first );
110 size_t rhsCount = FormComponentInfo::childCount( _components.second );
111 if ( lhsCount != rhsCount )
112 throw RuntimeException( "Found inconsistent form component hierarchies (1)!" );
113 return lhsCount;
116 static FormComponentPair getChild( const FormComponentPair& _components, size_t _index )
118 return FormComponentPair(
119 FormComponentInfo::getChild( _components.first, _index ),
120 FormComponentInfo::getChild( _components.second, _index )
125 typedef ::std::map< Reference< XControlModel >, Reference< XControlModel >, ::comphelper::OInterfaceCompare< XControlModel > > MapControlModels;
127 class FormComponentAssignment
129 public:
130 FormComponentAssignment( MapControlModels& _out_controlModelMap )
131 :m_rControlModelMap( _out_controlModelMap )
135 void process( const FormComponentPair& _component )
137 Reference< XControlModel > lhsControlModel( _component.first, UNO_QUERY );
138 Reference< XControlModel > rhsControlModel( _component.second, UNO_QUERY );
139 if ( lhsControlModel.is() != rhsControlModel.is() )
140 throw RuntimeException( "Found inconsistent form component hierarchies (2)!" );
142 if ( lhsControlModel.is() )
143 m_rControlModelMap[ lhsControlModel ] = rhsControlModel;
146 private:
147 MapControlModels& m_rControlModelMap;
152 void FmFormPageImpl::initFrom( FmFormPageImpl& i_foreignImpl )
154 // clone the Forms collection
155 const Reference< css::form::XForms > xForeignForms( const_cast< FmFormPageImpl& >( i_foreignImpl ).getForms( false ) );
157 if ( !xForeignForms.is() )
158 return;
162 m_xForms.set( xForeignForms->createClone(), UNO_QUERY_THROW );
164 // create a mapping between the original control models and their clones
165 MapControlModels aModelAssignment;
167 typedef TreeVisitor< FormComponentPair, FormHierarchyComparator, FormComponentAssignment > FormComponentVisitor;
168 FormComponentVisitor aVisitor = FormComponentVisitor( FormHierarchyComparator() );
170 FormComponentAssignment aAssignmentProcessor( aModelAssignment );
171 aVisitor.process( FormComponentPair( xForeignForms, m_xForms ), aAssignmentProcessor );
173 // assign the cloned models to their SdrObjects
174 SdrObjListIter aForeignIter( i_foreignImpl.m_rPage );
175 SdrObjListIter aOwnIter( m_rPage );
177 OSL_ENSURE( aForeignIter.IsMore() == aOwnIter.IsMore(), "FmFormPageImpl::FmFormPageImpl: inconsistent number of objects (1)!" );
178 while ( aForeignIter.IsMore() && aOwnIter.IsMore() )
180 FmFormObj* pForeignObj = dynamic_cast< FmFormObj* >( aForeignIter.Next() );
181 FmFormObj* pOwnObj = dynamic_cast< FmFormObj* >( aOwnIter.Next() );
183 bool bForeignIsForm = pForeignObj && ( pForeignObj->GetObjInventor() == FmFormInventor );
184 bool bOwnIsForm = pOwnObj && ( pOwnObj->GetObjInventor() == FmFormInventor );
186 if ( bForeignIsForm != bOwnIsForm )
188 // if this fires, don't attempt to do further assignments, something's completely messed up
189 SAL_WARN( "svx.form", "FmFormPageImpl::FmFormPageImpl: inconsistent ordering of objects!" );
190 break;
193 if ( !bForeignIsForm )
194 // no form control -> next round
195 continue;
197 Reference< XControlModel > xForeignModel( pForeignObj->GetUnoControlModel() );
198 if ( !xForeignModel.is() )
200 // if this fires, the SdrObject does not have a UNO Control Model. This is pathological, but well ...
201 // So the cloned SdrObject will also not have a UNO Control Model.
202 SAL_WARN( "svx.form", "FmFormPageImpl::FmFormPageImpl: control shape without control!" );
203 continue;
206 MapControlModels::const_iterator assignment = aModelAssignment.find( xForeignModel );
207 if ( assignment == aModelAssignment.end() )
209 // if this fires, the source SdrObject has a model, but it is not part of the model hierarchy in
210 // i_foreignImpl.getForms().
211 // Pathological, too ...
212 SAL_WARN( "svx.form", "FmFormPageImpl::FmFormPageImpl: no clone found for this model!" );
213 continue;
216 pOwnObj->SetUnoControlModel( assignment->second );
218 OSL_ENSURE( aForeignIter.IsMore() == aOwnIter.IsMore(), "FmFormPageImpl::FmFormPageImpl: inconsistent number of objects (2)!" );
220 catch( const Exception& )
222 DBG_UNHANDLED_EXCEPTION();
227 Reference< XMap > FmFormPageImpl::getControlToShapeMap()
229 Reference< XMap > xControlShapeMap( m_aControlShapeMap.get(), UNO_QUERY );
230 if ( xControlShapeMap.is() )
231 return xControlShapeMap;
233 xControlShapeMap = impl_createControlShapeMap_nothrow();
234 m_aControlShapeMap = xControlShapeMap;
235 return xControlShapeMap;
239 namespace
241 static void lcl_insertFormObject_throw( const FmFormObj& _object, const Reference< XMap >& _map )
243 // the control model
244 Reference< XControlModel > xControlModel( _object.GetUnoControlModel(), UNO_QUERY );
245 OSL_ENSURE( xControlModel.is(), "lcl_insertFormObject_throw: suspicious: no control model!" );
246 if ( !xControlModel.is() )
247 return;
249 Reference< XControlShape > xControlShape( const_cast< FmFormObj& >( _object ).getUnoShape(), UNO_QUERY );
250 OSL_ENSURE( xControlShape.is(), "lcl_insertFormObject_throw: suspicious: no control shape!" );
251 if ( !xControlShape.is() )
252 return;
254 _map->put( makeAny( xControlModel ), makeAny( xControlShape ) );
257 static void lcl_removeFormObject_throw( const FmFormObj& _object, const Reference< XMap >& _map, bool i_ignoreNonExistence = false )
259 // the control model
260 Reference< XControlModel > xControlModel( _object.GetUnoControlModel(), UNO_QUERY );
261 OSL_ENSURE( xControlModel.is(), "lcl_removeFormObject: suspicious: no control model!" );
262 if ( !xControlModel.is() )
264 return;
267 #if OSL_DEBUG_LEVEL > 0
268 Any aOldAssignment =
269 #endif
270 _map->remove( makeAny( xControlModel ) );
271 #if OSL_DEBUG_LEVEL > 0
272 (void)aOldAssignment;
273 #endif
274 OSL_ENSURE( !i_ignoreNonExistence ||
275 ( aOldAssignment == makeAny( Reference< XControlShape >( const_cast< FmFormObj& >( _object ).getUnoShape(), UNO_QUERY ) ) ),
276 "lcl_removeFormObject: map was inconsistent!" );
277 (void)i_ignoreNonExistence;
282 Reference< XMap > FmFormPageImpl::impl_createControlShapeMap_nothrow()
284 Reference< XMap > xMap;
288 xMap.set( EnumerableMap::create( comphelper::getProcessComponentContext(),
289 ::cppu::UnoType< XControlModel >::get(),
290 ::cppu::UnoType< XControlShape >::get()
291 ).get(), UNO_SET_THROW );
293 SdrObjListIter aPageIter( m_rPage );
294 while ( aPageIter.IsMore() )
296 // only FmFormObjs are what we're interested in
297 FmFormObj* pCurrent = FmFormObj::GetFormObject( aPageIter.Next() );
298 if ( !pCurrent )
299 continue;
301 lcl_insertFormObject_throw( *pCurrent, xMap );
304 catch( const Exception& )
306 DBG_UNHANDLED_EXCEPTION();
308 return xMap;
312 const Reference< css::form::XForms >& FmFormPageImpl::getForms( bool _bForceCreate )
314 if ( m_xForms.is() || !_bForceCreate )
315 return m_xForms;
317 if ( !m_bAttemptedFormCreation )
319 m_bAttemptedFormCreation = true;
321 Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
322 m_xForms = css::form::Forms::create( xContext );
324 if ( m_aFormsCreationHdl.IsSet() )
326 m_aFormsCreationHdl.Call( this );
329 FmFormModel* pFormsModel = PTR_CAST( FmFormModel, m_rPage.GetModel() );
331 // give the newly created collection a place in the universe
332 SfxObjectShell* pObjShell = pFormsModel ? pFormsModel->GetObjectShell() : NULL;
333 if ( pObjShell )
334 m_xForms->setParent( pObjShell->GetModel() );
336 // tell the UNDO environment that we have a new forms collection
337 if ( pFormsModel )
338 pFormsModel->GetUndoEnv().AddForms( Reference<XNameContainer>(m_xForms,UNO_QUERY_THROW) );
340 return m_xForms;
344 FmFormPageImpl::~FmFormPageImpl()
346 xCurrentForm = NULL;
348 ::comphelper::disposeComponent( m_xForms );
352 bool FmFormPageImpl::validateCurForm()
354 if ( !xCurrentForm.is() )
355 return false;
357 Reference< XChild > xAsChild( xCurrentForm, UNO_QUERY );
358 DBG_ASSERT( xAsChild.is(), "FmFormPageImpl::validateCurForm: a form which is no child??" );
359 if ( !xAsChild.is() || !xAsChild->getParent().is() )
360 xCurrentForm.clear();
362 return xCurrentForm.is();
366 void FmFormPageImpl::setCurForm(Reference< ::com::sun::star::form::XForm > xForm)
368 xCurrentForm = xForm;
372 Reference< XForm > FmFormPageImpl::getDefaultForm()
374 Reference< XForm > xForm;
376 Reference< XForms > xForms( getForms() );
378 // by default, we use our "current form"
379 if ( !validateCurForm() )
381 // check whether there is a "standard" form
382 if ( Reference<XNameAccess>(xForms,UNO_QUERY_THROW)->hasElements() )
384 // suche die Standardform
385 OUString sStandardFormname = SVX_RESSTR(RID_STR_STDFORMNAME);
389 if ( xForms->hasByName( sStandardFormname ) )
390 xForm.set( xForms->getByName( sStandardFormname ), UNO_QUERY_THROW );
391 else
393 xForm.set( xForms->getByIndex(0), UNO_QUERY_THROW );
396 catch( const Exception& )
398 DBG_UNHANDLED_EXCEPTION();
402 else
404 xForm = xCurrentForm;
407 // did not find an existing suitable form -> create a new one
408 if ( !xForm.is() )
410 SdrModel* pModel = m_rPage.GetModel();
412 if( pModel->IsUndoEnabled() )
414 OUString aStr(SVX_RESSTR(RID_STR_FORM));
415 OUString aUndoStr(SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT));
416 pModel->BegUndo(aUndoStr.replaceFirst("'#'", aStr));
421 xForm.set( ::comphelper::getProcessServiceFactory()->createInstance( FM_SUN_COMPONENT_FORM ), UNO_QUERY );
423 // a form should always have the command type table as default
424 Reference< XPropertySet > xFormProps( xForm, UNO_QUERY_THROW );
425 xFormProps->setPropertyValue( FM_PROP_COMMANDTYPE, makeAny( sal_Int32( CommandType::TABLE ) ) );
427 // and the "Standard" name
428 OUString sName = SVX_RESSTR(RID_STR_STDFORMNAME);
429 xFormProps->setPropertyValue( FM_PROP_NAME, makeAny( sName ) );
431 if( pModel->IsUndoEnabled() )
433 pModel->AddUndo(new FmUndoContainerAction(*static_cast<FmFormModel*>(pModel),
434 FmUndoContainerAction::Inserted,
435 xForms,
436 xForm,
437 xForms->getCount()));
439 xForms->insertByName( sName, makeAny( xForm ) );
440 xCurrentForm = xForm;
442 catch( const Exception& )
444 DBG_UNHANDLED_EXCEPTION();
445 xForm.clear();
448 if( pModel->IsUndoEnabled() )
449 pModel->EndUndo();
452 return xForm;
456 Reference< ::com::sun::star::form::XForm > FmFormPageImpl::findPlaceInFormComponentHierarchy(
457 const Reference< XFormComponent > & rContent, const Reference< XDataSource > & rDatabase,
458 const OUString& rDBTitle, const OUString& rCursorSource, sal_Int32 nCommandType )
460 // if the control already is child of a form, don't do anything
461 if (!rContent.is() || rContent->getParent().is())
462 return NULL;
464 Reference< XForm > xForm;
466 // Wenn Datenbank und CursorSource gesetzt sind, dann wird
467 // die Form anhand dieser Kriterien gesucht, ansonsten nur aktuelle
468 // und die StandardForm
469 if (rDatabase.is() && !rCursorSource.isEmpty())
471 validateCurForm();
473 // erst in der aktuellen form suchen
474 xForm = findFormForDataSource( xCurrentForm, rDatabase, rCursorSource, nCommandType );
476 Reference< ::com::sun::star::container::XIndexAccess > xFormsByIndex( getForms(), UNO_QUERY );
477 DBG_ASSERT(xFormsByIndex.is(), "FmFormPageImpl::findPlaceInFormComponentHierarchy : no index access for my forms collection !");
478 sal_Int32 nCount = xFormsByIndex->getCount();
479 for (sal_Int32 i = 0; !xForm.is() && i < nCount; i++)
481 Reference< ::com::sun::star::form::XForm > xToSearch;
482 xFormsByIndex->getByIndex(i) >>= xToSearch;
483 xForm = findFormForDataSource( xToSearch, rDatabase, rCursorSource, nCommandType );
486 // wenn keine ::com::sun::star::form gefunden, dann eine neue erzeugen
487 if (!xForm.is())
489 SdrModel* pModel = m_rPage.GetModel();
491 const bool bUndo = pModel->IsUndoEnabled();
493 if( bUndo )
495 OUString aStr(SVX_RESSTR(RID_STR_FORM));
496 OUString aUndoStr(SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT));
497 aUndoStr = aUndoStr.replaceFirst("#", aStr);
498 pModel->BegUndo(aUndoStr);
501 xForm = Reference< ::com::sun::star::form::XForm >(::comphelper::getProcessServiceFactory()->createInstance(FM_SUN_COMPONENT_FORM), UNO_QUERY);
502 // a form should always have the command type table as default
503 Reference< ::com::sun::star::beans::XPropertySet > xFormProps(xForm, UNO_QUERY);
504 try { xFormProps->setPropertyValue(FM_PROP_COMMANDTYPE, makeAny(sal_Int32(CommandType::TABLE))); }
505 catch(Exception&) { }
507 if (!rDBTitle.isEmpty())
508 xFormProps->setPropertyValue(FM_PROP_DATASOURCE,makeAny(rDBTitle));
509 else
511 Reference< ::com::sun::star::beans::XPropertySet > xDatabaseProps(rDatabase, UNO_QUERY);
512 Any aDatabaseUrl = xDatabaseProps->getPropertyValue(FM_PROP_URL);
513 xFormProps->setPropertyValue(FM_PROP_URL, aDatabaseUrl);
516 xFormProps->setPropertyValue(FM_PROP_COMMAND,makeAny(rCursorSource));
517 xFormProps->setPropertyValue(FM_PROP_COMMANDTYPE, makeAny(nCommandType));
519 Reference< ::com::sun::star::container::XNameAccess > xNamedSet( getForms(), UNO_QUERY );
521 const bool bTableOrQuery = ( CommandType::TABLE == nCommandType ) || ( CommandType::QUERY == nCommandType );
522 OUString sName = FormControlFactory::getUniqueName( xNamedSet,
523 bTableOrQuery ? rCursorSource : SVX_RESSTR(RID_STR_STDFORMNAME) );
525 xFormProps->setPropertyValue( FM_PROP_NAME, makeAny( sName ) );
527 if( bUndo )
529 Reference< ::com::sun::star::container::XIndexContainer > xContainer( getForms(), UNO_QUERY );
530 pModel->AddUndo(new FmUndoContainerAction(*static_cast<FmFormModel*>(pModel),
531 FmUndoContainerAction::Inserted,
532 xContainer,
533 xForm,
534 xContainer->getCount()));
537 getForms()->insertByName( sName, makeAny( xForm ) );
539 if( bUndo )
540 pModel->EndUndo();
542 xCurrentForm = xForm;
545 xForm = getDefaultForm();
546 return xForm;
550 Reference< XForm > FmFormPageImpl::findFormForDataSource(
551 const Reference< XForm > & rForm, const Reference< XDataSource > & _rxDatabase,
552 const OUString& _rCursorSource, sal_Int32 nCommandType)
554 Reference< XForm > xResultForm;
555 Reference< XRowSet > xDBForm(rForm, UNO_QUERY);
556 Reference< XPropertySet > xFormProps(rForm, UNO_QUERY);
557 if (!xDBForm.is() || !xFormProps.is())
558 return xResultForm;
560 OSL_ENSURE(_rxDatabase.is(), "FmFormPageImpl::findFormForDataSource: invalid data source!");
561 OUString sLookupName; // the name of the data source we're looking for
562 OUString sFormDataSourceName; // the name of the data source the current connection in the form is based on
565 Reference< XPropertySet > xDSProps(_rxDatabase, UNO_QUERY);
566 if (xDSProps.is())
567 xDSProps->getPropertyValue(FM_PROP_NAME) >>= sLookupName;
569 xFormProps->getPropertyValue(FM_PROP_DATASOURCE) >>= sFormDataSourceName;
570 // if there's no DataSourceName set at the form, check whether we can deduce one from its
571 // ActiveConnection
572 if (sFormDataSourceName.isEmpty())
574 Reference< XConnection > xFormConnection;
575 xFormProps->getPropertyValue( FM_PROP_ACTIVE_CONNECTION ) >>= xFormConnection;
576 if ( !xFormConnection.is() )
577 isEmbeddedInDatabase( xFormProps, xFormConnection );
578 if (xFormConnection.is())
580 Reference< XChild > xConnAsChild(xFormConnection, UNO_QUERY);
581 if (xConnAsChild.is())
583 Reference< XDataSource > xFormDS(xConnAsChild->getParent(), UNO_QUERY);
584 if (xFormDS.is())
586 xDSProps.set(xFormDS, css::uno::UNO_QUERY);
587 if (xDSProps.is())
588 xDSProps->getPropertyValue(FM_PROP_NAME) >>= sFormDataSourceName;
594 catch(const Exception& e)
596 (void)e;
597 OSL_FAIL("FmFormPageImpl::findFormForDataSource: caught an exception!");
600 if (sLookupName == sFormDataSourceName)
602 // jetzt noch ueberpruefen ob CursorSource und Type uebereinstimmen
603 OUString aCursorSource = ::comphelper::getString(xFormProps->getPropertyValue(FM_PROP_COMMAND));
604 sal_Int32 nType = ::comphelper::getINT32(xFormProps->getPropertyValue(FM_PROP_COMMANDTYPE));
605 if (aCursorSource.isEmpty() || ((nType == nCommandType) && (aCursorSource == _rCursorSource))) // found the form
607 xResultForm = rForm;
608 // Ist noch keine Datenquelle gesetzt, wird dieses hier nachgeholt
609 if (aCursorSource.isEmpty())
611 xFormProps->setPropertyValue(FM_PROP_COMMAND, makeAny(_rCursorSource));
612 xFormProps->setPropertyValue(FM_PROP_COMMANDTYPE, makeAny((sal_Int32)nCommandType));
617 // as long as xResultForm is NULL, search the child forms of rForm
618 Reference< XIndexAccess > xComponents(rForm, UNO_QUERY);
619 sal_Int32 nCount = xComponents->getCount();
620 for (sal_Int32 i = 0; !xResultForm.is() && i < nCount; ++i)
622 Reference< ::com::sun::star::form::XForm > xSearchForm;
623 xComponents->getByIndex(i) >>= xSearchForm;
624 // continue searching in the sub form
625 if (xSearchForm.is())
626 xResultForm = findFormForDataSource( xSearchForm, _rxDatabase, _rCursorSource, nCommandType );
628 return xResultForm;
632 OUString FmFormPageImpl::setUniqueName(const Reference< XFormComponent > & xFormComponent, const Reference< XForm > & xControls)
634 #if OSL_DEBUG_LEVEL > 0
637 OSL_ENSURE( !xFormComponent->getParent().is(), "FmFormPageImpl::setUniqueName: to be called before insertion!" );
639 catch( const Exception& )
641 DBG_UNHANDLED_EXCEPTION();
643 #endif
644 OUString sName;
645 Reference< ::com::sun::star::beans::XPropertySet > xSet(xFormComponent, UNO_QUERY);
646 if (xSet.is())
648 sName = ::comphelper::getString( xSet->getPropertyValue( FM_PROP_NAME ) );
649 Reference< ::com::sun::star::container::XNameAccess > xNameAcc(xControls, UNO_QUERY);
651 if (sName.isEmpty() || xNameAcc->hasByName(sName))
653 // setzen eines default Namens ueber die ClassId
654 sal_Int16 nClassId( FormComponentType::CONTROL );
655 xSet->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId;
657 OUString sDefaultName = FormControlFactory::getDefaultUniqueName_ByComponentType(
658 Reference< XNameAccess >( xControls, UNO_QUERY ), xSet );
660 // bei Radiobuttons, die einen Namen haben, diesen nicht ueberschreiben!
661 if (sName.isEmpty() || nClassId != ::com::sun::star::form::FormComponentType::RADIOBUTTON)
663 xSet->setPropertyValue(FM_PROP_NAME, makeAny(sDefaultName));
666 sName = sDefaultName;
669 return sName;
673 void FmFormPageImpl::formModelAssigned( const FmFormObj& _object )
675 Reference< XMap > xControlShapeMap( m_aControlShapeMap.get(), UNO_QUERY );
676 if ( !xControlShapeMap.is() )
677 // our map does not exist -> not interested in this event
678 return;
682 lcl_removeFormObject_throw( _object, xControlShapeMap, false );
683 lcl_insertFormObject_throw( _object, xControlShapeMap );
685 catch( const Exception& )
687 DBG_UNHANDLED_EXCEPTION();
692 void FmFormPageImpl::formObjectInserted( const FmFormObj& _object )
694 Reference< XMap > xControlShapeMap( m_aControlShapeMap.get(), UNO_QUERY );
695 if ( !xControlShapeMap.is() )
696 // our map does not exist -> not interested in this event
697 return;
701 lcl_insertFormObject_throw( _object, xControlShapeMap );
703 catch( const Exception& )
705 DBG_UNHANDLED_EXCEPTION();
710 void FmFormPageImpl::formObjectRemoved( const FmFormObj& _object )
712 Reference< XMap > xControlShapeMap( m_aControlShapeMap.get(), UNO_QUERY );
713 if ( !xControlShapeMap.is() )
714 // our map does not exist -> not interested in this event
715 return;
719 lcl_removeFormObject_throw( _object, xControlShapeMap );
721 catch( const Exception& )
723 DBG_UNHANDLED_EXCEPTION();
727 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */