xref: /trunk/main/accessibility/source/extended/AccessibleBrowseBoxHeaderCell.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
27 #include "accessibility/extended/AccessibleBrowseBoxHeaderCell.hxx"
28 #include <svtools/accessibletableprovider.hxx>
29 #include "accessibility/extended/AccessibleBrowseBox.hxx"
30 
31 namespace accessibility
32 {
33     using namespace ::com::sun::star::accessibility;
34     using namespace ::com::sun::star::lang;
35     using namespace ::com::sun::star::uno;
36     using namespace ::svt;
37 
AccessibleBrowseBoxHeaderCell(sal_Int32 _nColumnRowId,const Reference<XAccessible> & rxParent,IAccessibleTableProvider & rBrowseBox,const::com::sun::star::uno::Reference<::com::sun::star::awt::XWindow> & _xFocusWindow,AccessibleBrowseBoxObjType eObjType)38 AccessibleBrowseBoxHeaderCell::AccessibleBrowseBoxHeaderCell(sal_Int32 _nColumnRowId,
39                                   const Reference< XAccessible >& rxParent,
40                                   IAccessibleTableProvider& rBrowseBox,
41                                   const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& _xFocusWindow,
42                                   AccessibleBrowseBoxObjType eObjType)
43 : BrowseBoxAccessibleElement(rxParent,
44                           rBrowseBox,
45                           _xFocusWindow,
46                           eObjType,
47                           rBrowseBox.GetAccessibleObjectName( eObjType ,_nColumnRowId),
48                           rBrowseBox.GetAccessibleObjectDescription( eObjType ,_nColumnRowId))
49 , m_nColumnRowId(_nColumnRowId)
50 {
51 }
52 /** Creates a new AccessibleStateSetHelper and fills it with states of the
53     current object.
54     @return
55         A filled AccessibleStateSetHelper.
56 */
implCreateStateSetHelper()57 ::utl::AccessibleStateSetHelper* AccessibleBrowseBoxHeaderCell::implCreateStateSetHelper()
58 {
59     ::osl::MutexGuard aGuard( getOslMutex() );
60     ::utl::AccessibleStateSetHelper*
61         pStateSetHelper = new ::utl::AccessibleStateSetHelper;
62 
63     if( isAlive() )
64     {
65         // SHOWING done with mxParent
66         if( implIsShowing() )
67             pStateSetHelper->AddState( AccessibleStateType::SHOWING );
68         mpBrowseBox->FillAccessibleStateSet( *pStateSetHelper, getType() );
69         BBSolarGuard aSolarGuard;
70         pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
71         pStateSetHelper->AddState( AccessibleStateType::FOCUSABLE );
72         pStateSetHelper->AddState( AccessibleStateType::TRANSIENT );
73         pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
74 
75         sal_Bool bSelected = isRowBarCell() ? mpBrowseBox->IsRowSelected(m_nColumnRowId) : mpBrowseBox->IsColumnSelected(m_nColumnRowId);
76         if ( bSelected )
77             pStateSetHelper->AddState( AccessibleStateType::SELECTED );
78     }
79     else
80         pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
81 
82     return pStateSetHelper;
83 }
84 // -----------------------------------------------------------------------------
85 /** @return
86         The count of visible children.
87 */
getAccessibleChildCount()88 sal_Int32 SAL_CALL AccessibleBrowseBoxHeaderCell::getAccessibleChildCount()
89 {
90     return 0;
91 }
92 // -----------------------------------------------------------------------------
93 
94 /** @return
95         The XAccessible interface of the specified child.
96 */
getAccessibleChild(sal_Int32)97 Reference<XAccessible > SAL_CALL AccessibleBrowseBoxHeaderCell::getAccessibleChild( sal_Int32 )
98 {
99     throw IndexOutOfBoundsException();
100 }
101 // -----------------------------------------------------------------------------
102 
103 /** Grabs the focus to the column header. */
grabFocus()104 void SAL_CALL AccessibleBrowseBoxHeaderCell::grabFocus()
105 {
106     BBSolarGuard aSolarGuard;
107     ::osl::MutexGuard aGuard( getOslMutex() );
108     ensureIsAlive();
109     if ( isRowBarCell() )
110         mpBrowseBox->SelectRow(m_nColumnRowId);
111     else
112         mpBrowseBox->SelectColumn(static_cast<sal_uInt16>(m_nColumnRowId)); //!!!
113 }
114 // -----------------------------------------------------------------------------
115 /** @return
116         The name of this class.
117 */
getImplementationName()118 ::rtl::OUString SAL_CALL AccessibleBrowseBoxHeaderCell::getImplementationName()
119 {
120     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.AccessibleBrowseBoxHeaderCell" ) );
121 }
122 // -----------------------------------------------------------------------------
123 namespace
124 {
getRectangle(IAccessibleTableProvider * _pBrowseBox,sal_Int32 _nRowColIndex,sal_Bool _bOnScreen,sal_Bool _bRowBar)125     Rectangle getRectangle(IAccessibleTableProvider* _pBrowseBox,sal_Int32 _nRowColIndex, sal_Bool _bOnScreen,sal_Bool _bRowBar)
126     {
127         sal_Int32 nRow  = 0;
128         sal_uInt16 nCol = (sal_uInt16)_nRowColIndex;
129         if ( _bRowBar )
130         {
131             nRow = _nRowColIndex + 1;
132             nCol = 0;
133         }
134 
135         Rectangle aRet(_pBrowseBox->GetFieldRectPixelAbs( nRow , nCol, sal_True, _bOnScreen));
136         return Rectangle(aRet.TopLeft() - Point(0,aRet.GetHeight()),aRet.GetSize());
137     }
138 }
139 
implGetBoundingBox()140 Rectangle AccessibleBrowseBoxHeaderCell::implGetBoundingBox()
141 {
142     return getRectangle(mpBrowseBox,m_nColumnRowId,sal_False,isRowBarCell());
143 }
144 // -----------------------------------------------------------------------------
145 
implGetBoundingBoxOnScreen()146 Rectangle AccessibleBrowseBoxHeaderCell::implGetBoundingBoxOnScreen()
147 {
148     return getRectangle(mpBrowseBox,m_nColumnRowId,sal_True,isRowBarCell());
149 }
150 // -----------------------------------------------------------------------------
getAccessibleIndexInParent()151 sal_Int32 SAL_CALL AccessibleBrowseBoxHeaderCell::getAccessibleIndexInParent()
152 {
153     ::osl::MutexGuard aGuard( getOslMutex() );
154     ensureIsAlive();
155     sal_Int32 nIndex = m_nColumnRowId;
156     if ( mpBrowseBox->HasRowHeader() )
157         --nIndex;
158     return nIndex;
159 }
160 // -----------------------------------------------------------------------------
161 } // namespace accessibility
162 // -----------------------------------------------------------------------------
163