Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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"
33 :
34 :
35 : namespace dbaui
36 : {
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;
42 :
43 0 : OTableWindowAccess::OTableWindowAccess(OTableWindow* _pTable)
44 0 : :VCLXAccessibleComponent(_pTable->GetComponentInterface().is() ? _pTable->GetWindowPeer() : NULL)
45 0 : ,m_pTable(_pTable)
46 : {
47 0 : }
48 : // -----------------------------------------------------------------------------
49 0 : void SAL_CALL OTableWindowAccess::disposing()
50 : {
51 0 : m_pTable = NULL;
52 0 : VCLXAccessibleComponent::disposing();
53 0 : }
54 : // -----------------------------------------------------------------------------
55 0 : void OTableWindowAccess::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
56 : {
57 0 : if ( rVclWindowEvent.GetId() == VCLEVENT_OBJECT_DYING )
58 : {
59 0 : ::osl::MutexGuard aGuard( m_aMutex );
60 0 : m_pTable = NULL;
61 : }
62 :
63 0 : VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
64 0 : }
65 : // -----------------------------------------------------------------------------
66 0 : Any SAL_CALL OTableWindowAccess::queryInterface( const Type& aType ) throw (RuntimeException)
67 : {
68 0 : Any aRet(VCLXAccessibleComponent::queryInterface( aType ));
69 0 : return aRet.hasValue() ? aRet : OTableWindowAccess_BASE::queryInterface( aType );
70 : }
71 : // -----------------------------------------------------------------------------
72 0 : Sequence< Type > SAL_CALL OTableWindowAccess::getTypes( ) throw (RuntimeException)
73 : {
74 0 : return ::comphelper::concatSequences(VCLXAccessibleComponent::getTypes(),OTableWindowAccess_BASE::getTypes());
75 : }
76 : // -----------------------------------------------------------------------------
77 0 : ::rtl::OUString SAL_CALL OTableWindowAccess::getImplementationName() throw(RuntimeException)
78 : {
79 0 : return getImplementationName_Static();
80 : }
81 : // -----------------------------------------------------------------------------
82 0 : Sequence< ::rtl::OUString > SAL_CALL OTableWindowAccess::getSupportedServiceNames() throw(RuntimeException)
83 : {
84 0 : return getSupportedServiceNames_Static();
85 : }
86 : // -----------------------------------------------------------------------------
87 : // XServiceInfo - static methods
88 0 : Sequence< ::rtl::OUString > OTableWindowAccess::getSupportedServiceNames_Static(void) throw( RuntimeException )
89 : {
90 0 : Sequence< ::rtl::OUString > aSupported(2);
91 0 : aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.Accessible"));
92 0 : aSupported[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.AccessibleContext"));
93 0 : return aSupported;
94 : }
95 : // -----------------------------------------------------------------------------
96 0 : ::rtl::OUString OTableWindowAccess::getImplementationName_Static(void) throw( RuntimeException )
97 : {
98 0 : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbu.TableWindowAccessibility"));
99 : }
100 : // -----------------------------------------------------------------------------
101 : // XAccessibleContext
102 0 : sal_Int32 SAL_CALL OTableWindowAccess::getAccessibleChildCount( ) throw (RuntimeException)
103 : {
104 0 : ::osl::MutexGuard aGuard( m_aMutex );
105 0 : sal_Int32 nCount = 0;
106 0 : if(m_pTable)
107 : {
108 0 : if(m_pTable->GetTitleCtrl())
109 0 : ++nCount;
110 0 : if(m_pTable->GetListBox())
111 0 : ++nCount;
112 : }
113 0 : return nCount;
114 : }
115 : // -----------------------------------------------------------------------------
116 0 : Reference< XAccessible > SAL_CALL OTableWindowAccess::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException,RuntimeException)
117 : {
118 0 : ::osl::MutexGuard aGuard( m_aMutex );
119 0 : Reference< XAccessible > aRet;
120 0 : if(m_pTable)
121 : {
122 0 : switch(i)
123 : {
124 : case 0:
125 0 : if(m_pTable->GetTitleCtrl())
126 : {
127 0 : aRet = m_pTable->GetTitleCtrl()->GetAccessible();
128 0 : break;
129 : } // fall through if title control does not exist
130 : case 1:
131 0 : if(m_pTable->GetListBox())
132 0 : aRet = m_pTable->GetListBox()->GetAccessible();
133 0 : break;
134 : default:
135 0 : throw IndexOutOfBoundsException();
136 : }
137 : }
138 0 : return aRet;
139 : }
140 : // -----------------------------------------------------------------------------
141 0 : sal_Int32 SAL_CALL OTableWindowAccess::getAccessibleIndexInParent( ) throw (RuntimeException)
142 : {
143 0 : ::osl::MutexGuard aGuard( m_aMutex );
144 0 : sal_Int32 nIndex = -1;
145 0 : if( m_pTable )
146 : {
147 : // search the postion of our table window in the table window map
148 0 : OJoinTableView::OTableWindowMap* pMap = m_pTable->getTableView()->GetTabWinMap();
149 0 : OJoinTableView::OTableWindowMap::iterator aIter = pMap->begin();
150 0 : OJoinTableView::OTableWindowMap::iterator aEnd = pMap->end();
151 0 : for (nIndex = 0; aIter != aEnd && aIter->second != m_pTable; ++nIndex,++aIter)
152 : ;
153 0 : nIndex = aIter != aEnd ? nIndex : -1;
154 : }
155 0 : return nIndex;
156 : }
157 : // -----------------------------------------------------------------------------
158 0 : sal_Int16 SAL_CALL OTableWindowAccess::getAccessibleRole( ) throw (RuntimeException)
159 : {
160 0 : return AccessibleRole::PANEL; // ? or may be an AccessibleRole::WINDOW
161 : }
162 : // -----------------------------------------------------------------------------
163 0 : Reference< XAccessibleRelationSet > SAL_CALL OTableWindowAccess::getAccessibleRelationSet( ) throw (RuntimeException)
164 : {
165 0 : ::osl::MutexGuard aGuard( m_aMutex );
166 0 : return this;
167 : }
168 : // -----------------------------------------------------------------------------
169 : // XAccessibleComponent
170 0 : Reference< XAccessible > SAL_CALL OTableWindowAccess::getAccessibleAtPoint( const awt::Point& _aPoint ) throw (RuntimeException)
171 : {
172 0 : ::osl::MutexGuard aGuard( m_aMutex );
173 0 : Reference< XAccessible > aRet;
174 0 : if( m_pTable )
175 : {
176 0 : Point aPoint(_aPoint.X,_aPoint.Y);
177 0 : Rectangle aRect(m_pTable->GetDesktopRectPixel());
178 0 : if( aRect.IsInside(aPoint) )
179 0 : aRet = this;
180 0 : else if( m_pTable->GetListBox()->GetDesktopRectPixel().IsInside(aPoint))
181 0 : aRet = m_pTable->GetListBox()->GetAccessible();
182 : }
183 0 : return aRet;
184 : }
185 : // -----------------------------------------------------------------------------
186 0 : Reference< XAccessible > OTableWindowAccess::getParentChild(sal_Int32 _nIndex)
187 : {
188 0 : Reference< XAccessible > xReturn;
189 0 : Reference< XAccessible > xParent = getAccessibleParent();
190 0 : if ( xParent.is() )
191 : {
192 0 : Reference< XAccessibleContext > xParentContext = xParent->getAccessibleContext();
193 0 : if ( xParentContext.is() )
194 : {
195 0 : xReturn = xParentContext->getAccessibleChild(_nIndex);
196 0 : }
197 : }
198 0 : return xReturn;
199 : }
200 : // -----------------------------------------------------------------------------
201 :
202 0 : sal_Int32 SAL_CALL OTableWindowAccess::getRelationCount( ) throw (RuntimeException)
203 : {
204 0 : ::osl::MutexGuard aGuard( m_aMutex );
205 0 : return m_pTable ? m_pTable->getTableView()->getConnectionCount(m_pTable) : sal_Int32(0);
206 : }
207 : // -----------------------------------------------------------------------------
208 0 : AccessibleRelation SAL_CALL OTableWindowAccess::getRelation( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
209 : {
210 0 : ::osl::MutexGuard aGuard( m_aMutex );
211 0 : if( nIndex < 0 || nIndex >= getRelationCount() )
212 0 : throw IndexOutOfBoundsException();
213 :
214 0 : AccessibleRelation aRet;
215 0 : if( m_pTable )
216 : {
217 0 : OJoinTableView* pView = m_pTable->getTableView();
218 0 : ::std::vector<OTableConnection*>::const_iterator aIter = pView->getTableConnections(m_pTable) + nIndex;
219 0 : aRet.TargetSet.realloc(1);
220 0 : aRet.TargetSet[0] = getParentChild(aIter - pView->getTableConnections()->begin());
221 0 : aRet.RelationType = AccessibleRelationType::CONTROLLER_FOR;
222 : }
223 0 : return aRet;
224 : }
225 : // -----------------------------------------------------------------------------
226 0 : sal_Bool SAL_CALL OTableWindowAccess::containsRelation( sal_Int16 aRelationType ) throw (RuntimeException)
227 : {
228 0 : ::osl::MutexGuard aGuard( m_aMutex );
229 : return AccessibleRelationType::CONTROLLER_FOR == aRelationType
230 0 : && m_pTable && m_pTable->getTableView()->ExistsAConn(m_pTable);
231 : }
232 : // -----------------------------------------------------------------------------
233 0 : AccessibleRelation SAL_CALL OTableWindowAccess::getRelationByType( sal_Int16 aRelationType ) throw (RuntimeException)
234 : {
235 0 : ::osl::MutexGuard aGuard( m_aMutex );
236 0 : if( AccessibleRelationType::CONTROLLER_FOR == aRelationType && m_pTable)
237 : {
238 0 : OJoinTableView* pView = m_pTable->getTableView();
239 0 : const ::std::vector<OTableConnection*>* pConnectionList = pView->getTableConnections();
240 :
241 0 : ::std::vector<OTableConnection*>::const_iterator aIter = pView->getTableConnections(m_pTable);
242 0 : ::std::vector<OTableConnection*>::const_iterator aEnd = pConnectionList->end();
243 0 : ::std::vector< Reference<XInterface> > aRelations;
244 0 : aRelations.reserve(5); // just guessing
245 0 : for (; aIter != aEnd ; ++aIter )
246 : {
247 : uno::Reference<uno::XInterface> xInterface(
248 0 : getParentChild(aIter - pConnectionList->begin()));
249 0 : aRelations.push_back(xInterface);
250 0 : }
251 :
252 0 : Reference<XInterface> *pRelations = aRelations.empty() ? 0 : &aRelations[0];
253 0 : Sequence< Reference<XInterface> > aSeq(pRelations, aRelations.size());
254 0 : return AccessibleRelation(AccessibleRelationType::CONTROLLER_FOR,aSeq);
255 : }
256 0 : return AccessibleRelation();
257 : }
258 : // -----------------------------------------------------------------------------
259 0 : sal_Bool OTableWindowAccess::isEditable() const
260 : {
261 0 : return m_pTable && !m_pTable->getTableView()->getDesignView()->getController().isReadOnly();
262 : }
263 : // -----------------------------------------------------------------------------
264 0 : ::rtl::OUString SAL_CALL OTableWindowAccess::getTitledBorderText( ) throw (RuntimeException)
265 : {
266 0 : return getAccessibleName( );
267 : }
268 : // -----------------------------------------------------------------------------
269 0 : ::rtl::OUString SAL_CALL OTableWindowAccess::getAccessibleName( ) throw (RuntimeException)
270 : {
271 0 : ::osl::MutexGuard aGuard( m_aMutex );
272 0 : ::rtl::OUString sAccessibleName;
273 0 : if ( m_pTable )
274 0 : sAccessibleName = m_pTable->getTitle();
275 0 : return sAccessibleName;
276 : }
277 : // -----------------------------------------------------------------------------
278 0 : Reference< XAccessibleContext > SAL_CALL OTableWindowAccess::getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException)
279 : {
280 0 : return this;
281 : }
282 : // -----------------------------------------------------------------------------
283 :
284 : }
285 : // -----------------------------------------------------------------------------
286 :
287 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|