1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
24 #include "svx/fmtools.hxx"
26 #include "fmservs.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>
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::lang
;
56 using namespace ::com::sun::star::sdbc
;
57 using namespace ::com::sun::star::sdb
;
58 using namespace ::com::sun::star::container
;
59 using namespace ::com::sun::star::beans
;
60 using namespace ::com::sun::star::form
;
61 using ::com::sun::star::util::XCloneable
;
62 using ::com::sun::star::awt::XControlModel
;
63 using ::com::sun::star::container::XMap
;
64 using ::com::sun::star::container::EnumerableMap
;
65 using ::com::sun::star::drawing::XControlShape
;
66 using namespace ::svxform
;
69 FmFormPageImpl::FmFormPageImpl( FmFormPage
& _rPage
)
71 ,m_bFirstActivation( true )
72 ,m_bAttemptedFormCreation( false )
80 typedef Reference
< XInterface
> FormComponent
;
82 class FormComponentInfo
85 size_t childCount( const FormComponent
& _component
) const
87 Reference
< XIndexAccess
> xContainer( _component
, UNO_QUERY
);
88 if ( xContainer
.is() )
89 return xContainer
->getCount();
93 FormComponent
getChild( const FormComponent
& _component
, size_t _index
) const
95 Reference
< XIndexAccess
> xContainer( _component
, UNO_QUERY_THROW
);
96 return FormComponent( xContainer
->getByIndex( _index
), UNO_QUERY
);
100 typedef ::std::pair
< FormComponent
, FormComponent
> FormComponentPair
;
102 class FormHierarchyComparator
105 FormHierarchyComparator()
109 size_t childCount( const FormComponentPair
& _components
) const
111 size_t lhsCount
= m_aComponentInfo
.childCount( _components
.first
);
112 size_t rhsCount
= m_aComponentInfo
.childCount( _components
.second
);
113 if ( lhsCount
!= rhsCount
)
114 throw RuntimeException( OUString( "Found inconsistent form component hierarchies (1)!" ), NULL
);
118 FormComponentPair
getChild( const FormComponentPair
& _components
, size_t _index
) const
120 return FormComponentPair(
121 m_aComponentInfo
.getChild( _components
.first
, _index
),
122 m_aComponentInfo
.getChild( _components
.second
, _index
)
126 FormComponentInfo m_aComponentInfo
;
129 typedef ::std::map
< Reference
< XControlModel
>, Reference
< XControlModel
>, ::comphelper::OInterfaceCompare
< XControlModel
> > MapControlModels
;
131 class FormComponentAssignment
134 FormComponentAssignment( MapControlModels
& _out_controlModelMap
)
135 :m_rControlModelMap( _out_controlModelMap
)
139 void process( const FormComponentPair
& _component
)
141 Reference
< XControlModel
> lhsControlModel( _component
.first
, UNO_QUERY
);
142 Reference
< XControlModel
> rhsControlModel( _component
.second
, UNO_QUERY
);
143 if ( lhsControlModel
.is() != rhsControlModel
.is() )
144 throw RuntimeException( OUString( "Found inconsistent form component hierarchies (2)!" ), NULL
);
146 if ( lhsControlModel
.is() )
147 m_rControlModelMap
[ lhsControlModel
] = rhsControlModel
;
151 MapControlModels
& m_rControlModelMap
;
156 void FmFormPageImpl::initFrom( FmFormPageImpl
& i_foreignImpl
)
158 // clone the Forms collection
159 const Reference
< css::form::XForms
> xForeignForms( const_cast< FmFormPageImpl
& >( i_foreignImpl
).getForms( false ) );
161 if ( !xForeignForms
.is() )
166 m_xForms
.set( xForeignForms
->createClone(), UNO_QUERY_THROW
);
168 // create a mapping between the original control models and their clones
169 MapControlModels aModelAssignment
;
171 typedef TreeVisitor
< FormComponentPair
, FormHierarchyComparator
, FormComponentAssignment
> FormComponentVisitor
;
172 FormComponentVisitor aVisitor
= FormComponentVisitor( FormHierarchyComparator() );
174 FormComponentAssignment
aAssignmentProcessor( aModelAssignment
);
175 aVisitor
.process( FormComponentPair( xForeignForms
, m_xForms
), aAssignmentProcessor
);
177 // assign the cloned models to their SdrObjects
178 SdrObjListIter
aForeignIter( i_foreignImpl
.m_rPage
);
179 SdrObjListIter
aOwnIter( m_rPage
);
181 OSL_ENSURE( aForeignIter
.IsMore() == aOwnIter
.IsMore(), "FmFormPageImpl::FmFormPageImpl: inconsistent number of objects (1)!" );
182 while ( aForeignIter
.IsMore() && aOwnIter
.IsMore() )
184 FmFormObj
* pForeignObj
= dynamic_cast< FmFormObj
* >( aForeignIter
.Next() );
185 FmFormObj
* pOwnObj
= dynamic_cast< FmFormObj
* >( aOwnIter
.Next() );
187 bool bForeignIsForm
= pForeignObj
&& ( pForeignObj
->GetObjInventor() == FmFormInventor
);
188 bool bOwnIsForm
= pOwnObj
&& ( pOwnObj
->GetObjInventor() == FmFormInventor
);
190 if ( bForeignIsForm
!= bOwnIsForm
)
192 // if this fires, don't attempt to do further assignments, something's completely messed up
193 SAL_WARN( "svx.form", "FmFormPageImpl::FmFormPageImpl: inconsistent ordering of objects!" );
197 if ( !bForeignIsForm
)
198 // no form control -> next round
201 Reference
< XControlModel
> xForeignModel( pForeignObj
->GetUnoControlModel() );
202 if ( !xForeignModel
.is() )
204 // if this fires, the SdrObject does not have a UNO Control Model. This is pathological, but well ...
205 // So the cloned SdrObject will also not have a UNO Control Model.
206 SAL_WARN( "svx.form", "FmFormPageImpl::FmFormPageImpl: control shape without control!" );
210 MapControlModels::const_iterator assignment
= aModelAssignment
.find( xForeignModel
);
211 if ( assignment
== aModelAssignment
.end() )
213 // if this fires, the source SdrObject has a model, but it is not part of the model hierarchy in
214 // i_foreignImpl.getForms().
215 // Pathological, too ...
216 SAL_WARN( "svx.form", "FmFormPageImpl::FmFormPageImpl: no clone found for this model!" );
220 pOwnObj
->SetUnoControlModel( assignment
->second
);
222 OSL_ENSURE( aForeignIter
.IsMore() == aOwnIter
.IsMore(), "FmFormPageImpl::FmFormPageImpl: inconsistent number of objects (2)!" );
224 catch( const Exception
& )
226 DBG_UNHANDLED_EXCEPTION();
231 Reference
< XMap
> FmFormPageImpl::getControlToShapeMap()
233 Reference
< XMap
> xControlShapeMap( m_aControlShapeMap
.get(), UNO_QUERY
);
234 if ( xControlShapeMap
.is() )
235 return xControlShapeMap
;
237 xControlShapeMap
= impl_createControlShapeMap_nothrow();
238 m_aControlShapeMap
= xControlShapeMap
;
239 return xControlShapeMap
;
245 static void lcl_insertFormObject_throw( const FmFormObj
& _object
, const Reference
< XMap
>& _map
)
248 Reference
< XControlModel
> xControlModel( _object
.GetUnoControlModel(), UNO_QUERY
);
249 OSL_ENSURE( xControlModel
.is(), "lcl_insertFormObject_throw: suspicious: no control model!" );
250 if ( !xControlModel
.is() )
253 Reference
< XControlShape
> xControlShape( const_cast< FmFormObj
& >( _object
).getUnoShape(), UNO_QUERY
);
254 OSL_ENSURE( xControlShape
.is(), "lcl_insertFormObject_throw: suspicious: no control shape!" );
255 if ( !xControlShape
.is() )
258 _map
->put( makeAny( xControlModel
), makeAny( xControlShape
) );
261 static void lcl_removeFormObject_throw( const FmFormObj
& _object
, const Reference
< XMap
>& _map
, bool i_ignoreNonExistence
= false )
264 Reference
< XControlModel
> xControlModel( _object
.GetUnoControlModel(), UNO_QUERY
);
265 OSL_ENSURE( xControlModel
.is(), "lcl_removeFormObject: suspicious: no control model!" );
266 if ( !xControlModel
.is() )
271 #if OSL_DEBUG_LEVEL > 0
274 _map
->remove( makeAny( xControlModel
) );
275 #if OSL_DEBUG_LEVEL > 0
276 (void)aOldAssignment
;
278 OSL_ENSURE( !i_ignoreNonExistence
||
279 ( aOldAssignment
== makeAny( Reference
< XControlShape
>( const_cast< FmFormObj
& >( _object
).getUnoShape(), UNO_QUERY
) ) ),
280 "lcl_removeFormObject: map was inconsistent!" );
281 (void)i_ignoreNonExistence
;
286 Reference
< XMap
> FmFormPageImpl::impl_createControlShapeMap_nothrow()
288 Reference
< XMap
> xMap
;
292 xMap
.set( EnumerableMap::create( comphelper::getProcessComponentContext(),
293 ::cppu::UnoType
< XControlModel
>::get(),
294 ::cppu::UnoType
< XControlShape
>::get()
295 ).get(), UNO_SET_THROW
);
297 SdrObjListIter
aPageIter( m_rPage
);
298 while ( aPageIter
.IsMore() )
300 // only FmFormObjs are what we're interested in
301 FmFormObj
* pCurrent
= FmFormObj::GetFormObject( aPageIter
.Next() );
305 lcl_insertFormObject_throw( *pCurrent
, xMap
);
308 catch( const Exception
& )
310 DBG_UNHANDLED_EXCEPTION();
316 const Reference
< css::form::XForms
>& FmFormPageImpl::getForms( bool _bForceCreate
)
318 if ( m_xForms
.is() || !_bForceCreate
)
321 if ( !m_bAttemptedFormCreation
)
323 m_bAttemptedFormCreation
= true;
325 Reference
<XComponentContext
> xContext
= comphelper::getProcessComponentContext();
326 m_xForms
= css::form::Forms::create( xContext
);
328 if ( m_aFormsCreationHdl
.IsSet() )
330 m_aFormsCreationHdl
.Call( this );
333 FmFormModel
* pFormsModel
= PTR_CAST( FmFormModel
, m_rPage
.GetModel() );
335 // give the newly created collection a place in the universe
336 SfxObjectShell
* pObjShell
= pFormsModel
? pFormsModel
->GetObjectShell() : NULL
;
338 m_xForms
->setParent( pObjShell
->GetModel() );
340 // tell the UNDO environment that we have a new forms collection
342 pFormsModel
->GetUndoEnv().AddForms( Reference
<XNameContainer
>(m_xForms
,UNO_QUERY_THROW
) );
348 FmFormPageImpl::~FmFormPageImpl()
352 ::comphelper::disposeComponent( m_xForms
);
356 bool FmFormPageImpl::validateCurForm()
358 if ( !xCurrentForm
.is() )
361 Reference
< XChild
> xAsChild( xCurrentForm
, UNO_QUERY
);
362 DBG_ASSERT( xAsChild
.is(), "FmFormPageImpl::validateCurForm: a form which is no child??" );
363 if ( !xAsChild
.is() || !xAsChild
->getParent().is() )
364 xCurrentForm
.clear();
366 return xCurrentForm
.is();
370 void FmFormPageImpl::setCurForm(Reference
< ::com::sun::star::form::XForm
> xForm
)
372 xCurrentForm
= xForm
;
376 Reference
< XForm
> FmFormPageImpl::getDefaultForm()
378 Reference
< XForm
> xForm
;
380 Reference
< XForms
> xForms( getForms() );
382 // by default, we use our "current form"
383 if ( !validateCurForm() )
385 // check whether there is a "standard" form
386 if ( Reference
<XNameAccess
>(xForms
,UNO_QUERY_THROW
)->hasElements() )
388 // suche die Standardform
389 OUString sStandardFormname
= SVX_RESSTR(RID_STR_STDFORMNAME
);
393 if ( xForms
->hasByName( sStandardFormname
) )
394 xForm
.set( xForms
->getByName( sStandardFormname
), UNO_QUERY_THROW
);
397 xForm
.set( xForms
->getByIndex(0), UNO_QUERY_THROW
);
400 catch( const Exception
& )
402 DBG_UNHANDLED_EXCEPTION();
408 xForm
= xCurrentForm
;
411 // did not find an existing suitable form -> create a new one
414 SdrModel
* pModel
= m_rPage
.GetModel();
416 if( pModel
->IsUndoEnabled() )
418 OUString
aStr(SVX_RESSTR(RID_STR_FORM
));
419 OUString
aUndoStr(SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT
));
420 pModel
->BegUndo(aUndoStr
.replaceFirst("'#'", aStr
));
425 xForm
.set( ::comphelper::getProcessServiceFactory()->createInstance( FM_SUN_COMPONENT_FORM
), UNO_QUERY
);
427 // a form should always have the command type table as default
428 Reference
< XPropertySet
> xFormProps( xForm
, UNO_QUERY_THROW
);
429 xFormProps
->setPropertyValue( FM_PROP_COMMANDTYPE
, makeAny( sal_Int32( CommandType::TABLE
) ) );
431 // and the "Standard" name
432 OUString sName
= SVX_RESSTR(RID_STR_STDFORMNAME
);
433 xFormProps
->setPropertyValue( FM_PROP_NAME
, makeAny( sName
) );
435 if( pModel
->IsUndoEnabled() )
437 pModel
->AddUndo(new FmUndoContainerAction(*(FmFormModel
*)pModel
,
438 FmUndoContainerAction::Inserted
,
441 xForms
->getCount()));
443 xForms
->insertByName( sName
, makeAny( xForm
) );
444 xCurrentForm
= xForm
;
446 catch( const Exception
& )
448 DBG_UNHANDLED_EXCEPTION();
452 if( pModel
->IsUndoEnabled() )
460 Reference
< ::com::sun::star::form::XForm
> FmFormPageImpl::findPlaceInFormComponentHierarchy(
461 const Reference
< XFormComponent
> & rContent
, const Reference
< XDataSource
> & rDatabase
,
462 const OUString
& rDBTitle
, const OUString
& rCursorSource
, sal_Int32 nCommandType
)
464 // if the control already is child of a form, don't do anything
465 if (!rContent
.is() || rContent
->getParent().is())
468 Reference
< XForm
> xForm
;
470 // Wenn Datenbank und CursorSource gesetzt sind, dann wird
471 // die Form anhand dieser Kriterien gesucht, ansonsten nur aktuelle
472 // und die StandardForm
473 if (rDatabase
.is() && !rCursorSource
.isEmpty())
477 // erst in der aktuellen form suchen
478 xForm
= findFormForDataSource( xCurrentForm
, rDatabase
, rCursorSource
, nCommandType
);
480 Reference
< ::com::sun::star::container::XIndexAccess
> xFormsByIndex( getForms(), UNO_QUERY
);
481 DBG_ASSERT(xFormsByIndex
.is(), "FmFormPageImpl::findPlaceInFormComponentHierarchy : no index access for my forms collection !");
482 sal_Int32 nCount
= xFormsByIndex
->getCount();
483 for (sal_Int32 i
= 0; !xForm
.is() && i
< nCount
; i
++)
485 Reference
< ::com::sun::star::form::XForm
> xToSearch
;
486 xFormsByIndex
->getByIndex(i
) >>= xToSearch
;
487 xForm
= findFormForDataSource( xToSearch
, rDatabase
, rCursorSource
, nCommandType
);
490 // wenn keine ::com::sun::star::form gefunden, dann eine neue erzeugen
493 SdrModel
* pModel
= m_rPage
.GetModel();
495 const bool bUndo
= pModel
->IsUndoEnabled();
499 OUString
aStr(SVX_RESSTR(RID_STR_FORM
));
500 OUString
aUndoStr(SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT
));
501 aUndoStr
= aUndoStr
.replaceFirst("#", aStr
);
502 pModel
->BegUndo(aUndoStr
);
505 xForm
= Reference
< ::com::sun::star::form::XForm
>(::comphelper::getProcessServiceFactory()->createInstance(FM_SUN_COMPONENT_FORM
), UNO_QUERY
);
506 // a form should always have the command type table as default
507 Reference
< ::com::sun::star::beans::XPropertySet
> xFormProps(xForm
, UNO_QUERY
);
508 try { xFormProps
->setPropertyValue(FM_PROP_COMMANDTYPE
, makeAny(sal_Int32(CommandType::TABLE
))); }
509 catch(Exception
&) { }
511 if (!rDBTitle
.isEmpty())
512 xFormProps
->setPropertyValue(FM_PROP_DATASOURCE
,makeAny(rDBTitle
));
515 Reference
< ::com::sun::star::beans::XPropertySet
> xDatabaseProps(rDatabase
, UNO_QUERY
);
516 Any aDatabaseUrl
= xDatabaseProps
->getPropertyValue(FM_PROP_URL
);
517 xFormProps
->setPropertyValue(FM_PROP_DATASOURCE
, aDatabaseUrl
);
520 xFormProps
->setPropertyValue(FM_PROP_COMMAND
,makeAny(rCursorSource
));
521 xFormProps
->setPropertyValue(FM_PROP_COMMANDTYPE
, makeAny(nCommandType
));
523 Reference
< ::com::sun::star::container::XNameAccess
> xNamedSet( getForms(), UNO_QUERY
);
525 const bool bTableOrQuery
= ( CommandType::TABLE
== nCommandType
) || ( CommandType::QUERY
== nCommandType
);
526 OUString sName
= FormControlFactory::getUniqueName( xNamedSet
,
527 bTableOrQuery
? rCursorSource
: SVX_RESSTR(RID_STR_STDFORMNAME
) );
529 xFormProps
->setPropertyValue( FM_PROP_NAME
, makeAny( sName
) );
533 Reference
< ::com::sun::star::container::XIndexContainer
> xContainer( getForms(), UNO_QUERY
);
534 pModel
->AddUndo(new FmUndoContainerAction(*(FmFormModel
*)pModel
,
535 FmUndoContainerAction::Inserted
,
538 xContainer
->getCount()));
541 getForms()->insertByName( sName
, makeAny( xForm
) );
546 xCurrentForm
= xForm
;
549 xForm
= getDefaultForm();
554 Reference
< XForm
> FmFormPageImpl::findFormForDataSource(
555 const Reference
< XForm
> & rForm
, const Reference
< XDataSource
> & _rxDatabase
,
556 const OUString
& _rCursorSource
, sal_Int32 nCommandType
)
558 Reference
< XForm
> xResultForm
;
559 Reference
< XRowSet
> xDBForm(rForm
, UNO_QUERY
);
560 Reference
< XPropertySet
> xFormProps(rForm
, UNO_QUERY
);
561 if (!xDBForm
.is() || !xFormProps
.is())
564 OSL_ENSURE(_rxDatabase
.is(), "FmFormPageImpl::findFormForDataSource: invalid data source!");
565 OUString sLookupName
; // the name of the data source we're looking for
566 OUString sFormDataSourceName
; // the name of the data source the current connection in the form is based on
569 Reference
< XPropertySet
> xDSProps(_rxDatabase
, UNO_QUERY
);
571 xDSProps
->getPropertyValue(FM_PROP_NAME
) >>= sLookupName
;
573 xFormProps
->getPropertyValue(FM_PROP_DATASOURCE
) >>= sFormDataSourceName
;
574 // if there's no DataSourceName set at the form, check whether we can deduce one from its
576 if (sFormDataSourceName
.isEmpty())
578 Reference
< XConnection
> xFormConnection
;
579 xFormProps
->getPropertyValue( FM_PROP_ACTIVE_CONNECTION
) >>= xFormConnection
;
580 if ( !xFormConnection
.is() )
581 OStaticDataAccessTools().isEmbeddedInDatabase( xFormProps
, xFormConnection
);
582 if (xFormConnection
.is())
584 Reference
< XChild
> xConnAsChild(xFormConnection
, UNO_QUERY
);
585 if (xConnAsChild
.is())
587 Reference
< XDataSource
> xFormDS(xConnAsChild
->getParent(), UNO_QUERY
);
590 xDSProps
= xDSProps
.query(xFormDS
);
592 xDSProps
->getPropertyValue(FM_PROP_NAME
) >>= sFormDataSourceName
;
598 catch(const Exception
& e
)
601 OSL_FAIL("FmFormPageImpl::findFormForDataSource: caught an exception!");
604 if (sLookupName
== sFormDataSourceName
)
606 // jetzt noch ueberpruefen ob CursorSource und Type uebereinstimmen
607 OUString aCursorSource
= ::comphelper::getString(xFormProps
->getPropertyValue(FM_PROP_COMMAND
));
608 sal_Int32 nType
= ::comphelper::getINT32(xFormProps
->getPropertyValue(FM_PROP_COMMANDTYPE
));
609 if (aCursorSource
.isEmpty() || ((nType
== nCommandType
) && (aCursorSource
== _rCursorSource
))) // found the form
612 // Ist noch keine Datenquelle gesetzt, wird dieses hier nachgeholt
613 if (aCursorSource
.isEmpty())
615 xFormProps
->setPropertyValue(FM_PROP_COMMAND
, makeAny(_rCursorSource
));
616 xFormProps
->setPropertyValue(FM_PROP_COMMANDTYPE
, makeAny((sal_Int32
)nCommandType
));
621 // as long as xResultForm is NULL, search the child forms of rForm
622 Reference
< XIndexAccess
> xComponents(rForm
, UNO_QUERY
);
623 sal_Int32 nCount
= xComponents
->getCount();
624 for (sal_Int32 i
= 0; !xResultForm
.is() && i
< nCount
; ++i
)
626 Reference
< ::com::sun::star::form::XForm
> xSearchForm
;
627 xComponents
->getByIndex(i
) >>= xSearchForm
;
628 // continue searching in the sub form
629 if (xSearchForm
.is())
630 xResultForm
= findFormForDataSource( xSearchForm
, _rxDatabase
, _rCursorSource
, nCommandType
);
636 OUString
FmFormPageImpl::setUniqueName(const Reference
< XFormComponent
> & xFormComponent
, const Reference
< XForm
> & xControls
)
638 #if OSL_DEBUG_LEVEL > 0
641 OSL_ENSURE( !xFormComponent
->getParent().is(), "FmFormPageImpl::setUniqueName: to be called before insertion!" );
643 catch( const Exception
& )
645 DBG_UNHANDLED_EXCEPTION();
649 Reference
< ::com::sun::star::beans::XPropertySet
> xSet(xFormComponent
, UNO_QUERY
);
652 sName
= ::comphelper::getString( xSet
->getPropertyValue( FM_PROP_NAME
) );
653 Reference
< ::com::sun::star::container::XNameAccess
> xNameAcc(xControls
, UNO_QUERY
);
655 if (sName
.isEmpty() || xNameAcc
->hasByName(sName
))
657 // setzen eines default Namens ueber die ClassId
658 sal_Int16
nClassId( FormComponentType::CONTROL
);
659 xSet
->getPropertyValue( FM_PROP_CLASSID
) >>= nClassId
;
661 OUString sDefaultName
= FormControlFactory::getDefaultUniqueName_ByComponentType(
662 Reference
< XNameAccess
>( xControls
, UNO_QUERY
), xSet
);
664 // bei Radiobuttons, die einen Namen haben, diesen nicht ueberschreiben!
665 if (sName
.isEmpty() || nClassId
!= ::com::sun::star::form::FormComponentType::RADIOBUTTON
)
667 xSet
->setPropertyValue(FM_PROP_NAME
, makeAny(sDefaultName
));
670 sName
= sDefaultName
;
677 void FmFormPageImpl::formModelAssigned( const FmFormObj
& _object
)
679 Reference
< XMap
> xControlShapeMap( m_aControlShapeMap
.get(), UNO_QUERY
);
680 if ( !xControlShapeMap
.is() )
681 // our map does not exist -> not interested in this event
686 lcl_removeFormObject_throw( _object
, xControlShapeMap
, false );
687 lcl_insertFormObject_throw( _object
, xControlShapeMap
);
689 catch( const Exception
& )
691 DBG_UNHANDLED_EXCEPTION();
696 void FmFormPageImpl::formObjectInserted( const FmFormObj
& _object
)
698 Reference
< XMap
> xControlShapeMap( m_aControlShapeMap
.get(), UNO_QUERY
);
699 if ( !xControlShapeMap
.is() )
700 // our map does not exist -> not interested in this event
705 lcl_insertFormObject_throw( _object
, xControlShapeMap
);
707 catch( const Exception
& )
709 DBG_UNHANDLED_EXCEPTION();
714 void FmFormPageImpl::formObjectRemoved( const FmFormObj
& _object
)
716 Reference
< XMap
> xControlShapeMap( m_aControlShapeMap
.get(), UNO_QUERY
);
717 if ( !xControlShapeMap
.is() )
718 // our map does not exist -> not interested in this event
723 lcl_removeFormObject_throw( _object
, xControlShapeMap
);
725 catch( const Exception
& )
727 DBG_UNHANDLED_EXCEPTION();
731 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */