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 "RadioButton.hxx"
27cdf0e10cSrcweir #include "property.hxx"
28cdf0e10cSrcweir #ifndef _FRM_PROPERTY_HRC_
29cdf0e10cSrcweir #include "property.hrc"
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir #include "services.hxx"
32cdf0e10cSrcweir #include <tools/debug.hxx>
33cdf0e10cSrcweir #include <comphelper/extract.hxx>
34cdf0e10cSrcweir #include <comphelper/basicio.hxx>
35cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
36cdf0e10cSrcweir #include <com/sun/star/awt/XVclWindowPeer.hpp>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //.........................................................................
39cdf0e10cSrcweir namespace frm
40cdf0e10cSrcweir {
41cdf0e10cSrcweir using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
43cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
44cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
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::io;
50cdf0e10cSrcweir using namespace ::com::sun::star::lang;
51cdf0e10cSrcweir using namespace ::com::sun::star::util;
52cdf0e10cSrcweir using namespace ::com::sun::star::form::binding;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //==================================================================
55cdf0e10cSrcweir //------------------------------------------------------------------------------
ORadioButtonControl_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)56cdf0e10cSrcweir InterfaceRef SAL_CALL ORadioButtonControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) throw (RuntimeException)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir 	return *(new ORadioButtonControl(_rxFactory));
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //------------------------------------------------------------------------------
getSupportedServiceNames()62cdf0e10cSrcweir StringSequence SAL_CALL	ORadioButtonControl::getSupportedServiceNames() throw(RuntimeException)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	StringSequence aSupported = OBoundControl::getSupportedServiceNames();
65cdf0e10cSrcweir 	aSupported.realloc(aSupported.getLength() + 1);
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	::rtl::OUString* pArray = aSupported.getArray();
68cdf0e10cSrcweir 	pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_RADIOBUTTON;
69cdf0e10cSrcweir 	return aSupported;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
73cdf0e10cSrcweir //------------------------------------------------------------------
ORadioButtonControl(const Reference<XMultiServiceFactory> & _rxFactory)74cdf0e10cSrcweir ORadioButtonControl::ORadioButtonControl(const Reference<XMultiServiceFactory>& _rxFactory)
75cdf0e10cSrcweir 					  :OBoundControl(_rxFactory, VCL_CONTROL_RADIOBUTTON)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir //------------------------------------------------------------------
createPeer(const Reference<starawt::XToolkit> & _rxToolkit,const Reference<starawt::XWindowPeer> & _rxParent)80cdf0e10cSrcweir void SAL_CALL ORadioButtonControl::createPeer(const Reference<starawt::XToolkit>& _rxToolkit, const Reference<starawt::XWindowPeer>& _rxParent) throw (RuntimeException)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir 	OBoundControl::createPeer(_rxToolkit, _rxParent);
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	// switch off the auto-toggle, we do this ourself ....
85cdf0e10cSrcweir 	// (formerly this switch-off was done in the toolkit - but the correct place is here ...)
86cdf0e10cSrcweir //	Reference< XVclWindowPeer >  xVclWindowPeer( getPeer(), UNO_QUERY );
87cdf0e10cSrcweir //	if (xVclWindowPeer.is())
88cdf0e10cSrcweir //		xVclWindowPeer->setProperty(::rtl::OUString::createFromAscii("AutoToggle"), ::cppu::bool2any(sal_False));
89cdf0e10cSrcweir 	// new order: do _not_ switch off the auto toggle because:
90cdf0e10cSrcweir 	// * today, it is not necessary anymore to handle the toggling ourself (everything works fine without it)
91cdf0e10cSrcweir 	// * without auto toggle, the AccessibleEvents as fired by the radio buttons are
92cdf0e10cSrcweir 	//     a. newly checked button: "unchecked"->"checked"
93cdf0e10cSrcweir 	//     b. previously checked button: "checked"->"unchecked"
94cdf0e10cSrcweir 	//   This is deadly for AT-tools, which then get the "unchecked" event _immediately_ after the "checked" event,
95cdf0e10cSrcweir 	//   and only read the latter. This makes radio buttons pretty unusable in form documents.
96cdf0e10cSrcweir 	//   So we switched AutoToggle _on_, again, because then VCL can handle the notifications, and will send
97cdf0e10cSrcweir 	//   them in the proper order.
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir //==================================================================
ORadioButtonModel_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)101cdf0e10cSrcweir InterfaceRef SAL_CALL ORadioButtonModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) throw (RuntimeException)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	return *(new ORadioButtonModel(_rxFactory));
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir //------------------------------------------------------------------
DBG_NAME(ORadioButtonModel)107cdf0e10cSrcweir DBG_NAME( ORadioButtonModel )
108cdf0e10cSrcweir //------------------------------------------------------------------
109cdf0e10cSrcweir ORadioButtonModel::ORadioButtonModel(const Reference<XMultiServiceFactory>& _rxFactory)
110cdf0e10cSrcweir     :OReferenceValueComponent( _rxFactory, VCL_CONTROLMODEL_RADIOBUTTON, FRM_SUN_CONTROL_RADIOBUTTON,sal_True )
111cdf0e10cSrcweir 					// use the old control name for compytibility reasons
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	DBG_CTOR( ORadioButtonModel, NULL );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	m_nClassId = FormComponentType::RADIOBUTTON;
116cdf0e10cSrcweir 	m_aLabelServiceName = FRM_SUN_COMPONENT_GROUPBOX;
117cdf0e10cSrcweir     initValueProperty( PROPERTY_STATE, PROPERTY_ID_STATE );
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir //------------------------------------------------------------------
ORadioButtonModel(const ORadioButtonModel * _pOriginal,const Reference<XMultiServiceFactory> & _rxFactory)121cdf0e10cSrcweir ORadioButtonModel::ORadioButtonModel( const ORadioButtonModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
122cdf0e10cSrcweir 	:OReferenceValueComponent( _pOriginal, _rxFactory )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	DBG_CTOR( ORadioButtonModel, NULL );
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir //------------------------------------------------------------------------------
~ORadioButtonModel()128cdf0e10cSrcweir ORadioButtonModel::~ORadioButtonModel()
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	DBG_DTOR( ORadioButtonModel, NULL );
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir // XCloneable
134cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPLEMENT_DEFAULT_CLONING(ORadioButtonModel)135cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( ORadioButtonModel )
136cdf0e10cSrcweir 
137cdf0e10cSrcweir // XServiceInfo
138cdf0e10cSrcweir //------------------------------------------------------------------------------
139cdf0e10cSrcweir StringSequence SAL_CALL	ORadioButtonModel::getSupportedServiceNames() throw(RuntimeException)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	StringSequence aSupported = OReferenceValueComponent::getSupportedServiceNames();
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     sal_Int32 nOldLen = aSupported.getLength();
144cdf0e10cSrcweir 	aSupported.realloc( nOldLen + 8 );
145cdf0e10cSrcweir 	::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     *pStoreTo++ = BINDABLE_CONTROL_MODEL;
148cdf0e10cSrcweir     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
149cdf0e10cSrcweir     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
152cdf0e10cSrcweir     *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     *pStoreTo++ = FRM_SUN_COMPONENT_RADIOBUTTON;
155cdf0e10cSrcweir     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_RADIOBUTTON;
156cdf0e10cSrcweir     *pStoreTo++ = BINDABLE_DATABASE_RADIO_BUTTON;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	return aSupported;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir //------------------------------------------------------------------------------
SetSiblingPropsTo(const::rtl::OUString & rPropName,const Any & rValue)162cdf0e10cSrcweir void ORadioButtonModel::SetSiblingPropsTo(const ::rtl::OUString& rPropName, const Any& rValue)
163cdf0e10cSrcweir {
164cdf0e10cSrcweir 	// mein Name
165cdf0e10cSrcweir 	::rtl::OUString sMyName(m_aName);
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 	// meine Siblings durchiterieren
168cdf0e10cSrcweir 	Reference<XIndexAccess> xIndexAccess(getParent(), UNO_QUERY);
169cdf0e10cSrcweir 	if (xIndexAccess.is())
170cdf0e10cSrcweir 	{
171cdf0e10cSrcweir 		Reference<XPropertySet> xMyProps;
172cdf0e10cSrcweir 		query_interface(static_cast<XWeak*>(this), xMyProps);
173cdf0e10cSrcweir 		::rtl::OUString	sCurrentName;
174cdf0e10cSrcweir 		for (sal_Int32 i=0; i<xIndexAccess->getCount(); ++i)
175cdf0e10cSrcweir 		{
176cdf0e10cSrcweir 			Reference<XPropertySet>	xSiblingProperties(*(InterfaceRef*)xIndexAccess->getByIndex(i).getValue(), UNO_QUERY);
177cdf0e10cSrcweir 			if (!xSiblingProperties.is())
178cdf0e10cSrcweir 				continue;
179cdf0e10cSrcweir 			if (xMyProps == xSiblingProperties)
180cdf0e10cSrcweir 				continue;	// mich selber nicht umsetzen
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 			// nur wenn es ein Radio-Button ist
183cdf0e10cSrcweir 			if (!hasProperty(PROPERTY_CLASSID, xSiblingProperties))
184cdf0e10cSrcweir 				continue;
185cdf0e10cSrcweir 			sal_Int16 nType = 0;
186cdf0e10cSrcweir 			xSiblingProperties->getPropertyValue(PROPERTY_CLASSID) >>= nType;
187cdf0e10cSrcweir 			if (nType != FormComponentType::RADIOBUTTON)
188cdf0e10cSrcweir 				continue;
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 			// das 'zur selben Gruppe gehoeren' wird am Namen festgemacht
191cdf0e10cSrcweir 			xSiblingProperties->getPropertyValue(PROPERTY_NAME) >>= sCurrentName;
192cdf0e10cSrcweir 			if (sCurrentName == sMyName)
193cdf0e10cSrcweir 				xSiblingProperties->setPropertyValue(rPropName, rValue);
194cdf0e10cSrcweir 		}
195cdf0e10cSrcweir 	}
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir //------------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)199cdf0e10cSrcweir void ORadioButtonModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) throw (Exception)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	OReferenceValueComponent::setFastPropertyValue_NoBroadcast( nHandle, rValue );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 	// if the label control changed ...
204cdf0e10cSrcweir 	if (nHandle == PROPERTY_ID_CONTROLLABEL)
205cdf0e10cSrcweir 	{	// ... forward this to our siblings
206cdf0e10cSrcweir 		SetSiblingPropsTo(PROPERTY_CONTROLLABEL, rValue);
207cdf0e10cSrcweir 	}
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 	// wenn sich die ControlSource-Eigenschaft geaendert hat ...
210cdf0e10cSrcweir 	if (nHandle == PROPERTY_ID_CONTROLSOURCE)
211cdf0e10cSrcweir 	{	// ... muss ich allen meinen Siblings, die in der selben RadioButton-Gruppe sind wie ich, auch die
212cdf0e10cSrcweir 		// neue ControlSource mitgeben
213cdf0e10cSrcweir 		SetSiblingPropsTo(PROPERTY_CONTROLSOURCE, rValue);
214cdf0e10cSrcweir 	}
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 	// die andere Richtung : wenn sich mein Name aendert ...
217cdf0e10cSrcweir 	if (nHandle == PROPERTY_ID_NAME)
218cdf0e10cSrcweir 	{
219cdf0e10cSrcweir 		// ... muss ich testen, ob ich Siblings mit dem selben Namen habe, damit ich deren ControlSource uebernehmen kann
220cdf0e10cSrcweir 		Reference<XIndexAccess> xIndexAccess(getParent(), UNO_QUERY);
221cdf0e10cSrcweir 		if (xIndexAccess.is())
222cdf0e10cSrcweir 		{
223cdf0e10cSrcweir 			::rtl::OUString			sName;
224cdf0e10cSrcweir 			::rtl::OUString			sControlSource;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 			Reference<XPropertySet> xMyProps;
227cdf0e10cSrcweir 			query_interface(static_cast<XWeak*>(this), xMyProps);
228cdf0e10cSrcweir 			for (sal_Int32 i=0; i<xIndexAccess->getCount(); ++i)
229cdf0e10cSrcweir 			{
230cdf0e10cSrcweir 				Reference<XPropertySet>	xSiblingProperties(*(InterfaceRef*)xIndexAccess->getByIndex(i).getValue(), UNO_QUERY);
231cdf0e10cSrcweir 				if (!xSiblingProperties.is())
232cdf0e10cSrcweir 					continue;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 				if (xMyProps == xSiblingProperties)
235cdf0e10cSrcweir 					// nur wenn ich nicht mich selber gefunden habe
236cdf0e10cSrcweir 					continue;
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 				sal_Int16 nType = 0;
239cdf0e10cSrcweir 				xSiblingProperties->getPropertyValue(PROPERTY_CLASSID) >>= nType;
240cdf0e10cSrcweir 				if (nType != FormComponentType::RADIOBUTTON)
241cdf0e10cSrcweir 					// nur Radio-Buttons
242cdf0e10cSrcweir 					continue;
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 				xSiblingProperties->getPropertyValue(PROPERTY_NAME) >>= sName;
245cdf0e10cSrcweir 				// Control, das zur gleichen Gruppe gehoert ?
246cdf0e10cSrcweir 				if (rValue == sName)
247cdf0e10cSrcweir 				{
248cdf0e10cSrcweir 					setPropertyValue(PROPERTY_CONTROLSOURCE, xSiblingProperties->getPropertyValue(PROPERTY_CONTROLSOURCE));
249cdf0e10cSrcweir 					break;
250cdf0e10cSrcweir 				}
251cdf0e10cSrcweir 			}
252cdf0e10cSrcweir 		}
253cdf0e10cSrcweir 	}
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 	if (nHandle == PROPERTY_ID_DEFAULT_STATE)
256cdf0e10cSrcweir 	{
257cdf0e10cSrcweir 		sal_Int16 nValue;
258cdf0e10cSrcweir 		rValue >>= nValue;
259cdf0e10cSrcweir 		if (1 == nValue)
260cdf0e10cSrcweir 		{	// bei allen Radios der selben Gruppe das 'default checked' ruecksetzen, denn wie schon der highlander wusste :
261cdf0e10cSrcweir 			// es kann nur einen geben.
262cdf0e10cSrcweir 			Any aZero;
263cdf0e10cSrcweir 			nValue = 0;
264cdf0e10cSrcweir 			aZero <<= nValue;
265cdf0e10cSrcweir 			SetSiblingPropsTo(PROPERTY_DEFAULT_STATE, aZero);
266cdf0e10cSrcweir 		}
267cdf0e10cSrcweir 	}
268cdf0e10cSrcweir }
269cdf0e10cSrcweir 
270cdf0e10cSrcweir //------------------------------------------------------------------------------
describeFixedProperties(Sequence<Property> & _rProps) const271cdf0e10cSrcweir void ORadioButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
272cdf0e10cSrcweir {
273cdf0e10cSrcweir 	BEGIN_DESCRIBE_PROPERTIES( 1, OReferenceValueComponent )
274cdf0e10cSrcweir 		DECL_PROP1(TABINDEX,			sal_Int16,					BOUND);
275cdf0e10cSrcweir 	END_DESCRIBE_PROPERTIES();
276cdf0e10cSrcweir }
277cdf0e10cSrcweir 
278cdf0e10cSrcweir //------------------------------------------------------------------------------
getServiceName()279cdf0e10cSrcweir ::rtl::OUString SAL_CALL ORadioButtonModel::getServiceName() throw(RuntimeException)
280cdf0e10cSrcweir {
281cdf0e10cSrcweir 	return FRM_COMPONENT_RADIOBUTTON;	// old (non-sun) name for compatibility !
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir //------------------------------------------------------------------------------
write(const Reference<XObjectOutputStream> & _rxOutStream)285cdf0e10cSrcweir void SAL_CALL ORadioButtonModel::write(const Reference<XObjectOutputStream>& _rxOutStream)
286cdf0e10cSrcweir 	throw(IOException, RuntimeException)
287cdf0e10cSrcweir {
288cdf0e10cSrcweir 	OReferenceValueComponent::write(_rxOutStream);
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 	// Version
291cdf0e10cSrcweir 	_rxOutStream->writeShort(0x0003);
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 	// Properties
294cdf0e10cSrcweir 	_rxOutStream << getReferenceValue();
295cdf0e10cSrcweir 	_rxOutStream << (sal_Int16)getDefaultChecked();
296cdf0e10cSrcweir 	writeHelpTextCompatibly(_rxOutStream);
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 	// from version 0x0003 : common properties
299cdf0e10cSrcweir 	writeCommonProperties(_rxOutStream);
300cdf0e10cSrcweir }
301cdf0e10cSrcweir 
302cdf0e10cSrcweir //------------------------------------------------------------------------------
read(const Reference<XObjectInputStream> & _rxInStream)303cdf0e10cSrcweir void SAL_CALL ORadioButtonModel::read(const Reference<XObjectInputStream>& _rxInStream) throw(IOException, RuntimeException)
304cdf0e10cSrcweir {
305cdf0e10cSrcweir 	OReferenceValueComponent::read(_rxInStream);
306cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
307cdf0e10cSrcweir 
308cdf0e10cSrcweir 	// Version
309cdf0e10cSrcweir 	sal_uInt16 nVersion = _rxInStream->readShort();
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     ::rtl::OUString sReferenceValue;
312cdf0e10cSrcweir     sal_Int16 nDefaultChecked( 0 );
313cdf0e10cSrcweir 	switch (nVersion)
314cdf0e10cSrcweir 	{
315cdf0e10cSrcweir 		case 0x0001 :
316cdf0e10cSrcweir             _rxInStream >> sReferenceValue;
317cdf0e10cSrcweir             _rxInStream >> nDefaultChecked;
318cdf0e10cSrcweir             break;
319cdf0e10cSrcweir 		case 0x0002 :
320cdf0e10cSrcweir 			_rxInStream >> sReferenceValue;
321cdf0e10cSrcweir 			_rxInStream >> nDefaultChecked;
322cdf0e10cSrcweir 			readHelpTextCompatibly(_rxInStream);
323cdf0e10cSrcweir 			break;
324cdf0e10cSrcweir 		case 0x0003 :
325cdf0e10cSrcweir 			_rxInStream >> sReferenceValue;
326cdf0e10cSrcweir 			_rxInStream >> nDefaultChecked;
327cdf0e10cSrcweir 			readHelpTextCompatibly(_rxInStream);
328cdf0e10cSrcweir 			readCommonProperties(_rxInStream);
329cdf0e10cSrcweir 			break;
330cdf0e10cSrcweir 		default :
331cdf0e10cSrcweir 			DBG_ERROR("ORadioButtonModel::read : unknown version !");
332cdf0e10cSrcweir 			defaultCommonProperties();
333cdf0e10cSrcweir 			break;
334cdf0e10cSrcweir 	}
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     setReferenceValue( sReferenceValue );
337cdf0e10cSrcweir     setDefaultChecked( (ToggleState)nDefaultChecked );
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 	// Nach dem Lesen die Defaultwerte anzeigen
340cdf0e10cSrcweir 	if ( getControlSource().getLength() )
341cdf0e10cSrcweir 		// (not if we don't have a control source - the "State" property acts like it is persistent, then
342cdf0e10cSrcweir 		resetNoBroadcast();
343cdf0e10cSrcweir }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir //------------------------------------------------------------------------------
_propertyChanged(const PropertyChangeEvent & _rEvent)346cdf0e10cSrcweir void ORadioButtonModel::_propertyChanged(const PropertyChangeEvent& _rEvent) throw(RuntimeException)
347cdf0e10cSrcweir {
348cdf0e10cSrcweir 	if ( _rEvent.PropertyName.equals( PROPERTY_STATE ) )
349cdf0e10cSrcweir 	{
350cdf0e10cSrcweir 		if ( _rEvent.NewValue == (sal_Int16)1 )
351cdf0e10cSrcweir 		{
352cdf0e10cSrcweir 			// wenn sich mein Status auf 'checked' geaendert hat, muss ich alle meine Siblings, die in der selben Gruppe
353cdf0e10cSrcweir 			// sind wie ich, entsprechend zuruecksetzen
354cdf0e10cSrcweir 			Any aZero;
355cdf0e10cSrcweir 			aZero <<= (sal_Int16)0;
356cdf0e10cSrcweir 			SetSiblingPropsTo( PROPERTY_STATE, aZero );
357cdf0e10cSrcweir 		}
358cdf0e10cSrcweir 	}
359cdf0e10cSrcweir 
360cdf0e10cSrcweir     OReferenceValueComponent::_propertyChanged( _rEvent );
361cdf0e10cSrcweir }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir //------------------------------------------------------------------------------
translateDbColumnToControlValue()364cdf0e10cSrcweir Any ORadioButtonModel::translateDbColumnToControlValue()
365cdf0e10cSrcweir {
366cdf0e10cSrcweir     return makeAny( (sal_Int16)
367cdf0e10cSrcweir         ( ( m_xColumn->getString() == getReferenceValue() ) ? STATE_CHECK : STATE_NOCHECK )
368cdf0e10cSrcweir     );
369cdf0e10cSrcweir }
370cdf0e10cSrcweir 
371cdf0e10cSrcweir //------------------------------------------------------------------------------
translateExternalValueToControlValue(const Any & _rExternalValue) const372cdf0e10cSrcweir Any ORadioButtonModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
373cdf0e10cSrcweir {
374cdf0e10cSrcweir     Any aControlValue = OReferenceValueComponent::translateExternalValueToControlValue( _rExternalValue );
375cdf0e10cSrcweir     sal_Int16 nState = STATE_NOCHECK;
376cdf0e10cSrcweir     if ( ( aControlValue >>= nState ) && ( nState == STATE_DONTKNOW ) )
377cdf0e10cSrcweir         // radio buttons do not have the DONTKNOW state
378cdf0e10cSrcweir         aControlValue <<= (sal_Int16)STATE_NOCHECK;
379cdf0e10cSrcweir     return aControlValue;
380cdf0e10cSrcweir }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir //-----------------------------------------------------------------------------
commitControlValueToDbColumn(bool)383cdf0e10cSrcweir sal_Bool ORadioButtonModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
384cdf0e10cSrcweir {
385cdf0e10cSrcweir     Reference< XPropertySet > xField( getField() );
386cdf0e10cSrcweir 	OSL_PRECOND( xField.is(), "ORadioButtonModel::commitControlValueToDbColumn: not bound!" );
387cdf0e10cSrcweir 	if ( xField.is() )
388cdf0e10cSrcweir 	{
389cdf0e10cSrcweir 		try
390cdf0e10cSrcweir 		{
391cdf0e10cSrcweir 			sal_Int16 nValue = 0;
392cdf0e10cSrcweir 			m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) >>= nValue;
393cdf0e10cSrcweir 			if ( nValue == 1 )
394cdf0e10cSrcweir 				xField->setPropertyValue( PROPERTY_VALUE, makeAny( getReferenceValue() ) );
395cdf0e10cSrcweir 		}
396cdf0e10cSrcweir 		catch(Exception&)
397cdf0e10cSrcweir 		{
398cdf0e10cSrcweir 			DBG_ERROR("ORadioButtonModel::commitControlValueToDbColumn: could not commit !");
399cdf0e10cSrcweir 		}
400cdf0e10cSrcweir 	}
401cdf0e10cSrcweir 	return sal_True;
402cdf0e10cSrcweir }
403cdf0e10cSrcweir 
404cdf0e10cSrcweir //.........................................................................
405cdf0e10cSrcweir }
406cdf0e10cSrcweir //.........................................................................
407cdf0e10cSrcweir 
408