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::beans
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::com::sun::star
;
37 OTableWindowAccess::OTableWindowAccess(OTableWindow
* _pTable
)
38 :ImplInheritanceHelper(_pTable
->GetComponentInterface().is() ? _pTable
->GetWindowPeer() : nullptr)
42 void SAL_CALL
OTableWindowAccess::disposing()
45 VCLXAccessibleComponent::disposing();
47 void OTableWindowAccess::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
49 if ( rVclWindowEvent
.GetId() == VclEventId::ObjectDying
)
51 ::osl::MutexGuard
aGuard( m_aMutex
);
55 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent
);
57 OUString SAL_CALL
OTableWindowAccess::getImplementationName()
59 return "org.openoffice.comp.dbu.TableWindowAccessibility";
61 Sequence
< OUString
> SAL_CALL
OTableWindowAccess::getSupportedServiceNames()
63 return { "com.sun.star.accessibility.Accessible",
64 "com.sun.star.accessibility.AccessibleContext" };
67 sal_Int64 SAL_CALL
OTableWindowAccess::getAccessibleChildCount( )
69 ::osl::MutexGuard
aGuard( m_aMutex
);
74 if(m_pTable
->GetListBox())
79 Reference
< XAccessible
> SAL_CALL
OTableWindowAccess::getAccessibleChild( sal_Int64 i
)
81 ::osl::MutexGuard
aGuard( m_aMutex
);
82 Reference
< XAccessible
> aRet
;
83 if (m_pTable
&& !m_pTable
->isDisposed())
89 VclPtr
<OTableWindowTitle
> xCtrl(m_pTable
->GetTitleCtrl());
91 aRet
= xCtrl
->GetAccessible();
96 VclPtr
<OTableWindowListBox
> xCtrl(m_pTable
->GetListBox());
98 aRet
= xCtrl
->GetAccessible();
102 throw IndexOutOfBoundsException();
107 sal_Int64 SAL_CALL
OTableWindowAccess::getAccessibleIndexInParent( )
109 ::osl::MutexGuard
aGuard( m_aMutex
);
110 sal_Int64 nIndex
= -1;
113 // search the position of our table window in the table window map
114 bool bFoundElem
= false;
115 for (auto const& tabWin
: m_pTable
->getTableView()->GetTabWinMap())
117 if (tabWin
.second
== m_pTable
)
124 nIndex
= bFoundElem
? nIndex
: -1;
128 sal_Int16 SAL_CALL
OTableWindowAccess::getAccessibleRole( )
130 return AccessibleRole::PANEL
; // ? or may be an AccessibleRole::WINDOW
132 Reference
< XAccessibleRelationSet
> SAL_CALL
OTableWindowAccess::getAccessibleRelationSet( )
134 ::osl::MutexGuard
aGuard( m_aMutex
);
137 // XAccessibleComponent
138 Reference
< XAccessible
> SAL_CALL
OTableWindowAccess::getAccessibleAtPoint( const awt::Point
& _aPoint
)
140 ::osl::MutexGuard
aGuard( m_aMutex
);
141 Reference
< XAccessible
> aRet
;
142 if(m_pTable
&& !m_pTable
->isDisposed())
144 Point
aPoint(_aPoint
.X
,_aPoint
.Y
);
145 tools::Rectangle
aRect(m_pTable
->GetDesktopRectPixel());
146 if( aRect
.Contains(aPoint
) )
148 else if( m_pTable
->GetListBox()->GetDesktopRectPixel().Contains(aPoint
))
149 aRet
= m_pTable
->GetListBox()->GetAccessible();
153 Reference
< XAccessible
> OTableWindowAccess::getParentChild(sal_Int64 _nIndex
)
155 Reference
< XAccessible
> xReturn
;
156 Reference
< XAccessible
> xParent
= getAccessibleParent();
159 Reference
< XAccessibleContext
> xParentContext
= xParent
->getAccessibleContext();
160 if ( xParentContext
.is() )
162 xReturn
= xParentContext
->getAccessibleChild(_nIndex
);
168 sal_Int32 SAL_CALL
OTableWindowAccess::getRelationCount( )
170 ::osl::MutexGuard
aGuard( m_aMutex
);
171 return m_pTable
? m_pTable
->getTableView()->getConnectionCount(m_pTable
) : sal_Int32(0);
173 AccessibleRelation SAL_CALL
OTableWindowAccess::getRelation( sal_Int32 nIndex
)
175 ::osl::MutexGuard
aGuard( m_aMutex
);
176 if( nIndex
< 0 || nIndex
>= getRelationCount() )
177 throw IndexOutOfBoundsException();
179 AccessibleRelation aRet
;
182 OJoinTableView
* pView
= m_pTable
->getTableView();
183 auto aIter
= pView
->getTableConnections(m_pTable
) + nIndex
;
184 aRet
.TargetSet
= { getParentChild(aIter
- pView
->getTableConnections().begin()) };
185 aRet
.RelationType
= AccessibleRelationType::CONTROLLER_FOR
;
189 sal_Bool SAL_CALL
OTableWindowAccess::containsRelation( sal_Int16 aRelationType
)
191 ::osl::MutexGuard
aGuard( m_aMutex
);
192 return AccessibleRelationType::CONTROLLER_FOR
== aRelationType
193 && m_pTable
&& m_pTable
->getTableView()->ExistsAConn(m_pTable
);
195 AccessibleRelation SAL_CALL
OTableWindowAccess::getRelationByType( sal_Int16 aRelationType
)
197 ::osl::MutexGuard
aGuard( m_aMutex
);
198 if( AccessibleRelationType::CONTROLLER_FOR
== aRelationType
&& m_pTable
)
200 OJoinTableView
* pView
= m_pTable
->getTableView();
201 const auto& rConnectionList
= pView
->getTableConnections();
203 auto aIter
= pView
->getTableConnections(m_pTable
);
204 auto aEnd
= rConnectionList
.end();
205 std::vector
< Reference
<XInterface
> > aRelations
;
206 aRelations
.reserve(5); // just guessing
207 // TODO JNA aIter comes from pView->getTableConnections(m_pTable)
208 // and aEnd comes from pView->getTableConnections().end()
209 for (; aIter
!= aEnd
; ++aIter
)
211 uno::Reference
<uno::XInterface
> xInterface(
212 getParentChild(aIter
- rConnectionList
.begin()));
213 aRelations
.push_back(xInterface
);
216 Sequence
< Reference
<XInterface
> > aSeq(aRelations
.data(), aRelations
.size());
217 return AccessibleRelation(AccessibleRelationType::CONTROLLER_FOR
,aSeq
);
219 return AccessibleRelation();
221 OUString SAL_CALL
OTableWindowAccess::getTitledBorderText( )
223 return getAccessibleName( );
225 OUString SAL_CALL
OTableWindowAccess::getAccessibleName( )
227 ::osl::MutexGuard
aGuard( m_aMutex
);
228 OUString sAccessibleName
;
230 sAccessibleName
= m_pTable
->getTitle();
231 return sAccessibleName
;
233 Reference
< XAccessibleContext
> SAL_CALL
OTableWindowAccess::getAccessibleContext( )
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */