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