1*24acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*24acc546SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*24acc546SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*24acc546SAndrew Rist  * distributed with this work for additional information
6*24acc546SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*24acc546SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*24acc546SAndrew Rist  * "License"); you may not use this file except in compliance
9*24acc546SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*24acc546SAndrew Rist  *
11*24acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*24acc546SAndrew Rist  *
13*24acc546SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*24acc546SAndrew Rist  * software distributed under the License is distributed on an
15*24acc546SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*24acc546SAndrew Rist  * KIND, either express or implied.  See the License for the
17*24acc546SAndrew Rist  * specific language governing permissions and limitations
18*24acc546SAndrew Rist  * under the License.
19*24acc546SAndrew Rist  *
20*24acc546SAndrew Rist  *************************************************************/
21*24acc546SAndrew Rist 
22*24acc546SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir #include "GroupManager.hxx"
27cdf0e10cSrcweir #include <com/sun/star/beans/XFastPropertySet.hpp>
28cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp>
29cdf0e10cSrcweir #include <comphelper/property.hxx>
30cdf0e10cSrcweir #include <comphelper/uno3.hxx>
31cdf0e10cSrcweir #include <tools/solar.h>
32cdf0e10cSrcweir #include <tools/debug.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "property.hrc"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <algorithm>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //.........................................................................
39cdf0e10cSrcweir namespace frm
40cdf0e10cSrcweir {
41cdf0e10cSrcweir //.........................................................................
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace ::com::sun::star::uno;
44cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
45cdf0e10cSrcweir using namespace ::com::sun::star::beans;
46cdf0e10cSrcweir using namespace ::com::sun::star::container;
47cdf0e10cSrcweir using namespace ::com::sun::star::form;
48cdf0e10cSrcweir using namespace ::com::sun::star::awt;
49cdf0e10cSrcweir using namespace ::com::sun::star::lang;
50cdf0e10cSrcweir using namespace ::com::sun::star::form;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir namespace
53cdf0e10cSrcweir {
isRadioButton(const Reference<XPropertySet> & _rxComponent)54cdf0e10cSrcweir     bool isRadioButton( const Reference< XPropertySet >& _rxComponent )
55cdf0e10cSrcweir     {
56cdf0e10cSrcweir         bool bIs = false;
57cdf0e10cSrcweir 	    if ( hasProperty( PROPERTY_CLASSID, _rxComponent ) )
58cdf0e10cSrcweir         {
59cdf0e10cSrcweir             sal_Int16 nClassId = FormComponentType::CONTROL;
60cdf0e10cSrcweir             _rxComponent->getPropertyValue( PROPERTY_CLASSID ) >>= nClassId;
61cdf0e10cSrcweir             if ( nClassId == FormComponentType::RADIOBUTTON )
62cdf0e10cSrcweir                 bIs = true;
63cdf0e10cSrcweir         }
64cdf0e10cSrcweir         return bIs;
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir //========================================================================
69cdf0e10cSrcweir // class OGroupCompAcc
70cdf0e10cSrcweir //========================================================================
71cdf0e10cSrcweir //------------------------------------------------------------------
OGroupCompAcc(const Reference<XPropertySet> & rxElement,const OGroupComp & _rGroupComp)72cdf0e10cSrcweir OGroupCompAcc::OGroupCompAcc(const Reference<XPropertySet>& rxElement, const OGroupComp& _rGroupComp )
73cdf0e10cSrcweir 			   :m_xComponent( rxElement )
74cdf0e10cSrcweir 			   ,m_aGroupComp( _rGroupComp )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir //------------------------------------------------------------------
operator ==(const OGroupCompAcc & rCompAcc) const79cdf0e10cSrcweir sal_Bool OGroupCompAcc::operator==( const OGroupCompAcc& rCompAcc ) const
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	return (m_xComponent == rCompAcc.GetComponent());
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir //------------------------------------------------------------------
85cdf0e10cSrcweir class OGroupCompAccLess : public ::std::binary_function<OGroupCompAcc, OGroupCompAcc, sal_Bool>
86cdf0e10cSrcweir {
87cdf0e10cSrcweir public:
operator ()(const OGroupCompAcc & lhs,const OGroupCompAcc & rhs) const88cdf0e10cSrcweir 	sal_Bool operator() (const OGroupCompAcc& lhs, const OGroupCompAcc& rhs) const
89cdf0e10cSrcweir 	{
90cdf0e10cSrcweir 		return
91cdf0e10cSrcweir 			reinterpret_cast<sal_Int64>(lhs.m_xComponent.get())
92cdf0e10cSrcweir 		<	reinterpret_cast<sal_Int64>(rhs.m_xComponent.get());
93cdf0e10cSrcweir 	}
94cdf0e10cSrcweir };
95cdf0e10cSrcweir 
96cdf0e10cSrcweir //========================================================================
97cdf0e10cSrcweir // class OGroupComp
98cdf0e10cSrcweir //========================================================================
99cdf0e10cSrcweir 
100cdf0e10cSrcweir //------------------------------------------------------------------
OGroupComp()101cdf0e10cSrcweir OGroupComp::OGroupComp()
102cdf0e10cSrcweir     :m_nPos( -1 )
103cdf0e10cSrcweir     ,m_nTabIndex( 0 )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir //------------------------------------------------------------------
OGroupComp(const OGroupComp & _rSource)108cdf0e10cSrcweir OGroupComp::OGroupComp(const OGroupComp& _rSource)
109cdf0e10cSrcweir     :m_aName( _rSource.m_aName )
110cdf0e10cSrcweir     ,m_xComponent( _rSource.m_xComponent )
111cdf0e10cSrcweir     ,m_xControlModel(_rSource.m_xControlModel)
112cdf0e10cSrcweir     ,m_nPos( _rSource.m_nPos )
113cdf0e10cSrcweir     ,m_nTabIndex( _rSource.m_nTabIndex )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir //------------------------------------------------------------------
OGroupComp(const Reference<XPropertySet> & rxSet,sal_Int32 nInsertPos)118cdf0e10cSrcweir OGroupComp::OGroupComp(const Reference<XPropertySet>& rxSet, sal_Int32 nInsertPos )
119cdf0e10cSrcweir     :m_xComponent( rxSet )
120cdf0e10cSrcweir     ,m_xControlModel(rxSet,UNO_QUERY)
121cdf0e10cSrcweir     ,m_nPos( nInsertPos )
122cdf0e10cSrcweir     ,m_nTabIndex(0)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	if (m_xComponent.is())
125cdf0e10cSrcweir 	{
126cdf0e10cSrcweir 		if (hasProperty( PROPERTY_TABINDEX, m_xComponent ) )
127cdf0e10cSrcweir 			// Indices kleiner 0 werden wie 0 behandelt
128cdf0e10cSrcweir 			m_nTabIndex = Max(getINT16(m_xComponent->getPropertyValue( PROPERTY_TABINDEX )) , sal_Int16(0));
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 		m_xComponent->getPropertyValue( PROPERTY_NAME ) >>= m_aName;
131cdf0e10cSrcweir 	}
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir //------------------------------------------------------------------
operator ==(const OGroupComp & rComp) const135cdf0e10cSrcweir sal_Bool OGroupComp::operator==( const OGroupComp& rComp ) const
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 	return m_nTabIndex == rComp.GetTabIndex() && m_nPos == rComp.GetPos();
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir //------------------------------------------------------------------
141cdf0e10cSrcweir class OGroupCompLess : public ::std::binary_function<OGroupComp, OGroupComp, sal_Bool>
142cdf0e10cSrcweir {
143cdf0e10cSrcweir public:
operator ()(const OGroupComp & lhs,const OGroupComp & rhs) const144cdf0e10cSrcweir 	sal_Bool operator() (const OGroupComp& lhs, const OGroupComp& rhs) const
145cdf0e10cSrcweir 	{
146cdf0e10cSrcweir 		sal_Bool bResult;
147cdf0e10cSrcweir 		// TabIndex von 0 wird hinten einsortiert
148cdf0e10cSrcweir 		if (lhs.m_nTabIndex == rhs.GetTabIndex())
149cdf0e10cSrcweir 			bResult = lhs.m_nPos < rhs.GetPos();
150cdf0e10cSrcweir 		else if (lhs.m_nTabIndex && rhs.GetTabIndex())
151cdf0e10cSrcweir 			bResult = lhs.m_nTabIndex < rhs.GetTabIndex();
152cdf0e10cSrcweir 		else
153cdf0e10cSrcweir 			bResult = lhs.m_nTabIndex != 0;
154cdf0e10cSrcweir 		return bResult;
155cdf0e10cSrcweir 	}
156cdf0e10cSrcweir };
157cdf0e10cSrcweir 
158cdf0e10cSrcweir //========================================================================
159cdf0e10cSrcweir // class OGroup
160cdf0e10cSrcweir //========================================================================
161cdf0e10cSrcweir 
DBG_NAME(OGroup)162cdf0e10cSrcweir DBG_NAME(OGroup)
163cdf0e10cSrcweir //------------------------------------------------------------------
164cdf0e10cSrcweir OGroup::OGroup( const ::rtl::OUString& rGroupName )
165cdf0e10cSrcweir 		:m_aGroupName( rGroupName )
166cdf0e10cSrcweir 		,m_nInsertPos(0)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	DBG_CTOR(OGroup,NULL);
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir #ifdef DBG_UTIL
172cdf0e10cSrcweir //------------------------------------------------------------------
OGroup(const OGroup & _rSource)173cdf0e10cSrcweir OGroup::OGroup( const OGroup& _rSource )
174cdf0e10cSrcweir :m_aCompArray(_rSource.m_aCompArray)
175cdf0e10cSrcweir 	,m_aCompAccArray(_rSource.m_aCompAccArray)
176cdf0e10cSrcweir 	,m_aGroupName(_rSource.m_aGroupName)
177cdf0e10cSrcweir 	,m_nInsertPos(_rSource.m_nInsertPos)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 	DBG_CTOR(OGroup,NULL);
180cdf0e10cSrcweir }
181cdf0e10cSrcweir #endif
182cdf0e10cSrcweir 
183cdf0e10cSrcweir //------------------------------------------------------------------
~OGroup()184cdf0e10cSrcweir OGroup::~OGroup()
185cdf0e10cSrcweir {
186cdf0e10cSrcweir 	DBG_DTOR(OGroup,NULL);
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir //------------------------------------------------------------------
InsertComponent(const Reference<XPropertySet> & xSet)190cdf0e10cSrcweir void OGroup::InsertComponent( const Reference<XPropertySet>& xSet )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir 	OGroupComp aNewGroupComp( xSet, m_nInsertPos );
193cdf0e10cSrcweir 	sal_Int32 nPosInserted = insert_sorted(m_aCompArray, aNewGroupComp, OGroupCompLess());
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	OGroupCompAcc aNewGroupCompAcc( xSet, m_aCompArray[nPosInserted] );
196cdf0e10cSrcweir 	insert_sorted(m_aCompAccArray, aNewGroupCompAcc, OGroupCompAccLess());
197cdf0e10cSrcweir 	m_nInsertPos++;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir //------------------------------------------------------------------
RemoveComponent(const Reference<XPropertySet> & rxElement)201cdf0e10cSrcweir void OGroup::RemoveComponent( const Reference<XPropertySet>& rxElement )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir 	sal_Int32 nGroupCompAccPos;
204cdf0e10cSrcweir 	OGroupCompAcc aSearchCompAcc( rxElement, OGroupComp() );
205cdf0e10cSrcweir 	if ( seek_entry(m_aCompAccArray, aSearchCompAcc, nGroupCompAccPos, OGroupCompAccLess()) )
206cdf0e10cSrcweir 	{
207cdf0e10cSrcweir 		OGroupCompAcc& aGroupCompAcc = m_aCompAccArray[nGroupCompAccPos];
208cdf0e10cSrcweir 		const OGroupComp& aGroupComp = aGroupCompAcc.GetGroupComponent();
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 		sal_Int32 nGroupCompPos;
211cdf0e10cSrcweir 		if ( seek_entry(m_aCompArray, aGroupComp, nGroupCompPos, OGroupCompLess()) )
212cdf0e10cSrcweir 		{
213cdf0e10cSrcweir 			m_aCompAccArray.erase( m_aCompAccArray.begin() + nGroupCompAccPos );
214cdf0e10cSrcweir 			m_aCompArray.erase( m_aCompArray.begin() + nGroupCompPos );
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 			/*============================================================
217cdf0e10cSrcweir 			Durch das Entfernen der GroupComp ist die Einfuegeposition
218cdf0e10cSrcweir 			ungueltig geworden. Sie braucht hier aber nicht angepasst werden,
219cdf0e10cSrcweir 			da sie fortlaufend vergeben wird und damit immer
220cdf0e10cSrcweir 			aufsteigend eindeutig ist.
221cdf0e10cSrcweir 			============================================================*/
222cdf0e10cSrcweir 		}
223cdf0e10cSrcweir 		else
224cdf0e10cSrcweir 		{
225cdf0e10cSrcweir 			DBG_ERROR( "OGroup::RemoveComponent: Component nicht in Gruppe" );
226cdf0e10cSrcweir 		}
227cdf0e10cSrcweir 	}
228cdf0e10cSrcweir 	else
229cdf0e10cSrcweir 	{
230cdf0e10cSrcweir 		DBG_ERROR( "OGroup::RemoveComponent: Component nicht in Gruppe" );
231cdf0e10cSrcweir 	}
232cdf0e10cSrcweir }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir //------------------------------------------------------------------
operator ==(const OGroup & rGroup) const235cdf0e10cSrcweir sal_Bool OGroup::operator==( const OGroup& rGroup ) const
236cdf0e10cSrcweir {
237cdf0e10cSrcweir 	return m_aGroupName.equals(rGroup.GetGroupName());
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir //------------------------------------------------------------------
241cdf0e10cSrcweir class OGroupLess : public ::std::binary_function<OGroup, OGroup, sal_Bool>
242cdf0e10cSrcweir {
243cdf0e10cSrcweir public:
operator ()(const OGroup & lhs,const OGroup & rhs) const244cdf0e10cSrcweir 	sal_Bool operator() (const OGroup& lhs, const OGroup& rhs) const
245cdf0e10cSrcweir 	{
246cdf0e10cSrcweir 		return lhs.m_aGroupName < rhs.m_aGroupName;
247cdf0e10cSrcweir 	}
248cdf0e10cSrcweir };
249cdf0e10cSrcweir 
250cdf0e10cSrcweir //------------------------------------------------------------------
GetControlModels() const251cdf0e10cSrcweir Sequence< Reference<XControlModel>  > OGroup::GetControlModels() const
252cdf0e10cSrcweir {
253cdf0e10cSrcweir 	sal_Int32 nLen = m_aCompArray.size();
254cdf0e10cSrcweir 	Sequence<Reference<XControlModel> > aControlModelSeq( nLen );
255cdf0e10cSrcweir 	Reference<XControlModel>* pModels = aControlModelSeq.getArray();
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	ConstOGroupCompArrIterator aGroupComps = m_aCompArray.begin();
258cdf0e10cSrcweir 	for (sal_Int32 i = 0; i < nLen; ++i, ++pModels, ++aGroupComps)
259cdf0e10cSrcweir 	{
260cdf0e10cSrcweir 		*pModels = aGroupComps->GetControlModel();
261cdf0e10cSrcweir 	}
262cdf0e10cSrcweir 	return aControlModelSeq;
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir DBG_NAME(OGroupManager);
266cdf0e10cSrcweir //------------------------------------------------------------------
OGroupManager(const Reference<XContainer> & _rxContainer)267cdf0e10cSrcweir OGroupManager::OGroupManager(const Reference< XContainer >& _rxContainer)
268cdf0e10cSrcweir 	:m_pCompGroup( new OGroup( ::rtl::OUString::createFromAscii( "AllComponentGroup" ) ) )
269cdf0e10cSrcweir 	,m_xContainer(_rxContainer)
270cdf0e10cSrcweir {
271cdf0e10cSrcweir 	DBG_CTOR(OGroupManager,NULL);
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 	increment(m_refCount);
274cdf0e10cSrcweir 	{
275cdf0e10cSrcweir 		_rxContainer->addContainerListener(this);
276cdf0e10cSrcweir 	}
277cdf0e10cSrcweir 	decrement(m_refCount);
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir //------------------------------------------------------------------
~OGroupManager()281cdf0e10cSrcweir OGroupManager::~OGroupManager()
282cdf0e10cSrcweir {
283cdf0e10cSrcweir 	DBG_DTOR(OGroupManager,NULL);
284cdf0e10cSrcweir 	// Alle Components und CompGroup loeschen
285cdf0e10cSrcweir 	delete m_pCompGroup;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir // XPropertyChangeListener
289cdf0e10cSrcweir //------------------------------------------------------------------
disposing(const EventObject & evt)290cdf0e10cSrcweir void OGroupManager::disposing(const EventObject& evt) throw( RuntimeException )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir 	Reference<XContainer>  xContainer(evt.Source, UNO_QUERY);
293cdf0e10cSrcweir 	if (xContainer.get() == m_xContainer.get())
294cdf0e10cSrcweir 	{
295cdf0e10cSrcweir 		DELETEZ(m_pCompGroup);
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 		////////////////////////////////////////////////////////////////
298cdf0e10cSrcweir 		// Gruppen loeschen
299cdf0e10cSrcweir 		m_aGroupArr.clear();
300cdf0e10cSrcweir 		m_xContainer.clear();
301cdf0e10cSrcweir 	}
302cdf0e10cSrcweir }
303cdf0e10cSrcweir // -----------------------------------------------------------------------------
removeFromGroupMap(const::rtl::OUString & _sGroupName,const Reference<XPropertySet> & _xSet)304cdf0e10cSrcweir void OGroupManager::removeFromGroupMap(const ::rtl::OUString& _sGroupName,const Reference<XPropertySet>& _xSet)
305cdf0e10cSrcweir {
306cdf0e10cSrcweir 	// Component aus CompGroup entfernen
307cdf0e10cSrcweir 	m_pCompGroup->RemoveComponent( _xSet );
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 	OGroupArr::iterator aFind = m_aGroupArr.find(_sGroupName);
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 	if ( aFind != m_aGroupArr.end() )
312cdf0e10cSrcweir 	{
313cdf0e10cSrcweir 		// Gruppe vorhanden
314cdf0e10cSrcweir 		aFind->second.RemoveComponent( _xSet );
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 		// Wenn Anzahl der Gruppenelemente == 1 ist, Gruppe deaktivieren
317cdf0e10cSrcweir 		if ( aFind->second.Count() == 1 )
318cdf0e10cSrcweir 		{
319cdf0e10cSrcweir 			OActiveGroups::iterator aActiveFind = ::std::find(
320cdf0e10cSrcweir                 m_aActiveGroupMap.begin(),
321cdf0e10cSrcweir                 m_aActiveGroupMap.end(),
322cdf0e10cSrcweir                 aFind
323cdf0e10cSrcweir             );
324cdf0e10cSrcweir 			if ( aActiveFind != m_aActiveGroupMap.end() )
325cdf0e10cSrcweir             {
326cdf0e10cSrcweir                 // the group is active. Deactivate it if the remaining component
327cdf0e10cSrcweir                 // is *no* radio button
328cdf0e10cSrcweir                 if ( !isRadioButton( aFind->second.GetObject( 0 ) ) )
329cdf0e10cSrcweir 				    m_aActiveGroupMap.erase( aActiveFind );
330cdf0e10cSrcweir             }
331cdf0e10cSrcweir 		}
332cdf0e10cSrcweir 	}
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 	// Bei Component als PropertyChangeListener abmelden
336cdf0e10cSrcweir 	_xSet->removePropertyChangeListener( PROPERTY_NAME, this );
337cdf0e10cSrcweir 	if (hasProperty(PROPERTY_TABINDEX, _xSet))
338cdf0e10cSrcweir 		_xSet->removePropertyChangeListener( PROPERTY_TABINDEX, this );
339cdf0e10cSrcweir }
340cdf0e10cSrcweir //------------------------------------------------------------------
propertyChange(const PropertyChangeEvent & evt)341cdf0e10cSrcweir void SAL_CALL OGroupManager::propertyChange(const PropertyChangeEvent& evt) throw ( ::com::sun::star::uno::RuntimeException)
342cdf0e10cSrcweir {
343cdf0e10cSrcweir 	Reference<XPropertySet>  xSet(evt.Source, UNO_QUERY);
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 	// Component aus Gruppe entfernen
346cdf0e10cSrcweir 	::rtl::OUString		sGroupName;
347cdf0e10cSrcweir 	if (evt.PropertyName == PROPERTY_NAME)
348cdf0e10cSrcweir 		evt.OldValue >>= sGroupName;
349cdf0e10cSrcweir 	else
350cdf0e10cSrcweir 		xSet->getPropertyValue( PROPERTY_NAME ) >>= sGroupName;
351cdf0e10cSrcweir 
352cdf0e10cSrcweir 	removeFromGroupMap(sGroupName,xSet);
353cdf0e10cSrcweir 
354cdf0e10cSrcweir 	// Component neu einordnen
355cdf0e10cSrcweir 	InsertElement( xSet );
356cdf0e10cSrcweir }
357cdf0e10cSrcweir 
358cdf0e10cSrcweir // XContainerListener
359cdf0e10cSrcweir //------------------------------------------------------------------
elementInserted(const ContainerEvent & Event)360cdf0e10cSrcweir void SAL_CALL OGroupManager::elementInserted(const ContainerEvent& Event) throw ( ::com::sun::star::uno::RuntimeException)
361cdf0e10cSrcweir {
362cdf0e10cSrcweir 	Reference< XPropertySet > xProps;
363cdf0e10cSrcweir 	Event.Element >>= xProps;
364cdf0e10cSrcweir 	if ( xProps.is() )
365cdf0e10cSrcweir 		InsertElement( xProps );
366cdf0e10cSrcweir }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir //------------------------------------------------------------------
elementRemoved(const ContainerEvent & Event)369cdf0e10cSrcweir void SAL_CALL OGroupManager::elementRemoved(const ContainerEvent& Event) throw ( ::com::sun::star::uno::RuntimeException)
370cdf0e10cSrcweir {
371cdf0e10cSrcweir 	Reference<XPropertySet> xProps;
372cdf0e10cSrcweir 	Event.Element >>= xProps;
373cdf0e10cSrcweir 	if ( xProps.is() )
374cdf0e10cSrcweir 		RemoveElement( xProps );
375cdf0e10cSrcweir }
376cdf0e10cSrcweir 
377cdf0e10cSrcweir //------------------------------------------------------------------
elementReplaced(const ContainerEvent & Event)378cdf0e10cSrcweir void SAL_CALL OGroupManager::elementReplaced(const ContainerEvent& Event) throw ( ::com::sun::star::uno::RuntimeException)
379cdf0e10cSrcweir {
380cdf0e10cSrcweir 	Reference<XPropertySet> xProps;
381cdf0e10cSrcweir 	Event.ReplacedElement >>= xProps;
382cdf0e10cSrcweir 	if ( xProps.is() )
383cdf0e10cSrcweir 		RemoveElement( xProps );
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 	xProps.clear();
386cdf0e10cSrcweir 	Event.Element >>= xProps;
387cdf0e10cSrcweir 	if ( xProps.is() )
388cdf0e10cSrcweir 		InsertElement( xProps );
389cdf0e10cSrcweir }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir // Other functions
392cdf0e10cSrcweir //------------------------------------------------------------------
getControlModels()393cdf0e10cSrcweir Sequence<Reference<XControlModel> > OGroupManager::getControlModels()
394cdf0e10cSrcweir {
395cdf0e10cSrcweir 	return m_pCompGroup->GetControlModels();
396cdf0e10cSrcweir }
397cdf0e10cSrcweir 
398cdf0e10cSrcweir //------------------------------------------------------------------
getGroupCount()399cdf0e10cSrcweir sal_Int32 OGroupManager::getGroupCount()
400cdf0e10cSrcweir {
401cdf0e10cSrcweir 	return m_aActiveGroupMap.size();
402cdf0e10cSrcweir }
403cdf0e10cSrcweir 
404cdf0e10cSrcweir //------------------------------------------------------------------
getGroup(sal_Int32 nGroup,Sequence<Reference<XControlModel>> & _rGroup,::rtl::OUString & _rName)405cdf0e10cSrcweir void OGroupManager::getGroup(sal_Int32 nGroup, Sequence< Reference<XControlModel> >& _rGroup, ::rtl::OUString& _rName)
406cdf0e10cSrcweir {
407cdf0e10cSrcweir 	OSL_ENSURE(nGroup >= 0 && (size_t)nGroup < m_aActiveGroupMap.size(),"OGroupManager::getGroup: Invalid group index!");
408cdf0e10cSrcweir 	OGroupArr::iterator aGroupPos	= m_aActiveGroupMap[nGroup];
409cdf0e10cSrcweir 	_rName							= aGroupPos->second.GetGroupName();
410cdf0e10cSrcweir 	_rGroup							= aGroupPos->second.GetControlModels();
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir //------------------------------------------------------------------
getGroupByName(const::rtl::OUString & _rName,Sequence<Reference<XControlModel>> & _rGroup)414cdf0e10cSrcweir void OGroupManager::getGroupByName(const ::rtl::OUString& _rName, Sequence< Reference<XControlModel>  >& _rGroup)
415cdf0e10cSrcweir {
416cdf0e10cSrcweir 	OGroupArr::iterator aFind = m_aGroupArr.find(_rName);
417cdf0e10cSrcweir 	if ( aFind != m_aGroupArr.end() )
418cdf0e10cSrcweir 		_rGroup = aFind->second.GetControlModels();
419cdf0e10cSrcweir }
420cdf0e10cSrcweir 
421cdf0e10cSrcweir //------------------------------------------------------------------
InsertElement(const Reference<XPropertySet> & xSet)422cdf0e10cSrcweir void OGroupManager::InsertElement( const Reference<XPropertySet>& xSet )
423cdf0e10cSrcweir {
424cdf0e10cSrcweir 	// Nur ControlModels
425cdf0e10cSrcweir 	Reference<XControlModel>  xControl(xSet, UNO_QUERY);
426cdf0e10cSrcweir 	if (!xControl.is() )
427cdf0e10cSrcweir 		return;
428cdf0e10cSrcweir 
429cdf0e10cSrcweir 	// Component in CompGroup aufnehmen
430cdf0e10cSrcweir 	m_pCompGroup->InsertComponent( xSet );
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 	// Component in Gruppe aufnehmen
433cdf0e10cSrcweir 	::rtl::OUString sGroupName;
434cdf0e10cSrcweir 	xSet->getPropertyValue( PROPERTY_NAME ) >>= sGroupName;
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 	OGroupArr::iterator aFind = m_aGroupArr.find(sGroupName);
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 	if ( aFind == m_aGroupArr.end() )
439cdf0e10cSrcweir 	{
440cdf0e10cSrcweir 		aFind = m_aGroupArr.insert(OGroupArr::value_type(sGroupName,OGroup(sGroupName))).first;
441cdf0e10cSrcweir 	}
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 	aFind->second.InsertComponent( xSet );
444cdf0e10cSrcweir 
445cdf0e10cSrcweir 	// if we have at least 2 elements in the group, then this is an "active group"
446cdf0e10cSrcweir     bool bActivateGroup = aFind->second.Count() == 2;
447cdf0e10cSrcweir 
448cdf0e10cSrcweir     // Additionally, if the component is a radio button, then it's group becomes active,
449cdf0e10cSrcweir     // too. With this, we ensure that in a container with n radio buttons which all are
450cdf0e10cSrcweir     // in different groups the selection still works reliably (means that all radios can be
451cdf0e10cSrcweir     // clicked independently)
452cdf0e10cSrcweir     if ( aFind->second.Count() == 1 )
453cdf0e10cSrcweir     {
454cdf0e10cSrcweir         if ( isRadioButton( xSet ) )
455cdf0e10cSrcweir             bActivateGroup = true;
456cdf0e10cSrcweir     }
457cdf0e10cSrcweir 
458cdf0e10cSrcweir 	if ( bActivateGroup )
459cdf0e10cSrcweir 	{
460cdf0e10cSrcweir 		OActiveGroups::iterator aAlreadyExistent = ::std::find(
461cdf0e10cSrcweir             m_aActiveGroupMap.begin(),
462cdf0e10cSrcweir             m_aActiveGroupMap.end(),
463cdf0e10cSrcweir             aFind
464cdf0e10cSrcweir         );
465cdf0e10cSrcweir         if ( aAlreadyExistent == m_aActiveGroupMap.end() )
466cdf0e10cSrcweir     		m_aActiveGroupMap.push_back(  aFind );
467cdf0e10cSrcweir 	}
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 	// Bei Component als PropertyChangeListener anmelden
471cdf0e10cSrcweir 	xSet->addPropertyChangeListener( PROPERTY_NAME, this );
472cdf0e10cSrcweir 
473cdf0e10cSrcweir     // Tabindex muss nicht jeder unterstuetzen
474cdf0e10cSrcweir 	if (hasProperty(PROPERTY_TABINDEX, xSet))
475cdf0e10cSrcweir 		xSet->addPropertyChangeListener( PROPERTY_TABINDEX, this );
476cdf0e10cSrcweir 
477cdf0e10cSrcweir }
478cdf0e10cSrcweir 
479cdf0e10cSrcweir //------------------------------------------------------------------
RemoveElement(const Reference<XPropertySet> & xSet)480cdf0e10cSrcweir void OGroupManager::RemoveElement( const Reference<XPropertySet>& xSet )
481cdf0e10cSrcweir {
482cdf0e10cSrcweir 	// Nur ControlModels
483cdf0e10cSrcweir 	Reference<XControlModel>  xControl(xSet, UNO_QUERY);
484cdf0e10cSrcweir 	if (!xControl.is() )
485cdf0e10cSrcweir 		return;
486cdf0e10cSrcweir 
487cdf0e10cSrcweir 	// Component aus Gruppe entfernen
488cdf0e10cSrcweir 	::rtl::OUString		sGroupName;
489cdf0e10cSrcweir 	xSet->getPropertyValue( PROPERTY_NAME ) >>= sGroupName;
490cdf0e10cSrcweir 
491cdf0e10cSrcweir 	removeFromGroupMap(sGroupName,xSet);
492cdf0e10cSrcweir }
493cdf0e10cSrcweir 
494cdf0e10cSrcweir //.........................................................................
495cdf0e10cSrcweir }	// namespace frm
496cdf0e10cSrcweir //.........................................................................
497cdf0e10cSrcweir 
498