merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / querydesign / TableWindowAccess.cxx
blobeaffece608f676920fb68e333510f6cd5d636251
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableWindowAccess.cxx,v $
10 * $Revision: 1.14.34.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBACCESS_TABLEWINDOWACCESS_HXX
34 #include "TableWindowAccess.hxx"
35 #endif
36 #ifndef DBACCESS_JACCESS_HXX
37 #include "JAccess.hxx"
38 #endif
39 #ifndef DBAUI_TABLEWINDOW_HXX
40 #include "TableWindow.hxx"
41 #endif
42 #ifndef DBAUI_TABLEWINDOWLISTBOX_HXX
43 #include "TableWindowListBox.hxx"
44 #endif
45 #ifndef DBAUI_JOINDESIGNVIEW_HXX
46 #include "JoinDesignView.hxx"
47 #endif
48 #ifndef DBAUI_JOINCONTROLLER_HXX
49 #include "JoinController.hxx"
50 #endif
51 #ifndef DBAUI_JOINTABLEVIEW_HXX
52 #include "JoinTableView.hxx"
53 #endif
54 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEROLE_HPP_
55 #include <com/sun/star/accessibility/AccessibleRole.hpp>
56 #endif
57 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLERELATIONTYPE_HPP_
58 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
59 #endif
60 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLESTATETYPE_HPP_
61 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
62 #endif
63 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEEVENTID_HPP_
64 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
65 #endif
66 #ifndef _COMPHELPER_SEQUENCE_HXX_
67 #include <comphelper/sequence.hxx>
68 #endif
69 #ifndef _DBU_QRY_HRC_
70 #include "dbu_qry.hrc"
71 #endif
74 namespace dbaui
76 using namespace ::com::sun::star::accessibility;
77 using namespace ::com::sun::star::uno;
78 using namespace ::com::sun::star::beans;
79 using namespace ::com::sun::star::lang;
80 // using namespace ::com::sun::star::awt;
81 using namespace ::com::sun::star;
83 OTableWindowAccess::OTableWindowAccess(OTableWindow* _pTable)
84 :VCLXAccessibleComponent(_pTable->GetComponentInterface().is() ? _pTable->GetWindowPeer() : NULL)
85 ,m_pTable(_pTable)
88 // -----------------------------------------------------------------------------
89 void SAL_CALL OTableWindowAccess::disposing()
91 m_pTable = NULL;
92 VCLXAccessibleComponent::disposing();
94 // -----------------------------------------------------------------------------
95 void OTableWindowAccess::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
97 if ( rVclWindowEvent.GetId() == VCLEVENT_OBJECT_DYING )
99 ::osl::MutexGuard aGuard( m_aMutex );
100 m_pTable = NULL;
103 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
105 // -----------------------------------------------------------------------------
106 Any SAL_CALL OTableWindowAccess::queryInterface( const Type& aType ) throw (RuntimeException)
108 Any aRet(VCLXAccessibleComponent::queryInterface( aType ));
109 return aRet.hasValue() ? aRet : OTableWindowAccess_BASE::queryInterface( aType );
111 // -----------------------------------------------------------------------------
112 Sequence< Type > SAL_CALL OTableWindowAccess::getTypes( ) throw (RuntimeException)
114 return ::comphelper::concatSequences(VCLXAccessibleComponent::getTypes(),OTableWindowAccess_BASE::getTypes());
116 // -----------------------------------------------------------------------------
117 ::rtl::OUString SAL_CALL OTableWindowAccess::getImplementationName() throw(RuntimeException)
119 return getImplementationName_Static();
121 // -----------------------------------------------------------------------------
122 Sequence< ::rtl::OUString > SAL_CALL OTableWindowAccess::getSupportedServiceNames() throw(RuntimeException)
124 return getSupportedServiceNames_Static();
126 // -----------------------------------------------------------------------------
127 // XServiceInfo - static methods
128 Sequence< ::rtl::OUString > OTableWindowAccess::getSupportedServiceNames_Static(void) throw( RuntimeException )
130 Sequence< ::rtl::OUString > aSupported(2);
131 aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.accessibility.Accessible");
132 aSupported[1] = ::rtl::OUString::createFromAscii("com.sun.star.accessibility.AccessibleContext");
133 return aSupported;
135 // -----------------------------------------------------------------------------
136 ::rtl::OUString OTableWindowAccess::getImplementationName_Static(void) throw( RuntimeException )
138 return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbu.TableWindowAccessibility");
140 // -----------------------------------------------------------------------------
141 // XAccessibleContext
142 sal_Int32 SAL_CALL OTableWindowAccess::getAccessibleChildCount( ) throw (RuntimeException)
144 ::osl::MutexGuard aGuard( m_aMutex );
145 sal_Int32 nCount = 0;
146 if(m_pTable)
148 if(m_pTable->GetTitleCtrl())
149 ++nCount;
150 if(m_pTable->GetListBox())
151 ++nCount;
153 return nCount;
155 // -----------------------------------------------------------------------------
156 Reference< XAccessible > SAL_CALL OTableWindowAccess::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException,RuntimeException)
158 ::osl::MutexGuard aGuard( m_aMutex );
159 Reference< XAccessible > aRet;
160 if(m_pTable)
162 switch(i)
164 case 0:
165 if(m_pTable->GetTitleCtrl())
167 aRet = m_pTable->GetTitleCtrl()->GetAccessible();
168 break;
169 } // fall through if title control does not exist
170 case 1:
171 if(m_pTable->GetListBox())
172 aRet = m_pTable->GetListBox()->GetAccessible();
173 break;
174 default:
175 throw IndexOutOfBoundsException();
178 return aRet;
180 // -----------------------------------------------------------------------------
181 sal_Int32 SAL_CALL OTableWindowAccess::getAccessibleIndexInParent( ) throw (RuntimeException)
183 ::osl::MutexGuard aGuard( m_aMutex );
184 sal_Int32 nIndex = -1;
185 if( m_pTable )
187 // search the postion of our table window in the table window map
188 OJoinTableView::OTableWindowMap* pMap = m_pTable->getTableView()->GetTabWinMap();
189 OJoinTableView::OTableWindowMap::iterator aIter = pMap->begin();
190 OJoinTableView::OTableWindowMap::iterator aEnd = pMap->end();
191 for (nIndex = 0; aIter != aEnd && aIter->second != m_pTable; ++nIndex,++aIter)
193 nIndex = aIter != aEnd ? nIndex : -1;
195 return nIndex;
197 // -----------------------------------------------------------------------------
198 sal_Int16 SAL_CALL OTableWindowAccess::getAccessibleRole( ) throw (RuntimeException)
200 return AccessibleRole::PANEL; // ? or may be an AccessibleRole::WINDOW
202 // -----------------------------------------------------------------------------
203 Reference< XAccessibleRelationSet > SAL_CALL OTableWindowAccess::getAccessibleRelationSet( ) throw (RuntimeException)
205 ::osl::MutexGuard aGuard( m_aMutex );
206 return this;
208 // -----------------------------------------------------------------------------
209 // XAccessibleComponent
210 Reference< XAccessible > SAL_CALL OTableWindowAccess::getAccessibleAtPoint( const awt::Point& _aPoint ) throw (RuntimeException)
212 ::osl::MutexGuard aGuard( m_aMutex );
213 Reference< XAccessible > aRet;
214 if( m_pTable )
216 Point aPoint(_aPoint.X,_aPoint.Y);
217 Rectangle aRect(m_pTable->GetDesktopRectPixel());
218 if( aRect.IsInside(aPoint) )
219 aRet = this;
220 else if( m_pTable->GetListBox()->GetDesktopRectPixel().IsInside(aPoint))
221 aRet = m_pTable->GetListBox()->GetAccessible();
223 return aRet;
225 // -----------------------------------------------------------------------------
226 Reference< XAccessible > OTableWindowAccess::getParentChild(sal_Int32 _nIndex)
228 Reference< XAccessible > xReturn;
229 Reference< XAccessible > xParent = getAccessibleParent();
230 if ( xParent.is() )
232 Reference< XAccessibleContext > xParentContext = xParent->getAccessibleContext();
233 if ( xParentContext.is() )
235 xReturn = xParentContext->getAccessibleChild(_nIndex);
238 return xReturn;
240 // -----------------------------------------------------------------------------
242 sal_Int32 SAL_CALL OTableWindowAccess::getRelationCount( ) throw (RuntimeException)
244 ::osl::MutexGuard aGuard( m_aMutex );
245 return m_pTable ? m_pTable->getTableView()->getConnectionCount(m_pTable) : sal_Int32(0);
247 // -----------------------------------------------------------------------------
248 AccessibleRelation SAL_CALL OTableWindowAccess::getRelation( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
250 ::osl::MutexGuard aGuard( m_aMutex );
251 if( nIndex < 0 || nIndex >= getRelationCount() )
252 throw IndexOutOfBoundsException();
254 AccessibleRelation aRet;
255 if( m_pTable )
257 OJoinTableView* pView = m_pTable->getTableView();
258 ::std::vector<OTableConnection*>::const_iterator aIter = pView->getTableConnections(m_pTable) + nIndex;
259 aRet.TargetSet.realloc(1);
260 aRet.TargetSet[0] = getParentChild(aIter - pView->getTableConnections()->begin());
261 aRet.RelationType = AccessibleRelationType::CONTROLLER_FOR;
263 return aRet;
265 // -----------------------------------------------------------------------------
266 sal_Bool SAL_CALL OTableWindowAccess::containsRelation( sal_Int16 aRelationType ) throw (RuntimeException)
268 ::osl::MutexGuard aGuard( m_aMutex );
269 return AccessibleRelationType::CONTROLLER_FOR == aRelationType
270 && m_pTable && m_pTable->getTableView()->ExistsAConn(m_pTable);
272 // -----------------------------------------------------------------------------
273 AccessibleRelation SAL_CALL OTableWindowAccess::getRelationByType( sal_Int16 aRelationType ) throw (RuntimeException)
275 ::osl::MutexGuard aGuard( m_aMutex );
276 if( AccessibleRelationType::CONTROLLER_FOR == aRelationType && m_pTable)
278 OJoinTableView* pView = m_pTable->getTableView();
279 const ::std::vector<OTableConnection*>* pConnectionList = pView->getTableConnections();
281 ::std::vector<OTableConnection*>::const_iterator aIter = pView->getTableConnections(m_pTable);
282 ::std::vector<OTableConnection*>::const_iterator aEnd = pConnectionList->end();
283 ::std::vector< Reference<XInterface> > aRelations;
284 aRelations.reserve(5); // just guessing
285 for (; aIter != aEnd ; ++aIter )
286 aRelations.push_back(getParentChild(aIter - pConnectionList->begin()));
288 Reference<XInterface> *pRelations = aRelations.empty() ? 0 : &aRelations[0];
289 Sequence< Reference<XInterface> > aSeq(pRelations, aRelations.size());
290 return AccessibleRelation(AccessibleRelationType::CONTROLLER_FOR,aSeq);
292 return AccessibleRelation();
294 // -----------------------------------------------------------------------------
295 sal_Bool OTableWindowAccess::isEditable() const
297 return m_pTable && !m_pTable->getTableView()->getDesignView()->getController().isReadOnly();
299 // -----------------------------------------------------------------------------
300 ::rtl::OUString SAL_CALL OTableWindowAccess::getTitledBorderText( ) throw (RuntimeException)
302 return getAccessibleName( );
304 // -----------------------------------------------------------------------------
305 ::rtl::OUString SAL_CALL OTableWindowAccess::getAccessibleName( ) throw (RuntimeException)
307 ::osl::MutexGuard aGuard( m_aMutex );
308 ::rtl::OUString sAccessibleName;
309 if ( m_pTable )
310 sAccessibleName = m_pTable->getTitle();
311 return sAccessibleName;
313 // -----------------------------------------------------------------------------
314 Reference< XAccessibleContext > SAL_CALL OTableWindowAccess::getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException)
316 return this;
318 // -----------------------------------------------------------------------------
321 // -----------------------------------------------------------------------------