bump product version to 4.1.6.2
[LibreOffice.git] / dbaccess / source / ui / querydesign / TableWindowAccess.cxx
blob92fa870682c7706b5dd4edd2cba97423684699ee
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 "JAccess.hxx"
22 #include "TableWindow.hxx"
23 #include "TableWindowListBox.hxx"
24 #include "JoinDesignView.hxx"
25 #include "JoinController.hxx"
26 #include "JoinTableView.hxx"
27 #include <com/sun/star/accessibility/AccessibleRole.hpp>
28 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
29 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
30 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
31 #include <comphelper/sequence.hxx>
32 #include "dbu_qry.hrc"
35 namespace dbaui
37 using namespace ::com::sun::star::accessibility;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star;
43 OTableWindowAccess::OTableWindowAccess(OTableWindow* _pTable)
44 :VCLXAccessibleComponent(_pTable->GetComponentInterface().is() ? _pTable->GetWindowPeer() : NULL)
45 ,m_pTable(_pTable)
48 // -----------------------------------------------------------------------------
49 void SAL_CALL OTableWindowAccess::disposing()
51 m_pTable = NULL;
52 VCLXAccessibleComponent::disposing();
54 // -----------------------------------------------------------------------------
55 void OTableWindowAccess::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
57 if ( rVclWindowEvent.GetId() == VCLEVENT_OBJECT_DYING )
59 ::osl::MutexGuard aGuard( m_aMutex );
60 m_pTable = NULL;
63 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
65 // -----------------------------------------------------------------------------
66 Any SAL_CALL OTableWindowAccess::queryInterface( const Type& aType ) throw (RuntimeException)
68 Any aRet(VCLXAccessibleComponent::queryInterface( aType ));
69 return aRet.hasValue() ? aRet : OTableWindowAccess_BASE::queryInterface( aType );
71 // -----------------------------------------------------------------------------
72 Sequence< Type > SAL_CALL OTableWindowAccess::getTypes( ) throw (RuntimeException)
74 return ::comphelper::concatSequences(VCLXAccessibleComponent::getTypes(),OTableWindowAccess_BASE::getTypes());
76 // -----------------------------------------------------------------------------
77 OUString SAL_CALL OTableWindowAccess::getImplementationName() throw(RuntimeException)
79 return getImplementationName_Static();
81 // -----------------------------------------------------------------------------
82 Sequence< OUString > SAL_CALL OTableWindowAccess::getSupportedServiceNames() throw(RuntimeException)
84 return getSupportedServiceNames_Static();
86 // -----------------------------------------------------------------------------
87 // XServiceInfo - static methods
88 Sequence< OUString > OTableWindowAccess::getSupportedServiceNames_Static(void) throw( RuntimeException )
90 Sequence< OUString > aSupported(2);
91 aSupported[0] = OUString("com.sun.star.accessibility.Accessible");
92 aSupported[1] = OUString("com.sun.star.accessibility.AccessibleContext");
93 return aSupported;
95 // -----------------------------------------------------------------------------
96 OUString OTableWindowAccess::getImplementationName_Static(void) throw( RuntimeException )
98 return OUString("org.openoffice.comp.dbu.TableWindowAccessibility");
100 // -----------------------------------------------------------------------------
101 // XAccessibleContext
102 sal_Int32 SAL_CALL OTableWindowAccess::getAccessibleChildCount( ) throw (RuntimeException)
104 ::osl::MutexGuard aGuard( m_aMutex );
105 sal_Int32 nCount = 0;
106 if(m_pTable)
108 if(m_pTable->GetTitleCtrl())
109 ++nCount;
110 if(m_pTable->GetListBox())
111 ++nCount;
113 return nCount;
115 // -----------------------------------------------------------------------------
116 Reference< XAccessible > SAL_CALL OTableWindowAccess::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException,RuntimeException)
118 ::osl::MutexGuard aGuard( m_aMutex );
119 Reference< XAccessible > aRet;
120 if(m_pTable)
122 switch(i)
124 case 0:
125 if(m_pTable->GetTitleCtrl())
127 aRet = m_pTable->GetTitleCtrl()->GetAccessible();
128 break;
129 } // fall through if title control does not exist
130 case 1:
131 if(m_pTable->GetListBox())
132 aRet = m_pTable->GetListBox()->GetAccessible();
133 break;
134 default:
135 throw IndexOutOfBoundsException();
138 return aRet;
140 // -----------------------------------------------------------------------------
141 sal_Int32 SAL_CALL OTableWindowAccess::getAccessibleIndexInParent( ) throw (RuntimeException)
143 ::osl::MutexGuard aGuard( m_aMutex );
144 sal_Int32 nIndex = -1;
145 if( m_pTable )
147 // search the postion of our table window in the table window map
148 OJoinTableView::OTableWindowMap* pMap = m_pTable->getTableView()->GetTabWinMap();
149 OJoinTableView::OTableWindowMap::iterator aIter = pMap->begin();
150 OJoinTableView::OTableWindowMap::iterator aEnd = pMap->end();
151 for (nIndex = 0; aIter != aEnd && aIter->second != m_pTable; ++nIndex,++aIter)
153 nIndex = aIter != aEnd ? nIndex : -1;
155 return nIndex;
157 // -----------------------------------------------------------------------------
158 sal_Int16 SAL_CALL OTableWindowAccess::getAccessibleRole( ) throw (RuntimeException)
160 return AccessibleRole::PANEL; // ? or may be an AccessibleRole::WINDOW
162 // -----------------------------------------------------------------------------
163 Reference< XAccessibleRelationSet > SAL_CALL OTableWindowAccess::getAccessibleRelationSet( ) throw (RuntimeException)
165 ::osl::MutexGuard aGuard( m_aMutex );
166 return this;
168 // -----------------------------------------------------------------------------
169 // XAccessibleComponent
170 Reference< XAccessible > SAL_CALL OTableWindowAccess::getAccessibleAtPoint( const awt::Point& _aPoint ) throw (RuntimeException)
172 ::osl::MutexGuard aGuard( m_aMutex );
173 Reference< XAccessible > aRet;
174 if( m_pTable )
176 Point aPoint(_aPoint.X,_aPoint.Y);
177 Rectangle aRect(m_pTable->GetDesktopRectPixel());
178 if( aRect.IsInside(aPoint) )
179 aRet = this;
180 else if( m_pTable->GetListBox()->GetDesktopRectPixel().IsInside(aPoint))
181 aRet = m_pTable->GetListBox()->GetAccessible();
183 return aRet;
185 // -----------------------------------------------------------------------------
186 Reference< XAccessible > OTableWindowAccess::getParentChild(sal_Int32 _nIndex)
188 Reference< XAccessible > xReturn;
189 Reference< XAccessible > xParent = getAccessibleParent();
190 if ( xParent.is() )
192 Reference< XAccessibleContext > xParentContext = xParent->getAccessibleContext();
193 if ( xParentContext.is() )
195 xReturn = xParentContext->getAccessibleChild(_nIndex);
198 return xReturn;
200 // -----------------------------------------------------------------------------
202 sal_Int32 SAL_CALL OTableWindowAccess::getRelationCount( ) throw (RuntimeException)
204 ::osl::MutexGuard aGuard( m_aMutex );
205 return m_pTable ? m_pTable->getTableView()->getConnectionCount(m_pTable) : sal_Int32(0);
207 // -----------------------------------------------------------------------------
208 AccessibleRelation SAL_CALL OTableWindowAccess::getRelation( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
210 ::osl::MutexGuard aGuard( m_aMutex );
211 if( nIndex < 0 || nIndex >= getRelationCount() )
212 throw IndexOutOfBoundsException();
214 AccessibleRelation aRet;
215 if( m_pTable )
217 OJoinTableView* pView = m_pTable->getTableView();
218 ::std::vector<OTableConnection*>::const_iterator aIter = pView->getTableConnections(m_pTable) + nIndex;
219 aRet.TargetSet.realloc(1);
220 aRet.TargetSet[0] = getParentChild(aIter - pView->getTableConnections()->begin());
221 aRet.RelationType = AccessibleRelationType::CONTROLLER_FOR;
223 return aRet;
225 // -----------------------------------------------------------------------------
226 sal_Bool SAL_CALL OTableWindowAccess::containsRelation( sal_Int16 aRelationType ) throw (RuntimeException)
228 ::osl::MutexGuard aGuard( m_aMutex );
229 return AccessibleRelationType::CONTROLLER_FOR == aRelationType
230 && m_pTable && m_pTable->getTableView()->ExistsAConn(m_pTable);
232 // -----------------------------------------------------------------------------
233 AccessibleRelation SAL_CALL OTableWindowAccess::getRelationByType( sal_Int16 aRelationType ) throw (RuntimeException)
235 ::osl::MutexGuard aGuard( m_aMutex );
236 if( AccessibleRelationType::CONTROLLER_FOR == aRelationType && m_pTable)
238 OJoinTableView* pView = m_pTable->getTableView();
239 const ::std::vector<OTableConnection*>* pConnectionList = pView->getTableConnections();
241 ::std::vector<OTableConnection*>::const_iterator aIter = pView->getTableConnections(m_pTable);
242 ::std::vector<OTableConnection*>::const_iterator aEnd = pConnectionList->end();
243 ::std::vector< Reference<XInterface> > aRelations;
244 aRelations.reserve(5); // just guessing
245 for (; aIter != aEnd ; ++aIter )
247 uno::Reference<uno::XInterface> xInterface(
248 getParentChild(aIter - pConnectionList->begin()));
249 aRelations.push_back(xInterface);
252 Reference<XInterface> *pRelations = aRelations.empty() ? 0 : &aRelations[0];
253 Sequence< Reference<XInterface> > aSeq(pRelations, aRelations.size());
254 return AccessibleRelation(AccessibleRelationType::CONTROLLER_FOR,aSeq);
256 return AccessibleRelation();
258 // -----------------------------------------------------------------------------
259 sal_Bool OTableWindowAccess::isEditable() const
261 return m_pTable && !m_pTable->getTableView()->getDesignView()->getController().isReadOnly();
263 // -----------------------------------------------------------------------------
264 OUString SAL_CALL OTableWindowAccess::getTitledBorderText( ) throw (RuntimeException)
266 return getAccessibleName( );
268 // -----------------------------------------------------------------------------
269 OUString SAL_CALL OTableWindowAccess::getAccessibleName( ) throw (RuntimeException)
271 ::osl::MutexGuard aGuard( m_aMutex );
272 OUString sAccessibleName;
273 if ( m_pTable )
274 sAccessibleName = m_pTable->getTitle();
275 return sAccessibleName;
277 // -----------------------------------------------------------------------------
278 Reference< XAccessibleContext > SAL_CALL OTableWindowAccess::getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException)
280 return this;
282 // -----------------------------------------------------------------------------
285 // -----------------------------------------------------------------------------
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */