xref: /aoo42x/main/sw/source/core/access/acccontext.hxx (revision fb0b81f5)
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 #ifndef _ACCBASE_HXX
24 #define _ACCBASE_HXX
25 #include <accframe.hxx>
26 #include <accmap.hxx>
27 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
28 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
29 #include <com/sun/star/lang/DisposedException.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <cppuhelper/implbase5.hxx>
32 #include <cppuhelper/interfacecontainer.hxx>
33 
34 class Window;
35 class SwAccessibleMap;
36 class SwCrsrShell;
37 class SdrObject;
38 class SwPaM;
39 namespace utl {
40     class AccessibleStateSetHelper;
41 }
42 namespace accessibility {
43     class AccessibleShape;
44 }
45 class SwFmtFld;
46 class SwAccessibleChildContainer;
47 
48 const sal_Char sAccessibleServiceName[] = "com.sun.star.accessibility.Accessible";
49 
50 class SwAccessibleContext :
51 	public ::cppu::WeakImplHelper5<
52 				::com::sun::star::accessibility::XAccessible,
53                 ::com::sun::star::accessibility::XAccessibleContext,
54                 ::com::sun::star::accessibility::XAccessibleComponent,
55 				::com::sun::star::accessibility::XAccessibleEventBroadcaster,
56                 ::com::sun::star::lang::XServiceInfo
57                 >,
58 	public SwAccessibleFrame
59 {
60     // The implements for the XAccessibleSelection interface has been
61     // 'externalized' and wants access to the protected members like
62     // GetMap, GetChild, GetParent, and GetFrm.
63     friend class SwAccessibleSelectionHelper;
64 
65 
66 protected:
67 
68 	mutable ::osl::Mutex aListenerMutex;
69 	mutable ::vos::OMutex aMutex;
70 
71 private:
72 
73 	::rtl::OUString sName;	// immutable outside constructor
74 
75 	// The parent if it has been retrieved. This is always an
76 	// SwAccessibleContext. (protected by Mutex)
77 	::com::sun::star::uno::WeakReference <
78 		::com::sun::star::accessibility::XAccessible > xWeakParent;
79 
80 	SwAccessibleMap *pMap; 	// must be protected by solar mutex
81 
82     sal_uInt32 nClientId;   // client id in the AccessibleEventNotifier queue
83     sal_Int16 nRole;		// immutable outside constructor
84 
85 	// The current states (protected by mutex)
86 	sal_Bool bIsShowingState : 1;
87 	sal_Bool bIsEditableState : 1;
88 	sal_Bool bIsOpaqueState : 1;
89 	sal_Bool bIsDefuncState : 1;
90 
91 	// Are we currently disposing that object (protected by solar mutex)?
92 	sal_Bool bDisposing : 1;
93 
94     // --> OD 2008-03-10 #i85634#
95     // boolean, indicating if the accessible context is in general registered at
96     // the accessible map.
97     bool bRegisteredAtAccessibleMap;
98     // <--
99 
100 	void InitStates();
101 	//Solution:Add a member to identify the firt time that document load
102 	sal_Bool bBeginDocumentLoad;
103 
104 protected:
SetName(const::rtl::OUString & rName)105 	void SetName( const ::rtl::OUString& rName ) { sName = rName; }
GetRole() const106     inline sal_Int16 GetRole() const
107     {
108         return nRole;
109     }
110 	//Solution:Add a member to identify if the document is Asyn load.
111     sal_Bool isIfAsynLoad;
112 	//This flag is used to mark the object's selected state.
113 	sal_Bool   bIsSeletedInDoc;
114 	void SetParent( SwAccessibleContext *pParent );
115 	::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> GetWeakParent() const;
116 
IsDisposing() const117 	sal_Bool IsDisposing() const { return bDisposing; }
118 
119 	Window *GetWindow();
GetMap()120 	SwAccessibleMap *GetMap() { return pMap; }
GetMap() const121 	const SwAccessibleMap *GetMap() const { return pMap; }
122 
123     /** convenience method to get the SwViewShell through accessibility map */
GetShell()124     inline ViewShell* GetShell()
125     {
126         return GetMap()->GetShell();
127     }
GetShell() const128     inline const ViewShell* GetShell() const
129     {
130         return GetMap()->GetShell();
131     }
132 
133     /** convenience method to get SwCrsrShell through accessibility map
134      * @returns SwCrsrShell, or NULL if none is found */
135     SwCrsrShell* GetCrsrShell();
136     const SwCrsrShell* GetCrsrShell() const;
137 
138 	// Notify all children that the vis araea has changed.
139 	// The SwFrm might belong to the current object or to any other child or
140 	// grandchild.
141 	void ChildrenScrolled( const SwFrm *pFrm, const SwRect& rOldVisArea );
142 
143 	// The context's showing state changed. May only be called for context that
144 	// exist even if they aren't visible.
145 	void Scrolled( const SwRect& rOldVisArea );
146 
147 	// A child has been moved while setting the vis area
148 	void ScrolledWithin( const SwRect& rOldVisArea );
149 
150 	// The has been added while setting the vis area
151 	void ScrolledIn();
152 
153 	// The context has to be removed while setting the vis area
154 	void ScrolledOut( const SwRect& rOldVisArea );
155 
156 	// Invalidate the states of all children of the specified SwFrm. The
157 	// SwFrm might belong to the current object or to any child or grandchild!
158     // --> OD 2005-12-12 #i27301# - use new type definition for <_nStates>
159     void InvalidateChildrenStates( const SwFrm* _pFrm,
160                                    tAccessibleStates _nStates );
161     // <--
162 
163 	// Dispose children of the specified SwFrm. The SwFrm might belong to
164 	// the current object or to any other child or grandchild.
165 	void DisposeChildren( const SwFrm *pFrm,
166 									   sal_Bool bRecursive );
167 
168 	void DisposeShape( const SdrObject *pObj,
169 								::accessibility::AccessibleShape *pAccImpl );
170 	void ScrolledInShape( const SdrObject *pObj,
171 								::accessibility::AccessibleShape *pAccImpl );
172 
173 	virtual void _InvalidateContent( sal_Bool bVisibleDataFired );
174 
175 	virtual void _InvalidateCursorPos();
176 	virtual void _InvalidateFocus();
177 
178 public:
179 
SetMap(SwAccessibleMap * pM)180 	void SetMap(SwAccessibleMap *pM){pMap = pM;}
181 	void FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventObject& rEvent );
182 
183 protected:
184 
185 	// broadcast visual data event
186 	void FireVisibleDataEvent();
187 
188 	// broadcast state change event
189 	void FireStateChangedEvent( sal_Int16 nState, sal_Bool bNewState );
190 
191 	// Set states for getAccessibleStateSet.
192 	// This base class sets DEFUNC(0/1), EDITABLE(0/1), ENABLED(1),
193 	// SHOWING(0/1), OPAQUE(0/1) and VISIBLE(1).
194 	virtual void GetStates( ::utl::AccessibleStateSetHelper& rStateSet );
195 
196  	sal_Bool IsEditableState();
197 
198     virtual ::com::sun::star::awt::Rectangle SAL_CALL
199         getBoundsImpl(sal_Bool bRelative)
200 		throw (::com::sun::star::uno::RuntimeException);
201 
202     // --> OD 2008-03-10 #i85634#
NotRegisteredAtAccessibleMap()203     inline void NotRegisteredAtAccessibleMap()
204     {
205         bRegisteredAtAccessibleMap = false;
206     }
207     void RemoveFrmFromAccessibleMap();
208     // <--
209 
210 	virtual ~SwAccessibleContext();
211 
212 public:
213 
214 	SwAccessibleContext( SwAccessibleMap *pMap, sal_Int16 nRole,
215 						 const SwFrm *pFrm );
216 
217 	//=====  XAccessible  =====================================================
218 
219     ///	Return the XAccessibleContext.
220     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext> SAL_CALL
221     	getAccessibleContext (void) throw (com::sun::star::uno::RuntimeException);
222 
223 	//=====  XAccessibleContext  ==============================================
224 
225     ///	Return the number of currently visible children.
226     virtual sal_Int32 SAL_CALL getAccessibleChildCount (void)
227         throw (::com::sun::star::uno::RuntimeException);
228 
229     ///	Return the specified child or NULL if index is invalid.
230     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
231     	getAccessibleChild (sal_Int32 nIndex)
232         throw (::com::sun::star::uno::RuntimeException,
233 				::com::sun::star::lang::IndexOutOfBoundsException);
234 
235     ///	Return a reference to the parent.
236 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
237     	getAccessibleParent (void)
238         throw (::com::sun::star::uno::RuntimeException);
239 
240     ///	Return this objects index among the parents children.
241 	virtual	sal_Int32 SAL_CALL
242     	getAccessibleIndexInParent (void)
243         throw (::com::sun::star::uno::RuntimeException);
244 
245     ///	Return this object's role.
246 	virtual sal_Int16 SAL_CALL
247     	getAccessibleRole (void)
248         throw (::com::sun::star::uno::RuntimeException);
249 
250     ///	Return this object's description.
251 	virtual ::rtl::OUString SAL_CALL
252     	getAccessibleDescription (void)
253         throw (::com::sun::star::uno::RuntimeException);
254 
255     ///	Return the object's current name.
256 	virtual ::rtl::OUString SAL_CALL
257     	getAccessibleName (void)
258         throw (::com::sun::star::uno::RuntimeException);
259 
260 	///	Return NULL to indicate that an empty relation set.
261 	virtual ::com::sun::star::uno::Reference<
262             ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL
263     	getAccessibleRelationSet (void)
264         throw (::com::sun::star::uno::RuntimeException);
265 
266     ///	Return the set of current states.
267 	virtual ::com::sun::star::uno::Reference<
268             ::com::sun::star::accessibility::XAccessibleStateSet> SAL_CALL
269     	getAccessibleStateSet (void)
270         throw (::com::sun::star::uno::RuntimeException);
271 
272 	/**	Return the parents locale or throw exception if this object has no
273     	parent yet/anymore.
274     */
275 	virtual ::com::sun::star::lang::Locale SAL_CALL
276     	getLocale (void)
277 		throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException);
278 
279 	//=====  XAccessibleEventBroadcaster  =====================================
280 
281     virtual void SAL_CALL addEventListener(
282 			const ::com::sun::star::uno::Reference<
283 				::com::sun::star::accessibility::XAccessibleEventListener >& xListener )
284 		throw (::com::sun::star::uno::RuntimeException);
285     virtual void SAL_CALL removeEventListener(
286 			const ::com::sun::star::uno::Reference<
287 				::com::sun::star::accessibility::XAccessibleEventListener >& xListener )
288 		throw (::com::sun::star::uno::RuntimeException);
289 
290 	//=====  XAccessibleComponent  ============================================
291     virtual sal_Bool SAL_CALL containsPoint(
292 			const ::com::sun::star::awt::Point& aPoint )
293 		throw (::com::sun::star::uno::RuntimeException);
294 
295     virtual ::com::sun::star::uno::Reference<
296 		::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(
297 				const ::com::sun::star::awt::Point& aPoint )
298 		throw (::com::sun::star::uno::RuntimeException);
299 
300     virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds()
301 		throw (::com::sun::star::uno::RuntimeException);
302 
303     virtual ::com::sun::star::awt::Point SAL_CALL getLocation()
304 		throw (::com::sun::star::uno::RuntimeException);
305 
306     virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen()
307 		throw (::com::sun::star::uno::RuntimeException);
308 
309     virtual ::com::sun::star::awt::Size SAL_CALL getSize()
310 		throw (::com::sun::star::uno::RuntimeException);
311 
312     virtual void SAL_CALL grabFocus()
313 		throw (::com::sun::star::uno::RuntimeException);
314 
315     virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding()
316 		throw (::com::sun::star::uno::RuntimeException);
317     virtual sal_Int32 SAL_CALL getForeground()
318 		throw (::com::sun::star::uno::RuntimeException);
319     virtual sal_Int32 SAL_CALL getBackground()
320 		throw (::com::sun::star::uno::RuntimeException);
321 
322 
323 	//=====  XServiceInfo  ====================================================
324 
325     /**	Returns an identifier for the implementation of this object.
326     */
327 	virtual ::rtl::OUString SAL_CALL
328     	getImplementationName (void)
329         throw (::com::sun::star::uno::RuntimeException);
330 
331     /**	Return whether the specified service is supported by this class.
332     */
333     virtual sal_Bool SAL_CALL
334     	supportsService (const ::rtl::OUString& sServiceName)
335         throw (::com::sun::star::uno::RuntimeException);
336 
337     /** Returns a list of all supported services.  In this case that is just
338     	the AccessibleContext service.
339     */
340 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
341     	getSupportedServiceNames (void)
342              throw (::com::sun::star::uno::RuntimeException);
343 
344 	//====== thread safe C++ interface ========================================
345 
346 	// The object is not visible an longer and should be destroyed
347 	virtual void Dispose( sal_Bool bRecursive = sal_False );
348 
349 	// The child object is not visible an longer and should be destroyed
350     virtual void DisposeChild( const sw::access::SwAccessibleChild& rFrmOrObj, sal_Bool bRecursive );
351 
352 	// The object has been moved by the layout
353 	virtual void InvalidatePosOrSize( const SwRect& rFrm );
354 
355 	// The vhild object has been moved by the layout
356     virtual void InvalidateChildPosOrSize( const sw::access::SwAccessibleChild& rFrmOrObj,
357 										   const SwRect& rFrm );
358 
359 	// The content may have changed (but it hasn't tohave changed)
360 	void InvalidateContent();
361 
362 	// The caretPos has changed
363 	void InvalidateCursorPos();
364 
365 	// The Focus state has changed
366 	void InvalidateFocus();
367 
368 	// Check states
369     // --> OD 2005-12-12 #i27301# - use new type definition for <_nStates>
370     void InvalidateStates( tAccessibleStates _nStates );
371     // <--
372 
373     // the XAccessibleRelationSet may have changed
374     void InvalidateRelation( sal_uInt16 nType );
375 
376     /** text selection has changed
377 
378         OD 2005-12-14 #i27301#
379 
380         @author OD
381     */
382     void InvalidateTextSelection();
383 
384     /** attributes has changed
385 
386         OD 2009-01-06 #i88069#
387 
388         @author OD
389     */
390     void InvalidateAttr();
391 
392     bool HasAdditionalAccessibleChildren();
393 
394     /** get additional child by index
395 
396         OD 2010-01-27 #i88070#
397 
398         @author OD
399     */
400     Window* GetAdditionalAccessibleChild( const sal_Int32 nIndex );
401 
402     /** get all additional accessible children
403 
404         OD 2010-01-27 #i88070#
405 
406         @author OD
407     */
408     void GetAdditionalAccessibleChildren( std::vector< Window* >* pChildren );
409 
410 
GetName() const411 	const ::rtl::OUString& GetName() const { return sName; }
412 
413 	virtual sal_Bool HasCursor();	// required by map to remember that object
414 
415 	sal_Bool Select( SwPaM *pPaM, SdrObject *pObj, sal_Bool bAdd );
Select(SwPaM & rPaM)416     inline sal_Bool Select( SwPaM& rPaM )
417     {
418         return Select( &rPaM, 0, sal_False );
419     }
Select(SdrObject * pObj,sal_Bool bAdd)420     inline sal_Bool Select( SdrObject *pObj, sal_Bool bAdd )
421     {
422         return Select( 0, pObj, bAdd );
423     }
424 	//This method is used to updated the selected state and fire the selected state changed event.
425 	virtual sal_Bool SetSelectedState(sal_Bool bSeleted);
IsSeletedInDoc()426 	sal_Bool  IsSeletedInDoc(){  return bIsSeletedInDoc; }
427 
428     static ::rtl::OUString GetResource( sal_uInt16 nResId,
429                                         const ::rtl::OUString *pArg1 = 0,
430                                         const ::rtl::OUString *pArg2 = 0 );
431 };
432 
433 // some heaviliy used exception support
434 const sal_Char sDefunc[] = "object is defunctional";
435 const sal_Char sMissingWindow[] = "window is missing";
436 
437 #define THROW_RUNTIME_EXCEPTION( ifc, msg ) 								\
438 	::com::sun::star::uno::Reference < ifc > xThis( this );					\
439 	::com::sun::star::uno::RuntimeException aExcept(                        \
440         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(msg) ), xThis );		\
441 	throw aExcept;
442 
443 #define CHECK_FOR_DEFUNC_THIS( ifc, ths )									\
444 	if( !(GetFrm() && GetMap()) )											\
445 	{																		\
446 		::com::sun::star::uno::Reference < ifc > xThis( ths );				\
447 		::com::sun::star::lang::DisposedException aExcept( 					\
448 		    ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(sDefunc) ),        \
449             xThis );												        \
450 		throw aExcept;														\
451 	}
452 
453 #define CHECK_FOR_DEFUNC( ifc )												\
454 	CHECK_FOR_DEFUNC_THIS( ifc, this )
455 
456 #define CHECK_FOR_WINDOW( i, w ) 											\
457 	if( !(w) )																\
458 	{																		\
459 		THROW_RUNTIME_EXCEPTION( i, sMissingWindow );						\
460 	}
461 #endif
462 
463