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_dbaccess.hxx"
26 #ifndef DBACCESS_CONNECTIONLINEACCESS_HXX
27 #include "ConnectionLineAccess.hxx"
28 #endif
29 #ifndef DBAUI_JOINTABLEVIEW_HXX
30 #include "JoinTableView.hxx"
31 #endif
32 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEROLE_HPP_
33 #include <com/sun/star/accessibility/AccessibleRole.hpp>
34 #endif
35 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLERELATIONTYPE_HPP_
36 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
37 #endif
38 #ifndef _TOOLKIT_AWT_VCLXWINDOW_HXX_
39 #include <toolkit/awt/vclxwindow.hxx>
40 #endif
41 #ifndef DBAUI_TABLECONNECTION_HXX
42 #include "TableConnection.hxx"
43 #endif
44 #ifndef DBAUI_TABLEWINDOW_HXX
45 #include "TableWindow.hxx"
46 #endif
47 #ifndef _COMPHELPER_UNO3_HXX_
48 #include <comphelper/uno3.hxx>
49 #endif
50 #ifndef DBAUI_JOINDESIGNVIEW_HXX
51 #include "JoinDesignView.hxx"
52 #endif
53 #ifndef DBAUI_JOINCONTROLLER_HXX
54 #include "JoinController.hxx"
55 #endif
56 #ifndef _COMPHELPER_SEQUENCE_HXX_
57 #include <comphelper/sequence.hxx>
58 #endif
59 
60 namespace dbaui
61 {
62 	using namespace ::com::sun::star::accessibility;
63 	using namespace ::com::sun::star::uno;
64 	using namespace ::com::sun::star::beans;
65 	using namespace ::com::sun::star::lang;
66 	//	using namespace ::com::sun::star::awt;
67 	using namespace ::com::sun::star;
68 
69 	OConnectionLineAccess::OConnectionLineAccess(OTableConnection* _pLine)
70 		: VCLXAccessibleComponent(_pLine->GetComponentInterface().is() ? _pLine->GetWindowPeer() : NULL)
71 		,m_pLine(_pLine)
72 	{
73 	}
74 	// -----------------------------------------------------------------------------
75 	void SAL_CALL OConnectionLineAccess::disposing()
76 	{
77 		m_pLine = NULL;
78 		VCLXAccessibleComponent::disposing();
79 	}
80 	// -----------------------------------------------------------------------------
81 	Any SAL_CALL OConnectionLineAccess::queryInterface( const Type& aType ) throw (RuntimeException)
82 	{
83 		Any aRet(VCLXAccessibleComponent::queryInterface( aType ));
84 		return aRet.hasValue() ? aRet : OConnectionLineAccess_BASE::queryInterface( aType );
85 	}
86 	// -----------------------------------------------------------------------------
87 	Sequence< Type > SAL_CALL OConnectionLineAccess::getTypes(  ) throw (RuntimeException)
88 	{
89 		return ::comphelper::concatSequences(VCLXAccessibleComponent::getTypes(),OConnectionLineAccess_BASE::getTypes());
90 	}
91 	// -----------------------------------------------------------------------------
92 	::rtl::OUString SAL_CALL OConnectionLineAccess::getImplementationName() throw(RuntimeException)
93 	{
94 		return getImplementationName_Static();
95 	}
96 	// -----------------------------------------------------------------------------
97 	// XServiceInfo - static methods
98 	// -----------------------------------------------------------------------------
99 	::rtl::OUString OConnectionLineAccess::getImplementationName_Static(void) throw( RuntimeException )
100 	{
101 		return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbu.ConnectionLineAccessibility");
102 	}
103 	// -----------------------------------------------------------------------------
104 	// XAccessibleContext
105 	sal_Int32 SAL_CALL OConnectionLineAccess::getAccessibleChildCount(  ) throw (RuntimeException)
106 	{
107 		return 0;
108 	}
109 	// -----------------------------------------------------------------------------
110 	Reference< XAccessible > SAL_CALL OConnectionLineAccess::getAccessibleChild( sal_Int32 /*i*/ ) throw (RuntimeException)
111 	{
112 		return Reference< XAccessible >();
113 	}
114 	// -----------------------------------------------------------------------------
115 	sal_Int32 SAL_CALL OConnectionLineAccess::getAccessibleIndexInParent(  ) throw (RuntimeException)
116 	{
117 		::osl::MutexGuard aGuard( m_aMutex  );
118 		sal_Int32 nIndex = -1;
119 		if( m_pLine )
120 		{
121 			// search the position of our table window in the table window map
122 			nIndex = m_pLine->GetParent()->GetTabWinMap()->size();
123 			const ::std::vector<OTableConnection*>* pVec = m_pLine->GetParent()->getTableConnections();
124 			::std::vector<OTableConnection*>::const_iterator aIter = pVec->begin();
125             ::std::vector<OTableConnection*>::const_iterator aEnd = pVec->end();
126 			for (; aIter != aEnd && (*aIter) != m_pLine; ++nIndex,++aIter)
127 				;
128 			nIndex = ( aIter != aEnd ) ? nIndex : -1;
129 		}
130 		return nIndex;
131 	}
132 	// -----------------------------------------------------------------------------
133 	sal_Int16 SAL_CALL OConnectionLineAccess::getAccessibleRole(  ) throw (RuntimeException)
134 	{
135 		return AccessibleRole::UNKNOWN; // ? or may be an AccessibleRole::WINDOW
136 	}
137 	// -----------------------------------------------------------------------------
138 	::rtl::OUString SAL_CALL OConnectionLineAccess::getAccessibleDescription(  ) throw (RuntimeException)
139 	{
140 		static ::rtl::OUString sDescription(RTL_CONSTASCII_USTRINGPARAM("Relation"));
141 		return sDescription;
142 	}
143 	// -----------------------------------------------------------------------------
144 	Reference< XAccessibleRelationSet > SAL_CALL OConnectionLineAccess::getAccessibleRelationSet(  ) throw (RuntimeException)
145 	{
146 		::osl::MutexGuard aGuard( m_aMutex  );
147 		return this;
148 	}
149 	// -----------------------------------------------------------------------------
150 	// XAccessibleComponent
151 	sal_Bool SAL_CALL OConnectionLineAccess::contains( const awt::Point& _aPoint ) throw (RuntimeException)
152 	{
153 		::osl::MutexGuard aGuard( m_aMutex  );
154 		Point aPoint(_aPoint.X,_aPoint.Y);
155 		return m_pLine ? m_pLine->CheckHit(aPoint) : sal_False;
156 	}
157 	// -----------------------------------------------------------------------------
158 	Reference< XAccessible > SAL_CALL OConnectionLineAccess::getAccessibleAtPoint( const awt::Point& /*_aPoint*/ ) throw (RuntimeException)
159 	{
160 		return Reference< XAccessible >();
161 	}
162 	// -----------------------------------------------------------------------------
163 	awt::Rectangle SAL_CALL OConnectionLineAccess::getBounds(  ) throw (RuntimeException)
164 	{
165 		::osl::MutexGuard aGuard( m_aMutex  );
166 		Rectangle aRect(m_pLine ? m_pLine->GetBoundingRect() : Rectangle());
167 		return awt::Rectangle(aRect.getX(),aRect.getY(),aRect.getWidth(),aRect.getHeight());
168 	}
169 	// -----------------------------------------------------------------------------
170 	awt::Point SAL_CALL OConnectionLineAccess::getLocation(  ) throw (RuntimeException)
171 	{
172 		::osl::MutexGuard aGuard( m_aMutex  );
173 		Point aPoint(m_pLine ? m_pLine->GetBoundingRect().TopLeft() : Point());
174 		return awt::Point(aPoint.X(),aPoint.Y());
175 	}
176 	// -----------------------------------------------------------------------------
177 	awt::Point SAL_CALL OConnectionLineAccess::getLocationOnScreen(  ) throw (RuntimeException)
178 	{
179 		::osl::MutexGuard aGuard( m_aMutex  );
180 		Point aPoint(m_pLine ? m_pLine->GetParent()->ScreenToOutputPixel(m_pLine->GetBoundingRect().TopLeft()) : Point());
181 		return awt::Point(aPoint.X(),aPoint.Y());
182 	}
183 	// -----------------------------------------------------------------------------
184 	awt::Size SAL_CALL OConnectionLineAccess::getSize(  ) throw (RuntimeException)
185 	{
186 		::osl::MutexGuard aGuard( m_aMutex  );
187 		Size aSize(m_pLine ? m_pLine->GetBoundingRect().GetSize() : Size());
188 		return awt::Size(aSize.Width(),aSize.Height());
189 	}
190 	// -----------------------------------------------------------------------------
191 	sal_Bool SAL_CALL OConnectionLineAccess::isShowing(  ) throw (RuntimeException)
192 	{
193 		::osl::MutexGuard aGuard( m_aMutex  );
194 		return m_pLine ? m_pLine->GetParent()->GetWindowRegionPixel().IsInside(m_pLine->GetBoundingRect()) : sal_False;
195 	}
196 	// -----------------------------------------------------------------------------
197 	sal_Bool SAL_CALL OConnectionLineAccess::isVisible(  ) throw (RuntimeException)
198 	{
199 		return sal_True;
200 	}
201 	// -----------------------------------------------------------------------------
202 	sal_Bool SAL_CALL OConnectionLineAccess::isFocusTraversable(  ) throw (RuntimeException)
203 	{
204 		return sal_True;
205 	}
206 	// -----------------------------------------------------------------------------
207 	// XAccessibleRelationSet
208 	// -----------------------------------------------------------------------------
209 	sal_Int32 SAL_CALL OConnectionLineAccess::getRelationCount(  ) throw (RuntimeException)
210 	{
211 		return 1;
212 	}
213 	// -----------------------------------------------------------------------------
214 	AccessibleRelation SAL_CALL OConnectionLineAccess::getRelation( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
215 	{
216 		::osl::MutexGuard aGuard( m_aMutex  );
217 		if( nIndex < 0 || nIndex >= getRelationCount() )
218 			throw IndexOutOfBoundsException();
219 
220 		Sequence< Reference<XInterface> > aSeq(m_pLine ? 2 : 0);
221 		if( m_pLine )
222 		{
223 			aSeq[0] = m_pLine->GetSourceWin()->GetAccessible();
224 			aSeq[1] = m_pLine->GetDestWin()->GetAccessible();
225 		}
226 
227 		return AccessibleRelation(AccessibleRelationType::CONTROLLED_BY,aSeq);
228 	}
229 	// -----------------------------------------------------------------------------
230 	sal_Bool SAL_CALL OConnectionLineAccess::containsRelation( sal_Int16 aRelationType ) throw (RuntimeException)
231 	{
232 		return AccessibleRelationType::CONTROLLED_BY == aRelationType;
233 	}
234 	// -----------------------------------------------------------------------------
235 	AccessibleRelation SAL_CALL OConnectionLineAccess::getRelationByType( sal_Int16 aRelationType ) throw (RuntimeException)
236 	{
237 		if( AccessibleRelationType::CONTROLLED_BY == aRelationType )
238 			return getRelation(0);
239 		return AccessibleRelation();
240 	}
241 	// -----------------------------------------------------------------------------
242 	Reference< XAccessible > OTableConnection::CreateAccessible()
243 	{
244 		return new OConnectionLineAccess(this);
245 	}
246 	// -----------------------------------------------------------------------------
247 	OTableConnection::~OTableConnection()
248 	{
249 		DBG_DTOR(OTableConnection,NULL);
250 		//////////////////////////////////////////////////////////////////////
251 		// clear vector
252 		clearLineData();
253 	}
254 	// -----------------------------------------------------------------------------
255 	sal_Bool OConnectionLineAccess::isEditable() const
256 	{
257 
258 		return m_pLine ? !m_pLine->GetParent()->getDesignView()->getController().isReadOnly() : sal_False;
259 	}
260 	// -----------------------------------------------------------------------------
261 	Reference< XAccessibleContext > SAL_CALL OConnectionLineAccess::getAccessibleContext(  ) throw (::com::sun::star::uno::RuntimeException)
262 	{
263 		return this;
264 	}
265 	// -----------------------------------------------------------------------------
266 }
267 // -----------------------------------------------------------------------------
268 
269