xref: /AOO41X/main/svx/source/inc/GraphCtlAccessibleContext.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 
29 #ifndef _SVXGRAPHACCESSIBLECONTEXT_HXX
30 #define _SVXGRAPHACCESSIBLECONTEXT_HXX
31 
32 #ifndef _CPPUHELPER_IMPLBASE7_HXX_
33 #include <cppuhelper/compbase7.hxx>
34 #endif
35 #include <com/sun/star/uno/Reference.hxx>
36 #include <com/sun/star/accessibility/XAccessible.hpp>
37 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
38 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
39 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
40 #ifndef _COM_SUN_STAR_ACCESSIBILITY_IllegalAccessibleComponentStateException_HPP_
41 #include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
42 #endif
43 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
44 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
45 #include <cppuhelper/weak.hxx>
46 #include <com/sun/star/lang/XServiceInfo.hpp>
47 #include <com/sun/star/lang/XTypeProvider.hpp>
48 #include <com/sun/star/lang/XServiceName.hpp>
49 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
50 #include <vos/mutex.hxx>
51 #include <comphelper/broadcasthelper.hxx>
52 #include <svl/lstner.hxx>
53 
54 #include <set>
55 #include <map>
56 
57 #include <comphelper/servicehelper.hxx>
58 #include <svx/rectenum.hxx>
59 #include <svx/AccessibleShapeTreeInfo.hxx>
60 #include <svx/IAccessibleViewForwarder.hxx>
61 #include <svx/AccessibleShape.hxx>
62 
63 namespace com { namespace sun { namespace star { namespace awt {
64 	struct Point;
65 	struct Rectangle;
66 	struct Size;
67 	class XFocusListener;
68 } } } }
69 
70 class Rectangle;
71 class GraphCtrl;
72 class Window;
73 class SdrObject;
74 class SdrModel;
75 class SdrPage;
76 class SdrView;
77 
78 /**	@descr
79         This base class provides an implementation of the
80         <code>AccessibleContext</code> service.
81 */
82 
83 typedef ::cppu::WeakAggComponentImplHelper7<
84 				::com::sun::star::accessibility::XAccessible,
85 				::com::sun::star::accessibility::XAccessibleComponent,
86                 ::com::sun::star::accessibility::XAccessibleContext,
87 				::com::sun::star::accessibility::XAccessibleEventBroadcaster,
88 				::com::sun::star::accessibility::XAccessibleSelection,
89                 ::com::sun::star::lang::XServiceInfo,
90                 ::com::sun::star::lang::XServiceName >
91 				SvxGraphCtrlAccessibleContext_Base;
92 
93 class SvxGraphCtrlAccessibleContext : public SvxGraphCtrlAccessibleContext_Base, ::comphelper::OBaseMutex, SfxListener, ::accessibility::IAccessibleViewForwarder
94 {
95 public:
96 	friend class GraphCtrl;
97 
98 	//=====  internal  ========================================================
99 	SvxGraphCtrlAccessibleContext(
100         const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible>& rxParent,
101 		GraphCtrl&				rRepresentation,
102 		const ::rtl::OUString*	pName = NULL,
103 		const ::rtl::OUString*	pDescription = NULL );
104 
105 	void Notify( SfxBroadcaster& aBC, const	SfxHint& aHint );
106 
107 protected:
108 	virtual ~SvxGraphCtrlAccessibleContext();
109 public:
110 	//=====  XAccessible  =====================================================
111 
112     ///	Return the XAccessibleContext.
113     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext> SAL_CALL
114     	getAccessibleContext (void) throw (::com::sun::star::uno::RuntimeException);
115 
116 	//=====  XAccessibleComponent  ============================================
117 
118     virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& rPoint ) throw (::com::sun::star::uno::RuntimeException);
119     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const ::com::sun::star::awt::Point& rPoint )	throw (::com::sun::star::uno::RuntimeException);
120     virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds() throw (::com::sun::star::uno::RuntimeException);
121     virtual ::com::sun::star::awt::Point SAL_CALL getLocation() throw (::com::sun::star::uno::RuntimeException);
122     virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen() throw (::com::sun::star::uno::RuntimeException);
123     virtual ::com::sun::star::awt::Size SAL_CALL getSize() throw (::com::sun::star::uno::RuntimeException);
124     virtual void SAL_CALL addFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
125 	virtual void SAL_CALL removeFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
126     virtual void SAL_CALL grabFocus() throw (::com::sun::star::uno::RuntimeException);
127     virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding() throw (::com::sun::star::uno::RuntimeException);
128 
129     virtual sal_Int32 SAL_CALL getForeground (void)
130         throw (::com::sun::star::uno::RuntimeException);
131 
132     virtual sal_Int32 SAL_CALL getBackground (void)
133         throw (::com::sun::star::uno::RuntimeException);
134 
135 
136 	//=====  XAccessibleContext  ==============================================
137 
138     virtual sal_Int32 SAL_CALL getAccessibleChildCount (void) throw (::com::sun::star::uno::RuntimeException);
139     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL getAccessibleChild (sal_Int32 nIndex) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IndexOutOfBoundsException);
140 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL getAccessibleParent (void) throw (::com::sun::star::uno::RuntimeException);
141 	virtual	sal_Int32 SAL_CALL getAccessibleIndexInParent (void) throw (::com::sun::star::uno::RuntimeException);
142 	virtual sal_Int16 SAL_CALL getAccessibleRole (void) throw (::com::sun::star::uno::RuntimeException);
143 	virtual ::rtl::OUString SAL_CALL getAccessibleDescription (void) throw (::com::sun::star::uno::RuntimeException);
144 	virtual ::rtl::OUString SAL_CALL getAccessibleName (void) throw (::com::sun::star::uno::RuntimeException);
145 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL getAccessibleRelationSet (void) throw (::com::sun::star::uno::RuntimeException);
146 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet> SAL_CALL getAccessibleStateSet (void) throw (::com::sun::star::uno::RuntimeException);
147 	virtual ::com::sun::star::lang::Locale SAL_CALL	getLocale (void) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::accessibility::IllegalAccessibleComponentStateException);
148 //	virtual void SAL_CALL addPropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) {}
149 //  virtual void SAL_CALL removePropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) {}
150 
151     //=====  XComponent  ========================================================
152 
153 	using ::cppu::WeakAggComponentImplHelperBase::addEventListener;
154     using ::cppu::WeakAggComponentImplHelperBase::removeEventListener;
155 
156 	//=====  XAccessibleEventBroadcaster  =====================================
157 
158 	virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener>& xListener) throw (com::sun::star::uno::RuntimeException);
159 	virtual void SAL_CALL removeEventListener(	const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener>& xListener) throw (com::sun::star::uno::RuntimeException);
160 
161 	//=====  XServiceInfo  ====================================================
162 
163 	virtual ::rtl::OUString SAL_CALL getImplementationName (void) throw (::com::sun::star::uno::RuntimeException);
164     virtual sal_Bool SAL_CALL supportsService (const ::rtl::OUString& sServiceName) throw (::com::sun::star::uno::RuntimeException);
165 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL getSupportedServiceNames (void) throw (::com::sun::star::uno::RuntimeException);
166 
167 	//=====  XTypeProvider  ===================================================
168 
169     virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId (void) throw (::com::sun::star::uno::RuntimeException);
170 
171     //=====  XServiceName  ====================================================
172 
173 	virtual ::rtl::OUString SAL_CALL getServiceName (void) throw (::com::sun::star::uno::RuntimeException);
174 
175 	//=====  XAccessibleSelection =============================================
176 
177     virtual void SAL_CALL selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
178     virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
179     virtual void SAL_CALL clearAccessibleSelection() throw (::com::sun::star::uno::RuntimeException );
180     virtual void SAL_CALL selectAllAccessibleChildren() throw (::com::sun::star::uno::RuntimeException );
181     virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount() throw (::com::sun::star::uno::RuntimeException );
182     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
183 	virtual void SAL_CALL deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
184 
185     //=====  IAccessibleViewforwarder  ========================================
186 
187 	virtual sal_Bool IsValid (void) const;
188     virtual Rectangle GetVisibleArea() const;
189     virtual Point LogicToPixel (const Point& rPoint) const;
190     virtual Size LogicToPixel (const Size& rSize) const;
191     virtual Point PixelToLogic (const Point& rPoint) const;
192     virtual Size PixelToLogic (const Size& rSize) const;
193 
194 protected:
195 	//=====  internals ========================================================
196 
197 	void checkChildIndex( long nIndexOfChild ) throw (::com::sun::star::lang::IndexOutOfBoundsException );
198 	void checkChildIndexOnSelection( long nIndexOfChild ) throw (::com::sun::star::lang::IndexOutOfBoundsException );
199 
200 public:
201 
202 	/// Sets the name
203 	void setName( const ::rtl::OUString& rName );
204 
205 	/// Sets the description
206 	void setDescription( const ::rtl::OUString& rDescr );
207 
208     /** This method is used by the graph control to tell the
209         accessibility object about a new model and view.
210     */
211     void setModelAndView (SdrModel* pModel, SdrView* pView);
212 
213 private:
214 	static ::com::sun::star::uno::Sequence< sal_Int8 > getUniqueId( void );
215 protected:
216 
217     /**	Return the object's current bounding box relative to the desktop,
218         i.e in absolute pixel coordinates.
219         @return
220             The returned rectangle is a bounding box of the object given in
221             absolute screen coordinates.
222         @raise DisposedException
223             When the object is already disposed then a
224             <type>DisposedException</type> is thrown.
225     */
226  	virtual Rectangle GetBoundingBoxOnScreen(void) throw (::com::sun::star::uno::RuntimeException);
227 
228 	///	Return the object's current bounding box relative to the parent object.
229 	virtual Rectangle GetBoundingBox(void) throw (::com::sun::star::uno::RuntimeException);
230 
231 	virtual void SAL_CALL disposing();
232 
233 private:
234 	SdrObject* getSdrObject( sal_Int32 nIndex )
235 		throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IndexOutOfBoundsException );
236 
237 	void CommitChange (sal_Int16 aEventId, const ::com::sun::star::uno::Any& rNewValue, const ::com::sun::star::uno::Any& rOldValue);
238 	void FireEvent (const ::com::sun::star::accessibility::AccessibleEventObject& aEvent);
239 
240 	::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessible( const SdrObject* pObj );
241 
242 	accessibility::AccessibleShapeTreeInfo maTreeInfo;
243 
244     ///	Reference to the parent object.
245     ::com::sun::star::uno::Reference<
246     	 ::com::sun::star::accessibility::XAccessible> mxParent;
247 
248     /**	Description of this object.  This is not a constant because it can
249     	be set from the outside.
250     */
251     ::rtl::OUString msDescription;
252 
253     /**	Name of this object.
254     */
255     ::rtl::OUString msName;
256 
257     ///	map of accessible shapes
258 	struct SdrObjectCompareLess
259 	{
260 		bool operator()(const SdrObject* p1, const SdrObject* p2) const
261 		{
262 			return p1 < p2;
263 		}
264 	};
265 	typedef ::std::map< const SdrObject*, ::accessibility::AccessibleShape*, SdrObjectCompareLess > ShapesMapType;
266 	ShapesMapType mxShapes;
267 
268 	GraphCtrl*	mpControl;
269 
270 	SdrModel* mpModel;
271 	SdrPage* mpPage;
272 	SdrView* mpView;
273 
274     /// client id in the AccessibleEventNotifier queue
275     sal_uInt32 mnClientId;
276 
277 	sal_Bool mbDisposed;
278 };
279 
280 #endif
281 
282