xref: /trunk/main/accessibility/source/extended/AccessibleBrowseBoxCheckBoxCell.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_accessibility.hxx"
30 #include <accessibility/extended/AccessibleBrowseBoxCheckBoxCell.hxx>
31 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
32 #include <svtools/accessibletableprovider.hxx>
33 
34 namespace accessibility
35 {
36     using namespace com::sun::star::accessibility;
37     using namespace com::sun::star::uno;
38     using namespace com::sun::star::accessibility::AccessibleEventId;
39     using namespace ::svt;
40 
41     AccessibleCheckBoxCell::AccessibleCheckBoxCell(const Reference<XAccessible >& _rxParent,
42                                 IAccessibleTableProvider& _rBrowseBox,
43                                 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& _xFocusWindow,
44                                 sal_Int32 _nRowPos,
45                                 sal_uInt16 _nColPos
46                                 ,const TriState& _eState,
47                                 sal_Bool _bEnabled,
48                                 sal_Bool _bIsTriState)
49         :AccessibleBrowseBoxCell(_rxParent, _rBrowseBox, _xFocusWindow, _nRowPos, _nColPos, BBTYPE_CHECKBOXCELL)
50         ,m_eState(_eState)
51         ,m_bEnabled(_bEnabled)
52         ,m_bIsTriState(_bIsTriState)
53     {
54     }
55     // -----------------------------------------------------------------------------
56     IMPLEMENT_FORWARD_XINTERFACE2( AccessibleCheckBoxCell, AccessibleBrowseBoxCell, AccessibleCheckBoxCell_BASE )
57         // -----------------------------------------------------------------------------
58     IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleCheckBoxCell, AccessibleBrowseBoxCell, AccessibleCheckBoxCell_BASE )
59     //--------------------------------------------------------------------
60     Reference< XAccessibleContext > SAL_CALL AccessibleCheckBoxCell::getAccessibleContext(  ) throw (RuntimeException)
61     {
62         ensureIsAlive();
63         return this;
64     }
65     // -----------------------------------------------------------------------------
66     ::utl::AccessibleStateSetHelper* AccessibleCheckBoxCell::implCreateStateSetHelper()
67     {
68         ::utl::AccessibleStateSetHelper* pStateSetHelper =
69             AccessibleBrowseBoxCell::implCreateStateSetHelper();
70         if( isAlive() )
71         {
72             mpBrowseBox->FillAccessibleStateSetForCell(
73                 *pStateSetHelper, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
74             if ( m_eState == STATE_CHECK )
75                 pStateSetHelper->AddState( AccessibleStateType::CHECKED );
76         }
77         return pStateSetHelper;
78     }
79     // -----------------------------------------------------------------------------
80     // -----------------------------------------------------------------------------
81     // XAccessibleValue
82     // -----------------------------------------------------------------------------
83 
84     Any SAL_CALL AccessibleCheckBoxCell::getCurrentValue(  ) throw (RuntimeException)
85     {
86         ::osl::MutexGuard aGuard( getOslMutex() );
87 
88         sal_Int32 nValue = 0;
89         switch( m_eState )
90         {
91             case STATE_NOCHECK:
92                 nValue = 0;
93                 break;
94             case STATE_CHECK:
95                 nValue = 1;
96                 break;
97             case STATE_DONTKNOW:
98                 nValue = 2;
99                 break;
100         }
101         return makeAny(nValue);
102     }
103 
104     // -----------------------------------------------------------------------------
105 
106     sal_Bool SAL_CALL AccessibleCheckBoxCell::setCurrentValue( const Any& ) throw (RuntimeException)
107     {
108         return sal_False;
109     }
110 
111     // -----------------------------------------------------------------------------
112 
113     Any SAL_CALL AccessibleCheckBoxCell::getMaximumValue(  ) throw (RuntimeException)
114     {
115         ::osl::MutexGuard aGuard( getOslMutex() );
116 
117         Any aValue;
118 
119         if ( m_bIsTriState )
120             aValue <<= (sal_Int32) 2;
121         else
122             aValue <<= (sal_Int32) 1;
123 
124         return aValue;
125     }
126 
127     // -----------------------------------------------------------------------------
128 
129     Any SAL_CALL AccessibleCheckBoxCell::getMinimumValue(  ) throw (RuntimeException)
130     {
131         Any aValue;
132         aValue <<= (sal_Int32) 0;
133 
134         return aValue;
135     }
136     // -----------------------------------------------------------------------------
137     // XAccessibleContext
138     sal_Int32 SAL_CALL AccessibleCheckBoxCell::getAccessibleChildCount(  ) throw (::com::sun::star::uno::RuntimeException)
139     {
140         return 0;
141     }
142     // -----------------------------------------------------------------------------
143     ::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)
144     {
145         throw ::com::sun::star::lang::IndexOutOfBoundsException();
146     }
147     // -----------------------------------------------------------------------------
148     ::rtl::OUString SAL_CALL AccessibleCheckBoxCell::getImplementationName() throw ( ::com::sun::star::uno::RuntimeException )
149     {
150         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.TableCheckBoxCell" ) );
151     }
152     // -----------------------------------------------------------------------------
153     sal_Int32 SAL_CALL AccessibleCheckBoxCell::getAccessibleIndexInParent()
154             throw ( ::com::sun::star::uno::RuntimeException )
155     {
156         ::osl::MutexGuard aGuard( getOslMutex() );
157 
158         return ( getRowPos() * mpBrowseBox->GetColumnCount() ) + getColumnPos();
159     }
160     // -----------------------------------------------------------------------------
161     void AccessibleCheckBoxCell::SetChecked( sal_Bool _bChecked )
162     {
163         m_eState = _bChecked ? STATE_CHECK : STATE_NOCHECK;
164         Any aOldValue, aNewValue;
165         if ( _bChecked )
166             aNewValue <<= AccessibleStateType::CHECKED;
167         else
168             aOldValue <<= AccessibleStateType::CHECKED;
169         commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
170     }
171 }
172 
173