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