xref: /trunk/main/dbaccess/source/ui/querydesign/ConnectionLineAccess.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 #ifndef DBACCESS_CONNECTIONLINEACCESS_HXX
31 #include "ConnectionLineAccess.hxx"
32 #endif
33 #ifndef DBAUI_JOINTABLEVIEW_HXX
34 #include "JoinTableView.hxx"
35 #endif
36 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEROLE_HPP_
37 #include <com/sun/star/accessibility/AccessibleRole.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLERELATIONTYPE_HPP_
40 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
41 #endif
42 #ifndef _TOOLKIT_AWT_VCLXWINDOW_HXX_
43 #include <toolkit/awt/vclxwindow.hxx>
44 #endif
45 #ifndef DBAUI_TABLECONNECTION_HXX
46 #include "TableConnection.hxx"
47 #endif
48 #ifndef DBAUI_TABLEWINDOW_HXX
49 #include "TableWindow.hxx"
50 #endif
51 #ifndef _COMPHELPER_UNO3_HXX_
52 #include <comphelper/uno3.hxx>
53 #endif
54 #ifndef DBAUI_JOINDESIGNVIEW_HXX
55 #include "JoinDesignView.hxx"
56 #endif
57 #ifndef DBAUI_JOINCONTROLLER_HXX
58 #include "JoinController.hxx"
59 #endif
60 #ifndef _COMPHELPER_SEQUENCE_HXX_
61 #include <comphelper/sequence.hxx>
62 #endif
63 
64 namespace dbaui
65 {
66     using namespace ::com::sun::star::accessibility;
67     using namespace ::com::sun::star::uno;
68     using namespace ::com::sun::star::beans;
69     using namespace ::com::sun::star::lang;
70     //  using namespace ::com::sun::star::awt;
71     using namespace ::com::sun::star;
72 
73     OConnectionLineAccess::OConnectionLineAccess(OTableConnection* _pLine)
74         : VCLXAccessibleComponent(_pLine->GetComponentInterface().is() ? _pLine->GetWindowPeer() : NULL)
75         ,m_pLine(_pLine)
76     {
77     }
78     // -----------------------------------------------------------------------------
79     void SAL_CALL OConnectionLineAccess::disposing()
80     {
81         m_pLine = NULL;
82         VCLXAccessibleComponent::disposing();
83     }
84     // -----------------------------------------------------------------------------
85     Any SAL_CALL OConnectionLineAccess::queryInterface( const Type& aType ) throw (RuntimeException)
86     {
87         Any aRet(VCLXAccessibleComponent::queryInterface( aType ));
88         return aRet.hasValue() ? aRet : OConnectionLineAccess_BASE::queryInterface( aType );
89     }
90     // -----------------------------------------------------------------------------
91     Sequence< Type > SAL_CALL OConnectionLineAccess::getTypes(  ) throw (RuntimeException)
92     {
93         return ::comphelper::concatSequences(VCLXAccessibleComponent::getTypes(),OConnectionLineAccess_BASE::getTypes());
94     }
95     // -----------------------------------------------------------------------------
96     ::rtl::OUString SAL_CALL OConnectionLineAccess::getImplementationName() throw(RuntimeException)
97     {
98         return getImplementationName_Static();
99     }
100     // -----------------------------------------------------------------------------
101     // XServiceInfo - static methods
102     // -----------------------------------------------------------------------------
103     ::rtl::OUString OConnectionLineAccess::getImplementationName_Static(void) throw( RuntimeException )
104     {
105         return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbu.ConnectionLineAccessibility");
106     }
107     // -----------------------------------------------------------------------------
108     // XAccessibleContext
109     sal_Int32 SAL_CALL OConnectionLineAccess::getAccessibleChildCount(  ) throw (RuntimeException)
110     {
111         return 0;
112     }
113     // -----------------------------------------------------------------------------
114     Reference< XAccessible > SAL_CALL OConnectionLineAccess::getAccessibleChild( sal_Int32 /*i*/ ) throw (RuntimeException)
115     {
116         return Reference< XAccessible >();
117     }
118     // -----------------------------------------------------------------------------
119     sal_Int32 SAL_CALL OConnectionLineAccess::getAccessibleIndexInParent(  ) throw (RuntimeException)
120     {
121         ::osl::MutexGuard aGuard( m_aMutex  );
122         sal_Int32 nIndex = -1;
123         if( m_pLine )
124         {
125             // search the postion of our table window in the table window map
126             nIndex = m_pLine->GetParent()->GetTabWinMap()->size();
127             const ::std::vector<OTableConnection*>* pVec = m_pLine->GetParent()->getTableConnections();
128             ::std::vector<OTableConnection*>::const_iterator aIter = pVec->begin();
129             ::std::vector<OTableConnection*>::const_iterator aEnd = pVec->end();
130             for (; aIter != aEnd && (*aIter) != m_pLine; ++nIndex,++aIter)
131                 ;
132             nIndex = ( aIter != aEnd ) ? nIndex : -1;
133         }
134         return nIndex;
135     }
136     // -----------------------------------------------------------------------------
137     sal_Int16 SAL_CALL OConnectionLineAccess::getAccessibleRole(  ) throw (RuntimeException)
138     {
139         return AccessibleRole::UNKNOWN; // ? or may be an AccessibleRole::WINDOW
140     }
141     // -----------------------------------------------------------------------------
142     ::rtl::OUString SAL_CALL OConnectionLineAccess::getAccessibleDescription(  ) throw (RuntimeException)
143     {
144         static ::rtl::OUString sDescription(RTL_CONSTASCII_USTRINGPARAM("Relation"));
145         return sDescription;
146     }
147     // -----------------------------------------------------------------------------
148     Reference< XAccessibleRelationSet > SAL_CALL OConnectionLineAccess::getAccessibleRelationSet(  ) throw (RuntimeException)
149     {
150         ::osl::MutexGuard aGuard( m_aMutex  );
151         return this;
152     }
153     // -----------------------------------------------------------------------------
154     // XAccessibleComponent
155     sal_Bool SAL_CALL OConnectionLineAccess::contains( const awt::Point& _aPoint ) throw (RuntimeException)
156     {
157         ::osl::MutexGuard aGuard( m_aMutex  );
158         Point aPoint(_aPoint.X,_aPoint.Y);
159         return m_pLine ? m_pLine->CheckHit(aPoint) : sal_False;
160     }
161     // -----------------------------------------------------------------------------
162     Reference< XAccessible > SAL_CALL OConnectionLineAccess::getAccessibleAtPoint( const awt::Point& /*_aPoint*/ ) throw (RuntimeException)
163     {
164         return Reference< XAccessible >();
165     }
166     // -----------------------------------------------------------------------------
167     awt::Rectangle SAL_CALL OConnectionLineAccess::getBounds(  ) throw (RuntimeException)
168     {
169         ::osl::MutexGuard aGuard( m_aMutex  );
170         Rectangle aRect(m_pLine ? m_pLine->GetBoundingRect() : Rectangle());
171         return awt::Rectangle(aRect.getX(),aRect.getY(),aRect.getWidth(),aRect.getHeight());
172     }
173     // -----------------------------------------------------------------------------
174     awt::Point SAL_CALL OConnectionLineAccess::getLocation(  ) throw (RuntimeException)
175     {
176         ::osl::MutexGuard aGuard( m_aMutex  );
177         Point aPoint(m_pLine ? m_pLine->GetBoundingRect().TopLeft() : Point());
178         return awt::Point(aPoint.X(),aPoint.Y());
179     }
180     // -----------------------------------------------------------------------------
181     awt::Point SAL_CALL OConnectionLineAccess::getLocationOnScreen(  ) throw (RuntimeException)
182     {
183         ::osl::MutexGuard aGuard( m_aMutex  );
184         Point aPoint(m_pLine ? m_pLine->GetParent()->ScreenToOutputPixel(m_pLine->GetBoundingRect().TopLeft()) : Point());
185         return awt::Point(aPoint.X(),aPoint.Y());
186     }
187     // -----------------------------------------------------------------------------
188     awt::Size SAL_CALL OConnectionLineAccess::getSize(  ) throw (RuntimeException)
189     {
190         ::osl::MutexGuard aGuard( m_aMutex  );
191         Size aSize(m_pLine ? m_pLine->GetBoundingRect().GetSize() : Size());
192         return awt::Size(aSize.Width(),aSize.Height());
193     }
194     // -----------------------------------------------------------------------------
195     sal_Bool SAL_CALL OConnectionLineAccess::isShowing(  ) throw (RuntimeException)
196     {
197         ::osl::MutexGuard aGuard( m_aMutex  );
198         return m_pLine ? m_pLine->GetParent()->GetWindowRegionPixel().IsInside(m_pLine->GetBoundingRect()) : sal_False;
199     }
200     // -----------------------------------------------------------------------------
201     sal_Bool SAL_CALL OConnectionLineAccess::isVisible(  ) throw (RuntimeException)
202     {
203         return sal_True;
204     }
205     // -----------------------------------------------------------------------------
206     sal_Bool SAL_CALL OConnectionLineAccess::isFocusTraversable(  ) throw (RuntimeException)
207     {
208         return sal_True;
209     }
210     // -----------------------------------------------------------------------------
211     // XAccessibleRelationSet
212     // -----------------------------------------------------------------------------
213     sal_Int32 SAL_CALL OConnectionLineAccess::getRelationCount(  ) throw (RuntimeException)
214     {
215         return 1;
216     }
217     // -----------------------------------------------------------------------------
218     AccessibleRelation SAL_CALL OConnectionLineAccess::getRelation( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
219     {
220         ::osl::MutexGuard aGuard( m_aMutex  );
221         if( nIndex < 0 || nIndex >= getRelationCount() )
222             throw IndexOutOfBoundsException();
223 
224         Sequence< Reference<XInterface> > aSeq(m_pLine ? 2 : 0);
225         if( m_pLine )
226         {
227             aSeq[0] = m_pLine->GetSourceWin()->GetAccessible();
228             aSeq[1] = m_pLine->GetDestWin()->GetAccessible();
229         }
230 
231         return AccessibleRelation(AccessibleRelationType::CONTROLLED_BY,aSeq);
232     }
233     // -----------------------------------------------------------------------------
234     sal_Bool SAL_CALL OConnectionLineAccess::containsRelation( sal_Int16 aRelationType ) throw (RuntimeException)
235     {
236         return AccessibleRelationType::CONTROLLED_BY == aRelationType;
237     }
238     // -----------------------------------------------------------------------------
239     AccessibleRelation SAL_CALL OConnectionLineAccess::getRelationByType( sal_Int16 aRelationType ) throw (RuntimeException)
240     {
241         if( AccessibleRelationType::CONTROLLED_BY == aRelationType )
242             return getRelation(0);
243         return AccessibleRelation();
244     }
245     // -----------------------------------------------------------------------------
246     Reference< XAccessible > OTableConnection::CreateAccessible()
247     {
248         return new OConnectionLineAccess(this);
249     }
250     // -----------------------------------------------------------------------------
251     OTableConnection::~OTableConnection()
252     {
253         DBG_DTOR(OTableConnection,NULL);
254         //////////////////////////////////////////////////////////////////////
255         // clear vector
256         clearLineData();
257     }
258     // -----------------------------------------------------------------------------
259     sal_Bool OConnectionLineAccess::isEditable() const
260     {
261 
262         return m_pLine ? !m_pLine->GetParent()->getDesignView()->getController().isReadOnly() : sal_False;
263     }
264     // -----------------------------------------------------------------------------
265     Reference< XAccessibleContext > SAL_CALL OConnectionLineAccess::getAccessibleContext(  ) throw (::com::sun::star::uno::RuntimeException)
266     {
267         return this;
268     }
269     // -----------------------------------------------------------------------------
270 }
271 // -----------------------------------------------------------------------------
272 
273