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