Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / extended / AccessibleBrowseBoxCheckBoxCell.cxx
blob90d011a333f28932dd032c19f48e70a646efcdf3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <accessibility/extended/AccessibleBrowseBoxCheckBoxCell.hxx>
21 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
22 #include <svtools/accessibletableprovider.hxx>
24 namespace accessibility
26 using namespace com::sun::star::accessibility;
27 using namespace com::sun::star::uno;
28 using namespace com::sun::star::accessibility::AccessibleEventId;
29 using namespace ::svt;
31 AccessibleCheckBoxCell::AccessibleCheckBoxCell(const Reference<XAccessible >& _rxParent,
32 IAccessibleTableProvider& _rBrowseBox,
33 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& _xFocusWindow,
34 sal_Int32 _nRowPos,
35 sal_uInt16 _nColPos
36 ,const TriState& _eState,
37 bool _bIsTriState)
38 :AccessibleBrowseBoxCell(_rxParent, _rBrowseBox, _xFocusWindow, _nRowPos, _nColPos, BBTYPE_CHECKBOXCELL)
39 ,m_eState(_eState)
40 ,m_bIsTriState(_bIsTriState)
43 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleCheckBoxCell, AccessibleBrowseBoxCell, AccessibleCheckBoxCell_BASE )
45 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleCheckBoxCell, AccessibleBrowseBoxCell, AccessibleCheckBoxCell_BASE )
47 Reference< XAccessibleContext > SAL_CALL AccessibleCheckBoxCell::getAccessibleContext( ) throw (RuntimeException, std::exception)
49 ensureIsAlive();
50 return this;
53 ::utl::AccessibleStateSetHelper* AccessibleCheckBoxCell::implCreateStateSetHelper()
55 ::utl::AccessibleStateSetHelper* pStateSetHelper =
56 AccessibleBrowseBoxCell::implCreateStateSetHelper();
57 if( isAlive() )
59 mpBrowseBox->FillAccessibleStateSetForCell(
60 *pStateSetHelper, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
61 if ( m_eState == TRISTATE_TRUE )
62 pStateSetHelper->AddState( AccessibleStateType::CHECKED );
64 return pStateSetHelper;
67 // XAccessibleValue
69 Any SAL_CALL AccessibleCheckBoxCell::getCurrentValue( ) throw (RuntimeException, std::exception)
71 ::osl::MutexGuard aGuard( getOslMutex() );
73 sal_Int32 nValue = 0;
74 switch( m_eState )
76 case TRISTATE_FALSE:
77 nValue = 0;
78 break;
79 case TRISTATE_TRUE:
80 nValue = 1;
81 break;
82 case TRISTATE_INDET:
83 nValue = 2;
84 break;
86 return makeAny(nValue);
89 sal_Bool SAL_CALL AccessibleCheckBoxCell::setCurrentValue( const Any& ) throw (RuntimeException, std::exception)
91 return false;
94 Any SAL_CALL AccessibleCheckBoxCell::getMaximumValue( ) throw (RuntimeException, std::exception)
96 ::osl::MutexGuard aGuard( getOslMutex() );
98 Any aValue;
100 if ( m_bIsTriState )
101 aValue <<= (sal_Int32) 2;
102 else
103 aValue <<= (sal_Int32) 1;
105 return aValue;
108 Any SAL_CALL AccessibleCheckBoxCell::getMinimumValue( ) throw (RuntimeException, std::exception)
110 Any aValue;
111 aValue <<= (sal_Int32) 0;
113 return aValue;
116 // XAccessibleContext
117 sal_Int32 SAL_CALL AccessibleCheckBoxCell::getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
119 return 0;
122 ::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, std::exception)
124 throw ::com::sun::star::lang::IndexOutOfBoundsException();
127 OUString SAL_CALL AccessibleCheckBoxCell::getImplementationName() throw ( ::com::sun::star::uno::RuntimeException, std::exception )
129 return OUString( "com.sun.star.comp.svtools.TableCheckBoxCell" );
132 sal_Int32 SAL_CALL AccessibleCheckBoxCell::getAccessibleIndexInParent()
133 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
135 ::osl::MutexGuard aGuard( getOslMutex() );
137 return ( getRowPos() * mpBrowseBox->GetColumnCount() ) + getColumnPos();
140 void AccessibleCheckBoxCell::SetChecked( bool _bChecked )
142 m_eState = _bChecked ? TRISTATE_TRUE : TRISTATE_FALSE;
143 Any aOldValue, aNewValue;
144 if ( _bChecked )
145 aNewValue <<= AccessibleStateType::CHECKED;
146 else
147 aOldValue <<= AccessibleStateType::CHECKED;
148 commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */