tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / dbaccess / source / ui / querydesign / TableWindowAccess.cxx
blobfd3831b2496b4929edd7ac8387bc58811087b860
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
29 namespace dbaui
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)
38 ,m_pTable(_pTable)
41 void SAL_CALL OTableWindowAccess::disposing()
43 m_pTable = nullptr;
44 VCLXAccessibleComponent::disposing();
46 void OTableWindowAccess::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
48 if ( rVclWindowEvent.GetId() == VclEventId::ObjectDying )
50 ::osl::MutexGuard aGuard( m_aMutex );
51 m_pTable = nullptr;
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 };
65 // XAccessibleContext
66 sal_Int64 SAL_CALL OTableWindowAccess::getAccessibleChildCount( )
68 ::osl::MutexGuard aGuard( m_aMutex );
69 sal_Int64 nCount = 0;
70 if(m_pTable)
72 ++nCount;
73 if(m_pTable->GetListBox())
74 ++nCount;
76 return nCount;
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())
84 switch(i)
86 case 0:
88 VclPtr<OTableWindowTitle> xCtrl(m_pTable->GetTitleCtrl());
89 if (xCtrl)
90 aRet = xCtrl->GetAccessible();
91 break;
93 case 1:
95 VclPtr<OTableWindowListBox> xCtrl(m_pTable->GetListBox());
96 if (xCtrl)
97 aRet = xCtrl->GetAccessible();
98 break;
100 default:
101 throw IndexOutOfBoundsException();
104 return aRet;
106 sal_Int64 SAL_CALL OTableWindowAccess::getAccessibleIndexInParent( )
108 ::osl::MutexGuard aGuard( m_aMutex );
109 sal_Int64 nIndex = -1;
110 if( m_pTable )
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)
118 bFoundElem = true;
119 break;
121 ++nIndex;
123 nIndex = bFoundElem? nIndex : -1;
125 return nIndex;
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 );
134 return this;
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) )
146 aRet = this;
147 else if( m_pTable->GetListBox()->GetDesktopRectPixel().Contains(aPoint))
148 aRet = m_pTable->GetListBox()->GetAccessible();
150 return aRet;
152 Reference< XAccessible > OTableWindowAccess::getParentChild(sal_Int64 _nIndex)
154 Reference< XAccessible > xReturn;
155 Reference< XAccessible > xParent = getAccessibleParent();
156 if ( xParent.is() )
158 Reference< XAccessibleContext > xParentContext = xParent->getAccessibleContext();
159 if ( xParentContext.is() )
161 xReturn = xParentContext->getAccessibleChild(_nIndex);
164 return xReturn;
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;
179 if( m_pTable )
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;
186 return aRet;
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;
228 if ( m_pTable )
229 sAccessibleName = m_pTable->getTitle();
230 return sAccessibleName;
232 Reference< XAccessibleContext > SAL_CALL OTableWindowAccess::getAccessibleContext( )
234 return this;
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */