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