1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: acccontext.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <accframe.hxx>
34 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
35 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
36 #include <com/sun/star/lang/DisposedException.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <cppuhelper/implbase5.hxx>
39 #include <cppuhelper/interfacecontainer.hxx>
42 class SwAccessibleMap
;
46 namespace utl
{ class AccessibleStateSetHelper
; }
47 namespace accessibility
{ class AccessibleShape
; }
49 const sal_Char sAccessibleServiceName
[] = "com.sun.star.accessibility.Accessible";
51 class SwAccessibleContext
:
52 public ::cppu::WeakImplHelper5
<
53 ::com::sun::star::accessibility::XAccessible
,
54 ::com::sun::star::accessibility::XAccessibleContext
,
55 ::com::sun::star::accessibility::XAccessibleComponent
,
56 ::com::sun::star::accessibility::XAccessibleEventBroadcaster
,
57 ::com::sun::star::lang::XServiceInfo
59 public SwAccessibleFrame
61 // The implements for the XAccessibleSelection interface has been
62 // 'externalized' and wants access to the protected members like
63 // GetMap, GetChild, GetParent, and GetFrm.
64 friend class SwAccessibleSelectionHelper
;
69 mutable ::osl::Mutex aListenerMutex
;
70 mutable ::vos::OMutex aMutex
;
74 ::rtl::OUString sName
; // immutable outside constructor
76 // The parent if it has been retrieved. This is always an
77 // SwAccessibleContext. (protected by Mutex)
78 ::com::sun::star::uno::WeakReference
<
79 ::com::sun::star::accessibility::XAccessible
> xWeakParent
;
81 SwAccessibleMap
*pMap
; // must be protected by solar mutex
83 sal_uInt32 nClientId
; // client id in the AccessibleEventNotifier queue
84 sal_Int16 nRole
; // immutable outside constructor
86 // The current states (protected by mutex)
87 sal_Bool bIsShowingState
: 1;
88 sal_Bool bIsEditableState
: 1;
89 sal_Bool bIsOpaqueState
: 1;
90 sal_Bool bIsDefuncState
: 1;
92 // Are we currently disposing that object (protected by solar mutex)?
93 sal_Bool bDisposing
: 1;
95 // --> OD 2008-03-10 #i85634#
96 // boolean, indicating if the accessible context is in general registered at
97 // the accessible map.
98 bool bRegisteredAtAccessibleMap
;
104 void SetName( const ::rtl::OUString
& rName
) { sName
= rName
; }
105 inline sal_Int16
GetRole() const
110 void SetParent( SwAccessibleContext
*pParent
);
111 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> GetWeakParent() const;
113 sal_Bool
IsDisposing() const { return bDisposing
; }
116 SwAccessibleMap
*GetMap() { return pMap
; }
117 const SwAccessibleMap
*GetMap() const { return pMap
; }
119 /** convenience method to get the SwViewShell through accessibility map */
120 inline ViewShell
* GetShell()
122 return GetMap()->GetShell();
124 inline const ViewShell
* GetShell() const
126 return GetMap()->GetShell();
129 /** convenience method to get SwCrsrShell through accessibility map
130 * @returns SwCrsrShell, or NULL if none is found */
131 SwCrsrShell
* GetCrsrShell();
132 const SwCrsrShell
* GetCrsrShell() const;
134 // Notify all children that the vis araea has changed.
135 // The SwFrm might belong to the current object or to any other child or
137 void ChildrenScrolled( const SwFrm
*pFrm
, const SwRect
& rOldVisArea
);
139 // The context's showing state changed. May only be called for context that
140 // exist even if they aren't visible.
141 void Scrolled( const SwRect
& rOldVisArea
);
143 // A child has been moved while setting the vis area
144 void ScrolledWithin( const SwRect
& rOldVisArea
);
146 // The has been added while setting the vis area
149 // The context has to be removed while setting the vis area
150 void ScrolledOut( const SwRect
& rOldVisArea
);
152 // Invalidate the states of all children of the specified SwFrm. The
153 // SwFrm might belong the the current object or to any child or grandchild!
154 // --> OD 2005-12-12 #i27301# - use new type definition for <_nStates>
155 void InvalidateChildrenStates( const SwFrm
* _pFrm
,
156 tAccessibleStates _nStates
);
159 // Dispose children of the specified SwFrm. The SwFrm might belong to
160 // the current object or to any other child or grandchild.
161 void DisposeChildren( const SwFrm
*pFrm
,
162 sal_Bool bRecursive
);
164 void DisposeShape( const SdrObject
*pObj
,
165 ::accessibility::AccessibleShape
*pAccImpl
);
166 void ScrolledInShape( const SdrObject
*pObj
,
167 ::accessibility::AccessibleShape
*pAccImpl
);
169 virtual void _InvalidateContent( sal_Bool bVisibleDataFired
);
171 virtual void _InvalidateCursorPos();
172 virtual void _InvalidateFocus();
176 void FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventObject
& rEvent
);
180 // broadcast visual data event
181 void FireVisibleDataEvent();
183 // broadcast state change event
184 void FireStateChangedEvent( sal_Int16 nState
, sal_Bool bNewState
);
186 // Set states for getAccessibleStateSet.
187 // This base class sets DEFUNC(0/1), EDITABLE(0/1), ENABLED(1),
188 // SHOWING(0/1), OPAQUE(0/1) and VISIBLE(1).
189 virtual void GetStates( ::utl::AccessibleStateSetHelper
& rStateSet
);
191 sal_Bool
IsEditableState();
193 virtual ::com::sun::star::awt::Rectangle SAL_CALL
194 getBoundsImpl(sal_Bool bRelative
)
195 throw (::com::sun::star::uno::RuntimeException
);
197 // --> OD 2008-03-10 #i85634#
198 inline void NotRegisteredAtAccessibleMap()
200 bRegisteredAtAccessibleMap
= false;
202 void RemoveFrmFromAccessibleMap();
205 virtual ~SwAccessibleContext();
209 SwAccessibleContext( SwAccessibleMap
*pMap
, sal_Int16 nRole
,
212 //===== XAccessible =====================================================
214 /// Return the XAccessibleContext.
215 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
> SAL_CALL
216 getAccessibleContext (void) throw (com::sun::star::uno::RuntimeException
);
218 //===== XAccessibleContext ==============================================
220 /// Return the number of currently visible children.
221 virtual sal_Int32 SAL_CALL
getAccessibleChildCount (void)
222 throw (::com::sun::star::uno::RuntimeException
);
224 /// Return the specified child or NULL if index is invalid.
225 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
226 getAccessibleChild (sal_Int32 nIndex
)
227 throw (::com::sun::star::uno::RuntimeException
,
228 ::com::sun::star::lang::IndexOutOfBoundsException
);
230 /// Return a reference to the parent.
231 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
232 getAccessibleParent (void)
233 throw (::com::sun::star::uno::RuntimeException
);
235 /// Return this objects index among the parents children.
236 virtual sal_Int32 SAL_CALL
237 getAccessibleIndexInParent (void)
238 throw (::com::sun::star::uno::RuntimeException
);
240 /// Return this object's role.
241 virtual sal_Int16 SAL_CALL
242 getAccessibleRole (void)
243 throw (::com::sun::star::uno::RuntimeException
);
245 /// Return this object's description.
246 virtual ::rtl::OUString SAL_CALL
247 getAccessibleDescription (void)
248 throw (::com::sun::star::uno::RuntimeException
);
250 /// Return the object's current name.
251 virtual ::rtl::OUString SAL_CALL
252 getAccessibleName (void)
253 throw (::com::sun::star::uno::RuntimeException
);
255 /// Return NULL to indicate that an empty relation set.
256 virtual ::com::sun::star::uno::Reference
<
257 ::com::sun::star::accessibility::XAccessibleRelationSet
> SAL_CALL
258 getAccessibleRelationSet (void)
259 throw (::com::sun::star::uno::RuntimeException
);
261 /// Return the set of current states.
262 virtual ::com::sun::star::uno::Reference
<
263 ::com::sun::star::accessibility::XAccessibleStateSet
> SAL_CALL
264 getAccessibleStateSet (void)
265 throw (::com::sun::star::uno::RuntimeException
);
267 /** Return the parents locale or throw exception if this object has no
270 virtual ::com::sun::star::lang::Locale SAL_CALL
272 throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException
, ::com::sun::star::uno::RuntimeException
);
274 //===== XAccessibleEventBroadcaster =====================================
276 virtual void SAL_CALL
addEventListener(
277 const ::com::sun::star::uno::Reference
<
278 ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
)
279 throw (::com::sun::star::uno::RuntimeException
);
280 virtual void SAL_CALL
removeEventListener(
281 const ::com::sun::star::uno::Reference
<
282 ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
)
283 throw (::com::sun::star::uno::RuntimeException
);
285 //===== XAccessibleComponent ============================================
286 virtual sal_Bool SAL_CALL
containsPoint(
287 const ::com::sun::star::awt::Point
& aPoint
)
288 throw (::com::sun::star::uno::RuntimeException
);
290 virtual ::com::sun::star::uno::Reference
<
291 ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getAccessibleAtPoint(
292 const ::com::sun::star::awt::Point
& aPoint
)
293 throw (::com::sun::star::uno::RuntimeException
);
295 virtual ::com::sun::star::awt::Rectangle SAL_CALL
getBounds()
296 throw (::com::sun::star::uno::RuntimeException
);
298 virtual ::com::sun::star::awt::Point SAL_CALL
getLocation()
299 throw (::com::sun::star::uno::RuntimeException
);
301 virtual ::com::sun::star::awt::Point SAL_CALL
getLocationOnScreen()
302 throw (::com::sun::star::uno::RuntimeException
);
304 virtual ::com::sun::star::awt::Size SAL_CALL
getSize()
305 throw (::com::sun::star::uno::RuntimeException
);
307 virtual void SAL_CALL
grabFocus()
308 throw (::com::sun::star::uno::RuntimeException
);
310 virtual ::com::sun::star::uno::Any SAL_CALL
getAccessibleKeyBinding()
311 throw (::com::sun::star::uno::RuntimeException
);
312 virtual sal_Int32 SAL_CALL
getForeground()
313 throw (::com::sun::star::uno::RuntimeException
);
314 virtual sal_Int32 SAL_CALL
getBackground()
315 throw (::com::sun::star::uno::RuntimeException
);
318 //===== XServiceInfo ====================================================
320 /** Returns an identifier for the implementation of this object.
322 virtual ::rtl::OUString SAL_CALL
323 getImplementationName (void)
324 throw (::com::sun::star::uno::RuntimeException
);
326 /** Return whether the specified service is supported by this class.
328 virtual sal_Bool SAL_CALL
329 supportsService (const ::rtl::OUString
& sServiceName
)
330 throw (::com::sun::star::uno::RuntimeException
);
332 /** Returns a list of all supported services. In this case that is just
333 the AccessibleContext service.
335 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
336 getSupportedServiceNames (void)
337 throw (::com::sun::star::uno::RuntimeException
);
339 //====== thread safe C++ interface ========================================
341 // The object is not visible an longer and should be destroyed
342 virtual void Dispose( sal_Bool bRecursive
= sal_False
);
344 // The child object is not visible an longer and should be destroyed
345 virtual void DisposeChild( const SwFrmOrObj
& rFrmOrObj
, sal_Bool bRecursive
);
347 // The object has been moved by the layout
348 virtual void InvalidatePosOrSize( const SwRect
& rFrm
);
350 // The vhild object has been moved by the layout
351 virtual void InvalidateChildPosOrSize( const SwFrmOrObj
& rFrmOrObj
,
352 const SwRect
& rFrm
);
354 // The content may have changed (but it hasn't tohave changed)
355 void InvalidateContent();
357 // The caretPos has changed
358 void InvalidateCursorPos();
360 // The Focus state has changed
361 void InvalidateFocus();
364 // --> OD 2005-12-12 #i27301# - use new type definition for <_nStates>
365 void InvalidateStates( tAccessibleStates _nStates
);
368 // the XAccessibleRelationSet may have changed
369 void InvalidateRelation( sal_uInt16 nType
);
371 /** text selection has changed
373 OD 2005-12-14 #i27301#
377 void InvalidateTextSelection();
379 /** attributes has changed
381 OD 2009-01-06 #i88069#
385 void InvalidateAttr();
387 const ::rtl::OUString
& GetName() const { return sName
; }
389 virtual sal_Bool
HasCursor(); // required by map to remember that object
391 sal_Bool
Select( SwPaM
*pPaM
, SdrObject
*pObj
, sal_Bool bAdd
);
392 inline sal_Bool
Select( SwPaM
& rPaM
)
394 return Select( &rPaM
, 0, sal_False
);
396 inline sal_Bool
Select( SdrObject
*pObj
, sal_Bool bAdd
)
398 return Select( 0, pObj
, bAdd
);
401 static ::rtl::OUString
GetResource( sal_uInt16 nResId
,
402 const ::rtl::OUString
*pArg1
= 0,
403 const ::rtl::OUString
*pArg2
= 0 );
408 // some heaviliy used exception support
409 const sal_Char sDefunc
[] = "object is defunctional";
410 const sal_Char sMissingWindow
[] = "window is missing";
412 #define THROW_RUNTIME_EXCEPTION( ifc, msg ) \
413 ::com::sun::star::uno::Reference < ifc > xThis( this ); \
414 ::com::sun::star::uno::RuntimeException aExcept( \
415 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(msg) ), xThis ); \
418 #define CHECK_FOR_DEFUNC_THIS( ifc, ths ) \
419 if( !(GetFrm() && GetMap()) ) \
421 ::com::sun::star::uno::Reference < ifc > xThis( ths ); \
422 ::com::sun::star::lang::DisposedException aExcept( \
423 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(sDefunc) ), \
428 #define CHECK_FOR_DEFUNC( ifc ) \
429 CHECK_FOR_DEFUNC_THIS( ifc, this )
431 #define CHECK_FOR_WINDOW( i, w ) \
434 THROW_RUNTIME_EXCEPTION( i, sMissingWindow ); \