196de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
396de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
496de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
596de5490SAndrew Rist  * distributed with this work for additional information
696de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
796de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
896de5490SAndrew Rist  * "License"); you may not use this file except in compliance
996de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
1096de5490SAndrew Rist  *
1196de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1296de5490SAndrew Rist  *
1396de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1496de5490SAndrew Rist  * software distributed under the License is distributed on an
1596de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1696de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
1796de5490SAndrew Rist  * specific language governing permissions and limitations
1896de5490SAndrew Rist  * under the License.
1996de5490SAndrew Rist  *
2096de5490SAndrew Rist  *************************************************************/
2196de5490SAndrew Rist 
2296de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir #ifndef DBACCESS_TABLEWINDOWACCESS_HXX
27cdf0e10cSrcweir #include "TableWindowAccess.hxx"
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #ifndef DBACCESS_JACCESS_HXX
30cdf0e10cSrcweir #include "JAccess.hxx"
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #ifndef DBAUI_TABLEWINDOW_HXX
33cdf0e10cSrcweir #include "TableWindow.hxx"
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #ifndef DBAUI_TABLEWINDOWLISTBOX_HXX
36cdf0e10cSrcweir #include "TableWindowListBox.hxx"
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #ifndef DBAUI_JOINDESIGNVIEW_HXX
39cdf0e10cSrcweir #include "JoinDesignView.hxx"
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #ifndef DBAUI_JOINCONTROLLER_HXX
42cdf0e10cSrcweir #include "JoinController.hxx"
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir #ifndef DBAUI_JOINTABLEVIEW_HXX
45cdf0e10cSrcweir #include "JoinTableView.hxx"
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEROLE_HPP_
48cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLERELATIONTYPE_HPP_
51cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
52cdf0e10cSrcweir #endif
53cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLESTATETYPE_HPP_
54cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEEVENTID_HPP_
57cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
58cdf0e10cSrcweir #endif
59cdf0e10cSrcweir #ifndef _COMPHELPER_SEQUENCE_HXX_
60cdf0e10cSrcweir #include <comphelper/sequence.hxx>
61cdf0e10cSrcweir #endif
62cdf0e10cSrcweir #ifndef _DBU_QRY_HRC_
63cdf0e10cSrcweir #include "dbu_qry.hrc"
64cdf0e10cSrcweir #endif
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 
67cdf0e10cSrcweir namespace dbaui
68cdf0e10cSrcweir {
69cdf0e10cSrcweir 	using namespace ::com::sun::star::accessibility;
70cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
71cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
72cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
73cdf0e10cSrcweir 	//	using namespace ::com::sun::star::awt;
74cdf0e10cSrcweir 	using namespace ::com::sun::star;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	OTableWindowAccess::OTableWindowAccess(OTableWindow* _pTable)
77cdf0e10cSrcweir 		:VCLXAccessibleComponent(_pTable->GetComponentInterface().is() ? _pTable->GetWindowPeer() : NULL)
78cdf0e10cSrcweir 		,m_pTable(_pTable)
79cdf0e10cSrcweir 	{
80cdf0e10cSrcweir 	}
81cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
82cdf0e10cSrcweir     void SAL_CALL OTableWindowAccess::disposing()
83cdf0e10cSrcweir 	{
84cdf0e10cSrcweir 		m_pTable = NULL;
85cdf0e10cSrcweir 		VCLXAccessibleComponent::disposing();
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir     // -----------------------------------------------------------------------------
88cdf0e10cSrcweir     void OTableWindowAccess::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
89cdf0e10cSrcweir 	{
90cdf0e10cSrcweir         if ( rVclWindowEvent.GetId() == VCLEVENT_OBJECT_DYING )
91cdf0e10cSrcweir 		{
92cdf0e10cSrcweir         	::osl::MutexGuard aGuard( m_aMutex );
93cdf0e10cSrcweir             m_pTable = NULL;
94cdf0e10cSrcweir 		}
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
97cdf0e10cSrcweir 	}
98cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
99cdf0e10cSrcweir 	Any SAL_CALL OTableWindowAccess::queryInterface( const Type& aType ) throw (RuntimeException)
100cdf0e10cSrcweir 	{
101cdf0e10cSrcweir 		Any aRet(VCLXAccessibleComponent::queryInterface( aType ));
102cdf0e10cSrcweir 		return aRet.hasValue() ? aRet : OTableWindowAccess_BASE::queryInterface( aType );
103cdf0e10cSrcweir 	}
104cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
105cdf0e10cSrcweir 	Sequence< Type > SAL_CALL OTableWindowAccess::getTypes(  ) throw (RuntimeException)
106cdf0e10cSrcweir 	{
107cdf0e10cSrcweir 		return ::comphelper::concatSequences(VCLXAccessibleComponent::getTypes(),OTableWindowAccess_BASE::getTypes());
108cdf0e10cSrcweir 	}
109cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
110cdf0e10cSrcweir 	::rtl::OUString SAL_CALL OTableWindowAccess::getImplementationName() throw(RuntimeException)
111cdf0e10cSrcweir 	{
112cdf0e10cSrcweir 		return getImplementationName_Static();
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
115cdf0e10cSrcweir 	Sequence< ::rtl::OUString > SAL_CALL OTableWindowAccess::getSupportedServiceNames() throw(RuntimeException)
116cdf0e10cSrcweir 	{
117cdf0e10cSrcweir 		return getSupportedServiceNames_Static();
118cdf0e10cSrcweir 	}
119cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
120cdf0e10cSrcweir 	// XServiceInfo - static methods
121cdf0e10cSrcweir 	Sequence< ::rtl::OUString > OTableWindowAccess::getSupportedServiceNames_Static(void) throw( RuntimeException )
122cdf0e10cSrcweir 	{
123cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aSupported(2);
124cdf0e10cSrcweir 		aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.accessibility.Accessible");
125cdf0e10cSrcweir 		aSupported[1] = ::rtl::OUString::createFromAscii("com.sun.star.accessibility.AccessibleContext");
126cdf0e10cSrcweir 		return aSupported;
127cdf0e10cSrcweir 	}
128cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
129cdf0e10cSrcweir 	::rtl::OUString OTableWindowAccess::getImplementationName_Static(void) throw( RuntimeException )
130cdf0e10cSrcweir 	{
131cdf0e10cSrcweir 		return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbu.TableWindowAccessibility");
132cdf0e10cSrcweir 	}
133cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
134cdf0e10cSrcweir 	// XAccessibleContext
135cdf0e10cSrcweir     sal_Int32 SAL_CALL OTableWindowAccess::getAccessibleChildCount(  ) throw (RuntimeException)
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
138cdf0e10cSrcweir         sal_Int32 nCount = 0;
139cdf0e10cSrcweir         if(m_pTable)
140cdf0e10cSrcweir         {
141cdf0e10cSrcweir             if(m_pTable->GetTitleCtrl())
142cdf0e10cSrcweir                 ++nCount;
143cdf0e10cSrcweir             if(m_pTable->GetListBox())
144cdf0e10cSrcweir                 ++nCount;
145cdf0e10cSrcweir         }
146cdf0e10cSrcweir 		return nCount;
147cdf0e10cSrcweir 	}
148cdf0e10cSrcweir     // -----------------------------------------------------------------------------
149cdf0e10cSrcweir     Reference< XAccessible > SAL_CALL OTableWindowAccess::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException,RuntimeException)
150cdf0e10cSrcweir     {
151cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
152cdf0e10cSrcweir         Reference< XAccessible > aRet;
153cdf0e10cSrcweir         if(m_pTable)
154cdf0e10cSrcweir         {
155cdf0e10cSrcweir             switch(i)
156cdf0e10cSrcweir             {
157cdf0e10cSrcweir                 case 0:
158cdf0e10cSrcweir                     if(m_pTable->GetTitleCtrl())
159cdf0e10cSrcweir                     {
160cdf0e10cSrcweir                         aRet = m_pTable->GetTitleCtrl()->GetAccessible();
161cdf0e10cSrcweir                         break;
162cdf0e10cSrcweir                     } // fall through if title control does not exist
163cdf0e10cSrcweir                 case 1:
164cdf0e10cSrcweir                     if(m_pTable->GetListBox())
165cdf0e10cSrcweir                         aRet = m_pTable->GetListBox()->GetAccessible();
166cdf0e10cSrcweir                     break;
167cdf0e10cSrcweir                 default:
168cdf0e10cSrcweir                     throw IndexOutOfBoundsException();
169cdf0e10cSrcweir             }
170cdf0e10cSrcweir         }
171cdf0e10cSrcweir         return aRet;
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
174cdf0e10cSrcweir 	sal_Int32 SAL_CALL OTableWindowAccess::getAccessibleIndexInParent(  ) throw (RuntimeException)
175cdf0e10cSrcweir 	{
176cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex  );
177cdf0e10cSrcweir 		sal_Int32 nIndex = -1;
178cdf0e10cSrcweir 		if( m_pTable )
179cdf0e10cSrcweir 		{
180*07a3d7f1SPedro Giffuni 			// search the position of our table window in the table window map
181cdf0e10cSrcweir 			OJoinTableView::OTableWindowMap* pMap = m_pTable->getTableView()->GetTabWinMap();
182cdf0e10cSrcweir 			OJoinTableView::OTableWindowMap::iterator aIter = pMap->begin();
183cdf0e10cSrcweir             OJoinTableView::OTableWindowMap::iterator aEnd = pMap->end();
184cdf0e10cSrcweir 			for (nIndex = 0; aIter != aEnd && aIter->second != m_pTable; ++nIndex,++aIter)
185cdf0e10cSrcweir 				;
186cdf0e10cSrcweir 			nIndex = aIter != aEnd ? nIndex : -1;
187cdf0e10cSrcweir 		}
188cdf0e10cSrcweir 		return nIndex;
189cdf0e10cSrcweir 	}
190cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
191cdf0e10cSrcweir 	sal_Int16 SAL_CALL OTableWindowAccess::getAccessibleRole(  ) throw (RuntimeException)
192cdf0e10cSrcweir 	{
193cdf0e10cSrcweir 		return AccessibleRole::PANEL; // ? or may be an AccessibleRole::WINDOW
194cdf0e10cSrcweir 	}
195cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
196cdf0e10cSrcweir 	Reference< XAccessibleRelationSet > SAL_CALL OTableWindowAccess::getAccessibleRelationSet(  ) throw (RuntimeException)
197cdf0e10cSrcweir 	{
198cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex  );
199cdf0e10cSrcweir 		return this;
200cdf0e10cSrcweir 	}
201cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
202cdf0e10cSrcweir 	// XAccessibleComponent
203cdf0e10cSrcweir 	Reference< XAccessible > SAL_CALL OTableWindowAccess::getAccessibleAtPoint( const awt::Point& _aPoint ) throw (RuntimeException)
204cdf0e10cSrcweir 	{
205cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex  );
206cdf0e10cSrcweir 		Reference< XAccessible > aRet;
207cdf0e10cSrcweir 		if( m_pTable )
208cdf0e10cSrcweir 		{
209cdf0e10cSrcweir 			Point aPoint(_aPoint.X,_aPoint.Y);
210cdf0e10cSrcweir 			Rectangle aRect(m_pTable->GetDesktopRectPixel());
211cdf0e10cSrcweir 			if( aRect.IsInside(aPoint) )
212cdf0e10cSrcweir 				aRet = this;
213cdf0e10cSrcweir 			else if( m_pTable->GetListBox()->GetDesktopRectPixel().IsInside(aPoint))
214cdf0e10cSrcweir 				aRet = m_pTable->GetListBox()->GetAccessible();
215cdf0e10cSrcweir 		}
216cdf0e10cSrcweir 		return aRet;
217cdf0e10cSrcweir 	}
218cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
219cdf0e10cSrcweir 	Reference< XAccessible > OTableWindowAccess::getParentChild(sal_Int32 _nIndex)
220cdf0e10cSrcweir 	{
221cdf0e10cSrcweir 		Reference< XAccessible > xReturn;
222cdf0e10cSrcweir 		Reference< XAccessible > xParent = getAccessibleParent();
223cdf0e10cSrcweir 		if ( xParent.is() )
224cdf0e10cSrcweir 		{
225cdf0e10cSrcweir 			Reference< XAccessibleContext > xParentContext = xParent->getAccessibleContext();
226cdf0e10cSrcweir 			if ( xParentContext.is() )
227cdf0e10cSrcweir 			{
228cdf0e10cSrcweir 				xReturn = xParentContext->getAccessibleChild(_nIndex);
229cdf0e10cSrcweir 			}
230cdf0e10cSrcweir 		}
231cdf0e10cSrcweir 		return xReturn;
232cdf0e10cSrcweir 	}
233cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 	sal_Int32 SAL_CALL OTableWindowAccess::getRelationCount(  ) throw (RuntimeException)
236cdf0e10cSrcweir 	{
237cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex  );
238cdf0e10cSrcweir 		return m_pTable ? m_pTable->getTableView()->getConnectionCount(m_pTable) : sal_Int32(0);
239cdf0e10cSrcweir 	}
240cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
241cdf0e10cSrcweir 	AccessibleRelation SAL_CALL OTableWindowAccess::getRelation( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
242cdf0e10cSrcweir 	{
243cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex  );
244cdf0e10cSrcweir 		if( nIndex < 0 || nIndex >= getRelationCount() )
245cdf0e10cSrcweir 			throw IndexOutOfBoundsException();
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 		AccessibleRelation aRet;
248cdf0e10cSrcweir 		if( m_pTable )
249cdf0e10cSrcweir 		{
250cdf0e10cSrcweir 			OJoinTableView* pView = m_pTable->getTableView();
251cdf0e10cSrcweir 			::std::vector<OTableConnection*>::const_iterator aIter = pView->getTableConnections(m_pTable) + nIndex;
252cdf0e10cSrcweir 			aRet.TargetSet.realloc(1);
253cdf0e10cSrcweir 			aRet.TargetSet[0] = getParentChild(aIter - pView->getTableConnections()->begin());
254cdf0e10cSrcweir 			aRet.RelationType = AccessibleRelationType::CONTROLLER_FOR;
255cdf0e10cSrcweir 		}
256cdf0e10cSrcweir 		return aRet;
257cdf0e10cSrcweir 	}
258cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
259cdf0e10cSrcweir 	sal_Bool SAL_CALL OTableWindowAccess::containsRelation( sal_Int16 aRelationType ) throw (RuntimeException)
260cdf0e10cSrcweir 	{
261cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex  );
262cdf0e10cSrcweir 		return		AccessibleRelationType::CONTROLLER_FOR == aRelationType
263cdf0e10cSrcweir 				&&	m_pTable && m_pTable->getTableView()->ExistsAConn(m_pTable);
264cdf0e10cSrcweir 	}
265cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
266cdf0e10cSrcweir 	AccessibleRelation SAL_CALL OTableWindowAccess::getRelationByType( sal_Int16 aRelationType ) throw (RuntimeException)
267cdf0e10cSrcweir 	{
268cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex  );
269cdf0e10cSrcweir 		if( AccessibleRelationType::CONTROLLER_FOR == aRelationType && m_pTable)
270cdf0e10cSrcweir 		{
271cdf0e10cSrcweir 			OJoinTableView* pView = m_pTable->getTableView();
272cdf0e10cSrcweir 			const ::std::vector<OTableConnection*>* pConnectionList = pView->getTableConnections();
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 			::std::vector<OTableConnection*>::const_iterator aIter = pView->getTableConnections(m_pTable);
275cdf0e10cSrcweir             ::std::vector<OTableConnection*>::const_iterator aEnd = pConnectionList->end();
276cdf0e10cSrcweir 			::std::vector< Reference<XInterface> > aRelations;
277cdf0e10cSrcweir 			aRelations.reserve(5); // just guessing
278cdf0e10cSrcweir 			for (; aIter != aEnd ; ++aIter )
279cdf0e10cSrcweir 				aRelations.push_back(getParentChild(aIter - pConnectionList->begin()));
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 			Reference<XInterface> *pRelations = aRelations.empty() ? 0 : &aRelations[0];
282cdf0e10cSrcweir 			Sequence< Reference<XInterface> > aSeq(pRelations, aRelations.size());
283cdf0e10cSrcweir 			return AccessibleRelation(AccessibleRelationType::CONTROLLER_FOR,aSeq);
284cdf0e10cSrcweir 		}
285cdf0e10cSrcweir 		return AccessibleRelation();
286cdf0e10cSrcweir 	}
287cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
288cdf0e10cSrcweir 	sal_Bool OTableWindowAccess::isEditable() const
289cdf0e10cSrcweir 	{
290cdf0e10cSrcweir 		return m_pTable && !m_pTable->getTableView()->getDesignView()->getController().isReadOnly();
291cdf0e10cSrcweir 	}
292cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
293cdf0e10cSrcweir 	::rtl::OUString SAL_CALL OTableWindowAccess::getTitledBorderText(  ) throw (RuntimeException)
294cdf0e10cSrcweir 	{
295cdf0e10cSrcweir 		return getAccessibleName(  );
296cdf0e10cSrcweir 	}
297cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
298cdf0e10cSrcweir 	::rtl::OUString SAL_CALL OTableWindowAccess::getAccessibleName(  ) throw (RuntimeException)
299cdf0e10cSrcweir 	{
300cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex  );
301cdf0e10cSrcweir 		::rtl::OUString sAccessibleName;
302cdf0e10cSrcweir 		if ( m_pTable )
303cdf0e10cSrcweir 			sAccessibleName = m_pTable->getTitle();
304cdf0e10cSrcweir 		return sAccessibleName;
305cdf0e10cSrcweir 	}
306cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
307cdf0e10cSrcweir 	Reference< XAccessibleContext > SAL_CALL OTableWindowAccess::getAccessibleContext(  ) throw (::com::sun::star::uno::RuntimeException)
308cdf0e10cSrcweir 	{
309cdf0e10cSrcweir 		return this;
310cdf0e10cSrcweir 	}
311cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
312cdf0e10cSrcweir 
313cdf0e10cSrcweir }
314cdf0e10cSrcweir // -----------------------------------------------------------------------------
315cdf0e10cSrcweir 
316