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