10841af79SAndrew Rist /**************************************************************
2*d69df039Smseidel  *
30841af79SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
40841af79SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
50841af79SAndrew Rist  * distributed with this work for additional information
60841af79SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
70841af79SAndrew Rist  * to you under the Apache License, Version 2.0 (the
80841af79SAndrew Rist  * "License"); you may not use this file except in compliance
90841af79SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d69df039Smseidel  *
110841af79SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d69df039Smseidel  *
130841af79SAndrew Rist  * Unless required by applicable law or agreed to in writing,
140841af79SAndrew Rist  * software distributed under the License is distributed on an
150841af79SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
160841af79SAndrew Rist  * KIND, either express or implied.  See the License for the
170841af79SAndrew Rist  * specific language governing permissions and limitations
180841af79SAndrew Rist  * under the License.
19*d69df039Smseidel  *
200841af79SAndrew Rist  *************************************************************/
210841af79SAndrew Rist 
220841af79SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_accessibility.hxx"
26cdf0e10cSrcweir #include <accessibility/extended/AccessibleBrowseBoxCheckBoxCell.hxx>
27cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
28cdf0e10cSrcweir #include <svtools/accessibletableprovider.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir namespace accessibility
31cdf0e10cSrcweir {
32cdf0e10cSrcweir 	using namespace com::sun::star::accessibility;
33cdf0e10cSrcweir 	using namespace com::sun::star::uno;
34cdf0e10cSrcweir 	using namespace com::sun::star::accessibility::AccessibleEventId;
35*d69df039Smseidel 	using namespace ::svt;
36cdf0e10cSrcweir 
AccessibleCheckBoxCell(const Reference<XAccessible> & _rxParent,IAccessibleTableProvider & _rBrowseBox,const::com::sun::star::uno::Reference<::com::sun::star::awt::XWindow> & _xFocusWindow,sal_Int32 _nRowPos,sal_uInt16 _nColPos,const TriState & _eState,sal_Bool _bEnabled,sal_Bool _bIsTriState)37cdf0e10cSrcweir 	AccessibleCheckBoxCell::AccessibleCheckBoxCell(const Reference<XAccessible >& _rxParent,
38cdf0e10cSrcweir 								IAccessibleTableProvider& _rBrowseBox,
39cdf0e10cSrcweir 								const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& _xFocusWindow,
40cdf0e10cSrcweir 								sal_Int32 _nRowPos,
41cdf0e10cSrcweir 								sal_uInt16 _nColPos
42cdf0e10cSrcweir 								,const TriState& _eState,
43cdf0e10cSrcweir 								sal_Bool _bEnabled,
44cdf0e10cSrcweir 								sal_Bool _bIsTriState)
45*d69df039Smseidel 		:AccessibleBrowseBoxCell(_rxParent, _rBrowseBox, _xFocusWindow, _nRowPos, _nColPos, BBTYPE_CHECKBOXCELL)
46cdf0e10cSrcweir 		,m_eState(_eState)
47cdf0e10cSrcweir 		,m_bEnabled(_bEnabled)
48cdf0e10cSrcweir 		,m_bIsTriState(_bIsTriState)
49cdf0e10cSrcweir 	{
50cdf0e10cSrcweir 	}
51cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2(AccessibleCheckBoxCell,AccessibleBrowseBoxCell,AccessibleCheckBoxCell_BASE)52cdf0e10cSrcweir 	IMPLEMENT_FORWARD_XINTERFACE2( AccessibleCheckBoxCell, AccessibleBrowseBoxCell, AccessibleCheckBoxCell_BASE )
53cdf0e10cSrcweir 		// -----------------------------------------------------------------------------
54cdf0e10cSrcweir 	IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleCheckBoxCell, AccessibleBrowseBoxCell, AccessibleCheckBoxCell_BASE )
55cdf0e10cSrcweir 	//--------------------------------------------------------------------
56cdf0e10cSrcweir 	Reference< XAccessibleContext > SAL_CALL AccessibleCheckBoxCell::getAccessibleContext(  ) throw (RuntimeException)
57cdf0e10cSrcweir 	{
58cdf0e10cSrcweir 		ensureIsAlive();
59cdf0e10cSrcweir 		return this;
60cdf0e10cSrcweir 	}
61cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
implCreateStateSetHelper()62cdf0e10cSrcweir 	::utl::AccessibleStateSetHelper* AccessibleCheckBoxCell::implCreateStateSetHelper()
63cdf0e10cSrcweir 	{
64*d69df039Smseidel 		::utl::AccessibleStateSetHelper* pStateSetHelper =
65*d69df039Smseidel 			AccessibleBrowseBoxCell::implCreateStateSetHelper();
66*d69df039Smseidel 		if( isAlive() )
67*d69df039Smseidel 		{
68*d69df039Smseidel 			mpBrowseBox->FillAccessibleStateSetForCell(
69*d69df039Smseidel 				*pStateSetHelper, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
70*d69df039Smseidel 			if ( m_eState == STATE_CHECK )
71*d69df039Smseidel 				pStateSetHelper->AddState( AccessibleStateType::CHECKED );
72*d69df039Smseidel 		}
73*d69df039Smseidel 		return pStateSetHelper;
74cdf0e10cSrcweir 	}
75cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
76cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
77cdf0e10cSrcweir 	// XAccessibleValue
78cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
79cdf0e10cSrcweir 
getCurrentValue()80cdf0e10cSrcweir 	Any SAL_CALL AccessibleCheckBoxCell::getCurrentValue(  ) throw (RuntimeException)
81cdf0e10cSrcweir 	{
82cdf0e10cSrcweir 		::osl::MutexGuard aGuard( getOslMutex() );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 		sal_Int32 nValue = 0;
85cdf0e10cSrcweir 		switch( m_eState )
86cdf0e10cSrcweir 		{
87cdf0e10cSrcweir 			case STATE_NOCHECK:
88cdf0e10cSrcweir 				nValue = 0;
89cdf0e10cSrcweir 				break;
90cdf0e10cSrcweir 			case STATE_CHECK:
91cdf0e10cSrcweir 				nValue = 1;
92cdf0e10cSrcweir 				break;
93cdf0e10cSrcweir 			case STATE_DONTKNOW:
94cdf0e10cSrcweir 				nValue = 2;
95cdf0e10cSrcweir 				break;
96cdf0e10cSrcweir 		}
97cdf0e10cSrcweir 		return makeAny(nValue);
98cdf0e10cSrcweir 	}
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
101cdf0e10cSrcweir 
setCurrentValue(const Any &)102cdf0e10cSrcweir 	sal_Bool SAL_CALL AccessibleCheckBoxCell::setCurrentValue( const Any& ) throw (RuntimeException)
103cdf0e10cSrcweir 	{
104cdf0e10cSrcweir 		return sal_False;
105cdf0e10cSrcweir 	}
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
108cdf0e10cSrcweir 
getMaximumValue()109cdf0e10cSrcweir 	Any SAL_CALL AccessibleCheckBoxCell::getMaximumValue(  ) throw (RuntimeException)
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir 		::osl::MutexGuard aGuard( getOslMutex() );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 		Any aValue;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 		if ( m_bIsTriState )
116cdf0e10cSrcweir 			aValue <<= (sal_Int32) 2;
117cdf0e10cSrcweir 		else
118cdf0e10cSrcweir 			aValue <<= (sal_Int32) 1;
119*d69df039Smseidel 
120cdf0e10cSrcweir 		return aValue;
121cdf0e10cSrcweir 	}
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
124cdf0e10cSrcweir 
getMinimumValue()125cdf0e10cSrcweir 	Any SAL_CALL AccessibleCheckBoxCell::getMinimumValue(  ) throw (RuntimeException)
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 		Any aValue;
128cdf0e10cSrcweir 		aValue <<= (sal_Int32) 0;
129*d69df039Smseidel 
130cdf0e10cSrcweir 		return aValue;
131cdf0e10cSrcweir 	}
132cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
133cdf0e10cSrcweir 	// XAccessibleContext
getAccessibleChildCount()134cdf0e10cSrcweir 	sal_Int32 SAL_CALL AccessibleCheckBoxCell::getAccessibleChildCount(  ) throw (::com::sun::star::uno::RuntimeException)
135cdf0e10cSrcweir 	{
136cdf0e10cSrcweir 		return 0;
137cdf0e10cSrcweir 	}
138cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
getAccessibleChild(sal_Int32)139cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL AccessibleCheckBoxCell::getAccessibleChild( sal_Int32 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
140cdf0e10cSrcweir 	{
141cdf0e10cSrcweir 		throw ::com::sun::star::lang::IndexOutOfBoundsException();
142cdf0e10cSrcweir 	}
143cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
getImplementationName()144cdf0e10cSrcweir 	::rtl::OUString SAL_CALL AccessibleCheckBoxCell::getImplementationName() throw ( ::com::sun::star::uno::RuntimeException )
145cdf0e10cSrcweir 	{
146cdf0e10cSrcweir 		return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.TableCheckBoxCell" ) );
147cdf0e10cSrcweir 	}
148*d69df039Smseidel 	// -----------------------------------------------------------------------------
getAccessibleIndexInParent()149*d69df039Smseidel 	sal_Int32 SAL_CALL AccessibleCheckBoxCell::getAccessibleIndexInParent()
150*d69df039Smseidel 			throw ( ::com::sun::star::uno::RuntimeException )
151*d69df039Smseidel 	{
152*d69df039Smseidel 		::osl::MutexGuard aGuard( getOslMutex() );
153cdf0e10cSrcweir 
154*d69df039Smseidel 		return ( getRowPos() * mpBrowseBox->GetColumnCount() ) + getColumnPos();
155*d69df039Smseidel 	}
156*d69df039Smseidel 	// -----------------------------------------------------------------------------
SetChecked(sal_Bool _bChecked)157*d69df039Smseidel 	void AccessibleCheckBoxCell::SetChecked( sal_Bool _bChecked )
158*d69df039Smseidel 	{
159*d69df039Smseidel 		m_eState = _bChecked ? STATE_CHECK : STATE_NOCHECK;
160*d69df039Smseidel 		Any aOldValue, aNewValue;
161*d69df039Smseidel 		if ( _bChecked )
162*d69df039Smseidel 			aNewValue <<= AccessibleStateType::CHECKED;
163*d69df039Smseidel 		else
164*d69df039Smseidel 			aOldValue <<= AccessibleStateType::CHECKED;
165*d69df039Smseidel 		commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
166*d69df039Smseidel 	}
167*d69df039Smseidel }
168