Branch data 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 : : #ifndef _CHART2_ACCESSIBLEBASE_HXX_
20 : : #define _CHART2_ACCESSIBLEBASE_HXX_
21 : :
22 : : #include "ObjectIdentifier.hxx"
23 : :
24 : : #include <com/sun/star/chart2/XChartDocument.hpp>
25 : : #include <com/sun/star/accessibility/XAccessible.hpp>
26 : : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
27 : : #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
28 : : #include <com/sun/star/lang/XServiceInfo.hpp>
29 : : #include <com/sun/star/document/XEventListener.hpp>
30 : : #include <com/sun/star/lang/XEventListener.hpp>
31 : : #include <com/sun/star/lang/DisposedException.hpp>
32 : : #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
33 : : #include <com/sun/star/view/XSelectionSupplier.hpp>
34 : : #include <comphelper/accessibleeventnotifier.hxx>
35 : : #include <cppuhelper/compbase6.hxx>
36 : : #include <cppuhelper/interfacecontainer.hxx>
37 : : #include <unotools/accessiblestatesethelper.hxx>
38 : :
39 : : #include <vector>
40 : : #include <map>
41 : : #include <boost/shared_ptr.hpp>
42 : :
43 : : #include "MutexContainer.hxx"
44 : :
45 : : class SdrView;
46 : :
47 : : namespace accessibility
48 : : {
49 : : class IAccessibleViewForwarder;
50 : : }
51 : :
52 : : namespace chart
53 : : {
54 : :
55 : : class AccessibleBase;
56 : : class ObjectHierarchy;
57 : :
58 : : typedef ObjectIdentifier AccessibleUniqueId;
59 : :
60 [ # # ][ # # ]: 0 : struct AccessibleElementInfo
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
61 : : {
62 : : AccessibleUniqueId m_aOID;
63 : :
64 : : ::com::sun::star::uno::WeakReference<
65 : : ::com::sun::star::chart2::XChartDocument > m_xChartDocument;
66 : : ::com::sun::star::uno::WeakReference<
67 : : ::com::sun::star::view::XSelectionSupplier > m_xSelectionSupplier;
68 : : ::com::sun::star::uno::WeakReference<
69 : : ::com::sun::star::uno::XInterface > m_xView;
70 : : ::com::sun::star::uno::WeakReference<
71 : : ::com::sun::star::awt::XWindow > m_xWindow;
72 : :
73 : : ::boost::shared_ptr< ObjectHierarchy > m_spObjectHierarchy;
74 : :
75 : : AccessibleBase * m_pParent;
76 : : SdrView* m_pSdrView;
77 : : ::accessibility::IAccessibleViewForwarder* m_pViewForwarder;
78 : : };
79 : :
80 : :
81 : : namespace impl
82 : : {
83 : : typedef ::cppu::PartialWeakComponentImplHelper6<
84 : : ::com::sun::star::accessibility::XAccessible,
85 : : ::com::sun::star::accessibility::XAccessibleContext,
86 : : ::com::sun::star::accessibility::XAccessibleComponent,
87 : : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
88 : : ::com::sun::star::lang::XServiceInfo,
89 : : ::com::sun::star::lang::XEventListener
90 : : > AccessibleBase_Base;
91 : : }
92 : :
93 : : /** Base class for all Chart Accessibility objects
94 : : */
95 : : class AccessibleBase :
96 : : public MutexContainer,
97 : : public impl::AccessibleBase_Base
98 : : {
99 : : public:
100 : : enum EventType
101 : : {
102 : : OBJECT_CHANGE,
103 : : GOT_SELECTION,
104 : : LOST_SELECTION,
105 : : PROPERTY_CHANGE
106 : : };
107 : :
108 : : AccessibleBase( const AccessibleElementInfo & rAccInfo,
109 : : bool bMayHaveChildren,
110 : : bool bAlwaysTransparent = false );
111 : : virtual ~AccessibleBase();
112 : :
113 : : protected:
114 : : // for all calls to protected methods it is assumed that the mutex is locked
115 : : // unless calls outside via UNO, e.g. event notification, are done
116 : :
117 : : /** @param bThrowException if true, a DisposedException is thrown if the
118 : : object is already disposed
119 : : @return true, if the component is already disposed and bThrowException is false,
120 : : false otherwise
121 : : */
122 : : bool CheckDisposeState( bool bThrowException = true ) const throw (::com::sun::star::lang::DisposedException);
123 : :
124 : : /** Events coming from the core have to be processed in this methods. The
125 : : default implementation returns false, which indicates that the object is
126 : : not interested in the event. To react on events you have to implement
127 : : this method in derived classes.
128 : :
129 : : The default implementation iterates over all children and forwards the
130 : : event until the first child returns true.
131 : :
132 : : @param nObjId contains the object id of chart objects. If the object is
133 : : no chart object, the event is not broadcast.
134 : : @return If an object is the addressee of the event it should return
135 : : true, false otherwise.
136 : : */
137 : : virtual bool NotifyEvent( EventType eType, const AccessibleUniqueId & rId );
138 : :
139 : : /** Adds a state to the set.
140 : : */
141 : : void AddState( sal_Int16 aState ) throw (::com::sun::star::uno::RuntimeException);
142 : :
143 : : /** Removes a state from the set if the set contains the state, otherwise
144 : : nothing is done.
145 : : */
146 : : void RemoveState( sal_Int16 aState ) throw (::com::sun::star::uno::RuntimeException);
147 : :
148 : : /** has to be overloaded by derived classes that support child elements.
149 : : With this method a rescan is initiated that should result in a correct
150 : : list of children.
151 : :
152 : : This method is called when access to any methods concerning children is
153 : : invoked for the first time.
154 : : */
155 : : bool UpdateChildren();
156 : :
157 : : /** Is called by UpdateChildren. This method is only called if an update is
158 : : really necessary.
159 : : */
160 : : virtual bool ImplUpdateChildren();
161 : :
162 : : /** adds a child to the end of the internal vector of children. As a
163 : : result, the child-count increases by one, but all existing children keep
164 : : their indices.
165 : :
166 : : Important: as the implementation is needed, this should remain the only
167 : : method for adding children (i.e. there mustn't be an AddChild( Reference<
168 : : XAccessible > ) or the like).
169 : : */
170 : : void AddChild( AccessibleBase* pChild );
171 : :
172 : : /** removes a child from the internal vector. All children with index
173 : : greater than the index of the removed element get an index one less than
174 : : before.
175 : : */
176 : : void RemoveChildByOId( const ObjectIdentifier& rOId );
177 : :
178 : : /** Retrieve the pixel coordinates of logical coordinates (0,0) of the
179 : : current logic coordinate system. This can be used for
180 : : getLocationOnScreen, if the coordinates of an object are not relative to
181 : : its direct parent, but a parent higher up in hierarchy.
182 : :
183 : : @return the (x,y) pixel coordinates of the upper left corner
184 : : */
185 : : virtual ::com::sun::star::awt::Point GetUpperLeftOnScreen() const;
186 : :
187 : : /** This method creates an AccessibleEventObject and sends it to all
188 : : listeners that are currently listening to this object
189 : :
190 : : If bSendGlobally is true, the event is also broadcast via
191 : : vcl::unohelper::NotifyAccessibleStateEventGlobally()
192 : : */
193 : : void BroadcastAccEvent( sal_Int16 nId,
194 : : const ::com::sun::star::uno::Any & rNew,
195 : : const ::com::sun::star::uno::Any & rOld,
196 : : bool bSendGlobally = false ) const;
197 : :
198 : : /** Removes all children from the internal lists and broadcasts child remove
199 : : events.
200 : :
201 : : This method cares about mutex locking, and thus should be called without
202 : : the mutex locked.
203 : : */
204 : : virtual void KillAllChildren();
205 : :
206 : : /** Is called from getAccessibleChild(). Before this method is called, an
207 : : update of children is done if necessary.
208 : : */
209 : : virtual ::com::sun::star::uno::Reference<
210 : : ::com::sun::star::accessibility::XAccessible >
211 : : ImplGetAccessibleChildById( sal_Int32 i ) const
212 : : throw (::com::sun::star::lang::IndexOutOfBoundsException,
213 : : ::com::sun::star::uno::RuntimeException);
214 : :
215 : : /** Is called from getAccessibleChildCount(). Before this method is called,
216 : : an update of children is done if necessary.
217 : : */
218 : : virtual sal_Int32 ImplGetAccessibleChildCount() const
219 : : throw (::com::sun::star::uno::RuntimeException);
220 : :
221 : : AccessibleElementInfo GetInfo() const;
222 : : void SetInfo( const AccessibleElementInfo & rNewInfo );
223 : : AccessibleUniqueId GetId() const;
224 : :
225 : : // ________ XComponent ________
226 : 0 : virtual void SAL_CALL dispose()throw (::com::sun::star::uno::RuntimeException)
227 : 0 : { WeakComponentImplHelperBase::dispose(); }
228 : 0 : virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException)
229 : 0 : { WeakComponentImplHelperBase::addEventListener(xListener); }
230 : 0 : virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException)
231 : 0 : { WeakComponentImplHelperBase::removeEventListener(xListener); }
232 : :
233 : :
234 : : // ________ WeakComponentImplHelper (XComponent::dispose) ________
235 : : virtual void SAL_CALL disposing();
236 : :
237 : : // ________ XAccessible ________
238 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext()
239 : : throw (::com::sun::star::uno::RuntimeException);
240 : :
241 : : // ________ XAccessibleContext ________
242 : : virtual sal_Int32 SAL_CALL getAccessibleChildCount()
243 : : throw (::com::sun::star::uno::RuntimeException);
244 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
245 : : getAccessibleChild( sal_Int32 i )
246 : : throw (::com::sun::star::lang::IndexOutOfBoundsException,
247 : : ::com::sun::star::uno::RuntimeException);
248 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
249 : : getAccessibleParent()
250 : : throw (::com::sun::star::uno::RuntimeException);
251 : : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent()
252 : : throw (::com::sun::star::uno::RuntimeException);
253 : : /// @return AccessibleRole.SHAPE
254 : : virtual sal_Int16 SAL_CALL getAccessibleRole()
255 : : throw (::com::sun::star::uno::RuntimeException);
256 : : // has to be implemented by derived classes
257 : : // virtual ::rtl::OUString SAL_CALL getAccessibleName()
258 : : // throw (::com::sun::star::uno::RuntimeException);
259 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL
260 : : getAccessibleRelationSet()
261 : : throw (::com::sun::star::uno::RuntimeException);
262 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL
263 : : getAccessibleStateSet()
264 : : throw (::com::sun::star::uno::RuntimeException);
265 : : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale()
266 : : throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException,
267 : : ::com::sun::star::uno::RuntimeException);
268 : : // has to be implemented by derived classes
269 : : // virtual ::rtl::OUString SAL_CALL getAccessibleDescription()
270 : : // throw (::com::sun::star::uno::RuntimeException);
271 : :
272 : : // ________ XAccessibleComponent ________
273 : : virtual sal_Bool SAL_CALL containsPoint(
274 : : const ::com::sun::star::awt::Point& aPoint )
275 : : throw (::com::sun::star::uno::RuntimeException);
276 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
277 : : getAccessibleAtPoint( const ::com::sun::star::awt::Point& aPoint )
278 : : throw (::com::sun::star::uno::RuntimeException);
279 : : // has to be defined in derived classes
280 : : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds()
281 : : throw (::com::sun::star::uno::RuntimeException);
282 : : virtual ::com::sun::star::awt::Point SAL_CALL getLocation()
283 : : throw (::com::sun::star::uno::RuntimeException);
284 : : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen()
285 : : throw (::com::sun::star::uno::RuntimeException);
286 : : virtual ::com::sun::star::awt::Size SAL_CALL getSize()
287 : : throw (::com::sun::star::uno::RuntimeException);
288 : : virtual void SAL_CALL grabFocus()
289 : : throw (::com::sun::star::uno::RuntimeException);
290 : : virtual sal_Int32 SAL_CALL getForeground()
291 : : throw (::com::sun::star::uno::RuntimeException);
292 : : virtual sal_Int32 SAL_CALL getBackground()
293 : : throw (::com::sun::star::uno::RuntimeException);
294 : :
295 : : // ________ XServiceInfo ________
296 : : virtual ::rtl::OUString SAL_CALL getImplementationName()
297 : : throw (::com::sun::star::uno::RuntimeException);
298 : : virtual sal_Bool SAL_CALL supportsService(
299 : : const ::rtl::OUString& ServiceName )
300 : : throw (::com::sun::star::uno::RuntimeException);
301 : : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
302 : : throw (::com::sun::star::uno::RuntimeException);
303 : :
304 : : // ________ XEventListener ________
305 : : virtual void SAL_CALL disposing(
306 : : const ::com::sun::star::lang::EventObject& Source )
307 : : throw (::com::sun::star::uno::RuntimeException);
308 : :
309 : : // ________ XAccessibleEventBroadcaster ________
310 : : virtual void SAL_CALL addEventListener(
311 : : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener )
312 : : throw (::com::sun::star::uno::RuntimeException);
313 : : virtual void SAL_CALL removeEventListener(
314 : : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener )
315 : : throw (::com::sun::star::uno::RuntimeException);
316 : :
317 : : private:
318 : : enum eColorType
319 : : {
320 : : ACC_BASE_FOREGROUND,
321 : : ACC_BASE_BACKGROUND
322 : : };
323 : : sal_Int32 getColor( eColorType eColType );
324 : :
325 : : private:
326 : : typedef ::com::sun::star::uno::Reference<
327 : : ::com::sun::star::accessibility::XAccessible > tAccessible;
328 : : /** type of the vector containing the accessible children
329 : : */
330 : : typedef ::std::vector< tAccessible > ChildListVectorType;
331 : : /** type of the hash containing a vector index for every AccessibleUniqueId
332 : : of the object in the child list
333 : : */
334 : : typedef ::std::map< ObjectIdentifier, tAccessible > ChildOIDMap;
335 : :
336 : : bool m_bIsDisposed;
337 : : const bool m_bMayHaveChildren;
338 : : bool m_bChildrenInitialized;
339 : : ChildListVectorType m_aChildList;
340 : :
341 : : ChildOIDMap m_aChildOIDMap;
342 : :
343 : : ::comphelper::AccessibleEventNotifier::TClientId m_nEventNotifierId;
344 : :
345 : : /** Implementation helper for getAccessibleStateSet()
346 : :
347 : : Note: This member must come before m_aStateSet!
348 : : */
349 : : ::utl::AccessibleStateSetHelper * m_pStateSetHelper;
350 : : /** this is returned in getAccessibleStateSet().
351 : :
352 : : The implementation is an ::utl::AccessibleStateSetHelper. To access
353 : : implementation methods use m_pStateSetHelper.
354 : :
355 : : Note: Keeping this reference ensures, that the helper object is only
356 : : destroyed after this object has been disposed().
357 : : */
358 : : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet >
359 : : m_aStateSet;
360 : :
361 : : AccessibleElementInfo m_aAccInfo;
362 : : const bool m_bAlwaysTransparent;
363 : : /** denotes if the state-set is initialized. On initialization the selected
364 : : state is checked.
365 : :
366 : : This variable is monitored by the solar mutex!
367 : :
368 : : Note: declared volatile to enable double-check-locking
369 : : */
370 : : volatile bool m_bStateSetInitialized;
371 : : };
372 : :
373 : : } // namespace chart
374 : :
375 : : #endif
376 : :
377 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|