1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <TableWindowAccess.hxx>
21 #include <TableWindow.hxx>
22 #include <TableWindowListBox.hxx>
23 #include <JoinTableView.hxx>
24 #include <com/sun/star/accessibility/AccessibleRole.hpp>
25 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
26 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
27 #include <vcl/vclevent.hxx>
31 using namespace ::com::sun::star::accessibility
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::lang
;
34 using namespace ::com::sun::star
;
36 OTableWindowAccess::OTableWindowAccess(OTableWindow
* _pTable
)
37 :ImplInheritanceHelper(_pTable
)
41 void SAL_CALL
OTableWindowAccess::disposing()
44 VCLXAccessibleComponent::disposing();
46 void OTableWindowAccess::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
48 if ( rVclWindowEvent
.GetId() == VclEventId::ObjectDying
)
50 ::osl::MutexGuard
aGuard( m_aMutex
);
54 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent
);
56 OUString SAL_CALL
OTableWindowAccess::getImplementationName()
58 return u
"org.openoffice.comp.dbu.TableWindowAccessibility"_ustr
;
60 Sequence
< OUString
> SAL_CALL
OTableWindowAccess::getSupportedServiceNames()
62 return { u
"com.sun.star.accessibility.Accessible"_ustr
,
63 u
"com.sun.star.accessibility.AccessibleContext"_ustr
};
66 sal_Int64 SAL_CALL
OTableWindowAccess::getAccessibleChildCount( )
68 ::osl::MutexGuard
aGuard( m_aMutex
);
73 if(m_pTable
->GetListBox())
78 Reference
< XAccessible
> SAL_CALL
OTableWindowAccess::getAccessibleChild( sal_Int64 i
)
80 ::osl::MutexGuard
aGuard( m_aMutex
);
81 Reference
< XAccessible
> aRet
;
82 if (m_pTable
&& !m_pTable
->isDisposed())
88 VclPtr
<OTableWindowTitle
> xCtrl(m_pTable
->GetTitleCtrl());
90 aRet
= xCtrl
->GetAccessible();
95 VclPtr
<OTableWindowListBox
> xCtrl(m_pTable
->GetListBox());
97 aRet
= xCtrl
->GetAccessible();
101 throw IndexOutOfBoundsException();
106 sal_Int64 SAL_CALL
OTableWindowAccess::getAccessibleIndexInParent( )
108 ::osl::MutexGuard
aGuard( m_aMutex
);
109 sal_Int64 nIndex
= -1;
112 // search the position of our table window in the table window map
113 bool bFoundElem
= false;
114 for (auto const& tabWin
: m_pTable
->getTableView()->GetTabWinMap())
116 if (tabWin
.second
== m_pTable
)
123 nIndex
= bFoundElem
? nIndex
: -1;
127 sal_Int16 SAL_CALL
OTableWindowAccess::getAccessibleRole( )
129 return AccessibleRole::PANEL
; // ? or may be an AccessibleRole::WINDOW
131 Reference
< XAccessibleRelationSet
> SAL_CALL
OTableWindowAccess::getAccessibleRelationSet( )
133 ::osl::MutexGuard
aGuard( m_aMutex
);
136 // XAccessibleComponent
137 Reference
< XAccessible
> SAL_CALL
OTableWindowAccess::getAccessibleAtPoint( const awt::Point
& _aPoint
)
139 ::osl::MutexGuard
aGuard( m_aMutex
);
140 Reference
< XAccessible
> aRet
;
141 if(m_pTable
&& !m_pTable
->isDisposed())
143 AbsoluteScreenPixelPoint
aPoint(_aPoint
.X
,_aPoint
.Y
);
144 AbsoluteScreenPixelRectangle
aRect(m_pTable
->GetDesktopRectPixel());
145 if( aRect
.Contains(aPoint
) )
147 else if( m_pTable
->GetListBox()->GetDesktopRectPixel().Contains(aPoint
))
148 aRet
= m_pTable
->GetListBox()->GetAccessible();
152 Reference
< XAccessible
> OTableWindowAccess::getParentChild(sal_Int64 _nIndex
)
154 Reference
< XAccessible
> xReturn
;
155 Reference
< XAccessible
> xParent
= getAccessibleParent();
158 Reference
< XAccessibleContext
> xParentContext
= xParent
->getAccessibleContext();
159 if ( xParentContext
.is() )
161 xReturn
= xParentContext
->getAccessibleChild(_nIndex
);
167 sal_Int32 SAL_CALL
OTableWindowAccess::getRelationCount( )
169 ::osl::MutexGuard
aGuard( m_aMutex
);
170 return m_pTable
? m_pTable
->getTableView()->getConnectionCount(m_pTable
) : sal_Int32(0);
172 AccessibleRelation SAL_CALL
OTableWindowAccess::getRelation( sal_Int32 nIndex
)
174 ::osl::MutexGuard
aGuard( m_aMutex
);
175 if( nIndex
< 0 || nIndex
>= getRelationCount() )
176 throw IndexOutOfBoundsException();
178 AccessibleRelation aRet
;
181 OJoinTableView
* pView
= m_pTable
->getTableView();
182 auto aIter
= pView
->getTableConnections(m_pTable
) + nIndex
;
183 aRet
.TargetSet
= { getParentChild(aIter
- pView
->getTableConnections().begin()) };
184 aRet
.RelationType
= AccessibleRelationType_CONTROLLER_FOR
;
188 sal_Bool SAL_CALL
OTableWindowAccess::containsRelation(AccessibleRelationType eRelationType
)
190 ::osl::MutexGuard
aGuard( m_aMutex
);
191 return AccessibleRelationType_CONTROLLER_FOR
== eRelationType
192 && m_pTable
&& m_pTable
->getTableView()->ExistsAConn(m_pTable
);
194 AccessibleRelation SAL_CALL
OTableWindowAccess::getRelationByType(AccessibleRelationType eRelationType
)
196 ::osl::MutexGuard
aGuard( m_aMutex
);
197 if (AccessibleRelationType_CONTROLLER_FOR
== eRelationType
&& m_pTable
)
199 OJoinTableView
* pView
= m_pTable
->getTableView();
200 const auto& rConnectionList
= pView
->getTableConnections();
202 auto aIter
= pView
->getTableConnections(m_pTable
);
203 auto aEnd
= rConnectionList
.end();
204 std::vector
< Reference
<css::accessibility::XAccessible
> > aRelations
;
205 aRelations
.reserve(5); // just guessing
206 // TODO JNA aIter comes from pView->getTableConnections(m_pTable)
207 // and aEnd comes from pView->getTableConnections().end()
208 for (; aIter
!= aEnd
; ++aIter
)
210 uno::Reference
<css::accessibility::XAccessible
> xAccessible(
211 getParentChild(aIter
- rConnectionList
.begin()));
212 aRelations
.push_back(xAccessible
);
215 Sequence
<Reference
<css::accessibility::XAccessible
>> aSeq(aRelations
.data(), aRelations
.size());
216 return AccessibleRelation(AccessibleRelationType_CONTROLLER_FOR
, aSeq
);
218 return AccessibleRelation();
220 OUString SAL_CALL
OTableWindowAccess::getTitledBorderText( )
222 return getAccessibleName( );
224 OUString SAL_CALL
OTableWindowAccess::getAccessibleName( )
226 ::osl::MutexGuard
aGuard( m_aMutex
);
227 OUString sAccessibleName
;
229 sAccessibleName
= m_pTable
->getTitle();
230 return sAccessibleName
;
232 Reference
< XAccessibleContext
> SAL_CALL
OTableWindowAccess::getAccessibleContext( )
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */