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