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 
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 */
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 
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 */
88 sal_Int32 SAL_CALL AccessibleBrowseBoxHeaderCell::getAccessibleChildCount()
89 	throw ( RuntimeException )
90 {
91 	return 0;
92 }
93 // -----------------------------------------------------------------------------
94 
95 /** @return
96 		The XAccessible interface of the specified child.
97 */
98 Reference<XAccessible > SAL_CALL AccessibleBrowseBoxHeaderCell::getAccessibleChild( sal_Int32 )
99 	throw ( IndexOutOfBoundsException,RuntimeException )
100 {
101 	throw IndexOutOfBoundsException();
102 }
103 // -----------------------------------------------------------------------------
104 
105 /** Grabs the focus to the column header. */
106 void SAL_CALL AccessibleBrowseBoxHeaderCell::grabFocus()
107 	throw ( ::com::sun::star::uno::RuntimeException )
108 {
109 	BBSolarGuard aSolarGuard;
110 	::osl::MutexGuard aGuard( getOslMutex() );
111 	ensureIsAlive();
112 	if ( isRowBarCell() )
113 		mpBrowseBox->SelectRow(m_nColumnRowId);
114 	else
115 		mpBrowseBox->SelectColumn(static_cast<sal_uInt16>(m_nColumnRowId)); //!!!
116 }
117 // -----------------------------------------------------------------------------
118 /** @return
119 		The name of this class.
120 */
121 ::rtl::OUString SAL_CALL AccessibleBrowseBoxHeaderCell::getImplementationName()
122 	throw ( ::com::sun::star::uno::RuntimeException )
123 {
124 	return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.AccessibleBrowseBoxHeaderCell" ) );
125 }
126 // -----------------------------------------------------------------------------
127 namespace
128 {
129 	Rectangle getRectangle(IAccessibleTableProvider* _pBrowseBox,sal_Int32 _nRowColIndex, sal_Bool _bOnScreen,sal_Bool _bRowBar)
130 	{
131 		sal_Int32 nRow  = 0;
132 		sal_uInt16 nCol =  (sal_uInt16)_nRowColIndex;
133 		if ( _bRowBar )
134 		{
135 			nRow = _nRowColIndex + 1;
136 			nCol = 0;
137 		}
138 
139 		Rectangle aRet(_pBrowseBox->GetFieldRectPixelAbs( nRow , nCol, sal_True, _bOnScreen));
140 		return Rectangle(aRet.TopLeft() - Point(0,aRet.GetHeight()),aRet.GetSize());
141 	}
142 }
143 
144 Rectangle AccessibleBrowseBoxHeaderCell::implGetBoundingBox()
145 {
146 	return getRectangle(mpBrowseBox,m_nColumnRowId,sal_False,isRowBarCell());
147 }
148 // -----------------------------------------------------------------------------
149 
150 Rectangle AccessibleBrowseBoxHeaderCell::implGetBoundingBoxOnScreen()
151 {
152 	return getRectangle(mpBrowseBox,m_nColumnRowId,sal_True,isRowBarCell());
153 }
154 // -----------------------------------------------------------------------------
155 sal_Int32 SAL_CALL AccessibleBrowseBoxHeaderCell::getAccessibleIndexInParent()
156     throw ( RuntimeException )
157 {
158     ::osl::MutexGuard aGuard( getOslMutex() );
159     ensureIsAlive();
160 	sal_Int32 nIndex = m_nColumnRowId;
161 	if ( mpBrowseBox->HasRowHeader() )
162 		--nIndex;
163 	return nIndex;
164 }
165 // -----------------------------------------------------------------------------
166 } // namespace accessibility
167 // -----------------------------------------------------------------------------
168 
169 
170