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 : namespace vcl { 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 : bool bIsShowingState : 1;
80 : bool bIsEditableState : 1;
81 : bool bIsOpaqueState : 1;
82 : bool bIsDefuncState : 1;
83 :
84 : // Are we currently disposing that object (protected by solar mutex)?
85 : 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 first time that document load
93 : bool bBeginDocumentLoad;
94 :
95 : protected:
96 208 : void SetName( const OUString& rName ) { sName = rName; }
97 16 : inline sal_Int16 GetRole() const
98 : {
99 16 : return nRole;
100 : }
101 : //Add a member to identify if the document is Asyn load.
102 : bool isIfAsynLoad;
103 : //This flag is used to mark the object's selected state.
104 : bool bIsSeletedInDoc;
105 : void SetParent( SwAccessibleContext *pParent );
106 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> GetWeakParent() const;
107 :
108 68 : bool IsDisposing() const { return bDisposing; }
109 :
110 : vcl::Window *GetWindow();
111 20982 : SwAccessibleMap *GetMap() { return pMap; }
112 28 : const SwAccessibleMap *GetMap() const { return pMap; }
113 :
114 : /** convenience method to get the SwViewShell through accessibility map */
115 540 : inline SwViewShell* GetShell()
116 : {
117 540 : 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 area 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 : 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( 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, 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 : bool IsEditableState();
185 :
186 : virtual ::com::sun::star::awt::Rectangle SAL_CALL
187 : getBoundsImpl(bool bRelative)
188 : throw (css::uno::RuntimeException, std::exception);
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( bool bRecursive = false );
329 :
330 : // The child object is not visible an longer and should be destroyed
331 : virtual void DisposeChild( const sw::access::SwAccessibleChild& rFrmOrObj, 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 : vcl::Window* GetAdditionalAccessibleChild( const sal_Int32 nIndex );
363 :
364 : // #i88070# - get all additional accessible children
365 : void GetAdditionalAccessibleChildren( std::vector< vcl::Window* >* pChildren );
366 :
367 16 : const OUString& GetName() const { return sName; }
368 :
369 : virtual bool HasCursor(); // required by map to remember that object
370 :
371 : bool Select( SwPaM *pPaM, SdrObject *pObj, bool bAdd );
372 12 : inline bool Select( SwPaM& rPaM )
373 : {
374 12 : return Select( &rPaM, 0, false );
375 : }
376 0 : inline bool Select( SdrObject *pObj, 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 bool SetSelectedState(bool bSeleted);
383 0 : 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 heavily used exception support
391 : #define THROW_RUNTIME_EXCEPTION( ifc, msg ) \
392 : ::com::sun::star::uno::Reference < ifc > xThis( this ); \
393 : ::com::sun::star::uno::RuntimeException aExcept( \
394 : OUString( msg ), xThis ); \
395 : throw aExcept;
396 :
397 : #define CHECK_FOR_DEFUNC_THIS( ifc, ths ) \
398 : if( !(GetFrm() && GetMap()) ) \
399 : { \
400 : ::com::sun::star::uno::Reference < ifc > xThis( ths ); \
401 : ::com::sun::star::lang::DisposedException aExcept( \
402 : OUString( "object is defunctional" ), \
403 : xThis ); \
404 : throw aExcept; \
405 : }
406 :
407 : #define CHECK_FOR_DEFUNC( ifc ) \
408 : CHECK_FOR_DEFUNC_THIS( ifc, this )
409 :
410 : #define CHECK_FOR_WINDOW( i, w ) \
411 : if( !(w) ) \
412 : { \
413 : THROW_RUNTIME_EXCEPTION( i, "window is missing" ); \
414 : }
415 : #endif
416 :
417 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|