merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / controller / inc / AccessibleBase.hxx
blobea52a29c614b75dc142de63408756e6cd2472f9e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 #ifndef _CHART2_ACCESSIBLEBASE_HXX_
28 #define _CHART2_ACCESSIBLEBASE_HXX_
30 #include "ObjectIdentifier.hxx"
32 #include <com/sun/star/chart2/XChartDocument.hpp>
33 #include <com/sun/star/accessibility/XAccessible.hpp>
34 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
35 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/document/XEventListener.hpp>
38 #include <com/sun/star/lang/XEventListener.hpp>
39 #include <com/sun/star/lang/DisposedException.hpp>
40 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
41 #include <com/sun/star/view/XSelectionSupplier.hpp>
42 #include <comphelper/accessibleeventnotifier.hxx>
43 #include <cppuhelper/compbase6.hxx>
44 #include <cppuhelper/interfacecontainer.hxx>
45 #include <unotools/accessiblestatesethelper.hxx>
47 #include <vector>
48 #include <map>
49 #include <boost/shared_ptr.hpp>
51 #include "MutexContainer.hxx"
53 class SfxItemSet;
54 class SdrObject;
55 class SdrView;
57 namespace accessibility
59 class IAccessibleViewForwarder;
62 namespace chart
65 class AccessibleBase;
66 class ObjectHierarchy;
68 typedef ObjectIdentifier AccessibleUniqueId;
70 struct AccessibleElementInfo
72 AccessibleUniqueId m_aOID;
74 ::com::sun::star::uno::WeakReference<
75 ::com::sun::star::chart2::XChartDocument > m_xChartDocument;
76 ::com::sun::star::uno::WeakReference<
77 ::com::sun::star::view::XSelectionSupplier > m_xSelectionSupplier;
78 ::com::sun::star::uno::WeakReference<
79 ::com::sun::star::uno::XInterface > m_xView;
80 ::com::sun::star::uno::WeakReference<
81 ::com::sun::star::awt::XWindow > m_xWindow;
83 ::boost::shared_ptr< ObjectHierarchy > m_spObjectHierarchy;
85 AccessibleBase * m_pParent;
86 SdrView* m_pSdrView;
87 ::accessibility::IAccessibleViewForwarder* m_pViewForwarder;
91 namespace impl
93 typedef ::cppu::WeakComponentImplHelper6<
94 ::com::sun::star::accessibility::XAccessible,
95 ::com::sun::star::accessibility::XAccessibleContext,
96 ::com::sun::star::accessibility::XAccessibleComponent,
97 ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
98 ::com::sun::star::lang::XServiceInfo,
99 ::com::sun::star::lang::XEventListener
100 > AccessibleBase_Base;
103 /** Base class for all Chart Accessibility objects
105 class AccessibleBase :
106 public MutexContainer,
107 public impl::AccessibleBase_Base
109 public:
110 enum EventType
112 OBJECT_CHANGE,
113 GOT_SELECTION,
114 LOST_SELECTION,
115 PROPERTY_CHANGE
118 AccessibleBase( const AccessibleElementInfo & rAccInfo,
119 bool bMayHaveChildren,
120 bool bAlwaysTransparent = false );
121 virtual ~AccessibleBase();
123 protected:
124 // for all calls to protected methods it is assumed that the mutex is locked
125 // unless calls outside via UNO, e.g. event notification, are done
127 /** @param bThrowException if true, a DisposedException is thrown if the
128 object is already disposed
129 @return true, if the component is already disposed and bThrowException is false,
130 false otherwise
132 bool CheckDisposeState( bool bThrowException = true ) const throw (::com::sun::star::lang::DisposedException);
134 /** Events coming from the core have to be processed in this methods. The
135 default implementation returns false, which indicates that the object is
136 not interested in the event. To react on events you have to implement
137 this method in derived classes.
139 The default implementation iterates over all children and forwards the
140 event until the first child returns true.
142 @param nObjId contains the object id of chart objects. If the object is
143 no chart object, the event is not broadcast.
144 @return If an object is the addressee of the event it should return
145 true, false otherwise.
147 virtual bool NotifyEvent( EventType eType, const AccessibleUniqueId & rId );
149 /** Adds a state to the set.
151 void AddState( sal_Int16 aState ) throw (::com::sun::star::uno::RuntimeException);
153 /** Removes a state from the set if the set contains the state, otherwise
154 nothing is done.
156 void RemoveState( sal_Int16 aState ) throw (::com::sun::star::uno::RuntimeException);
158 /** has to be overloaded by derived classes that support child elements.
159 With this method a rescan is initiated that should result in a correct
160 list of children.
162 This method is called when access to any methods concerning children is
163 invoked for the first time.
165 bool UpdateChildren();
167 /** Is called by UpdateChildren. This method is only called if an update is
168 really necessary.
170 virtual bool ImplUpdateChildren();
172 /** adds a child to the end of the internal vector of children. As a
173 result, the child-count increases by one, but all existing children keep
174 their indices.
176 Important: as the implementation is needed, this should remain the only
177 method for adding children (i.e. there mustn't be an AddChild( Reference<
178 XAccessible > ) or the like).
180 void AddChild( AccessibleBase* pChild );
182 /** removes a child from the internal vector. All children with index
183 greater than the index of the removed element get an index one less than
184 before.
186 void RemoveChildByOId( const ObjectIdentifier& rOId );
188 /** Retrieve the pixel coordinates of logical coordinates (0,0) of the
189 current logic coordinate system. This can be used for
190 getLocationOnScreen, if the coordinates of an object are not relative to
191 its direct parent, but a parent higher up in hierarchy.
193 @return the (x,y) pixel coordinates of the upper left corner
195 virtual ::com::sun::star::awt::Point GetUpperLeftOnScreen() const;
197 /** This method creates an AccessibleEventObject and sends it to all
198 listeners that are currently listening to this object
200 If bSendGlobally is true, the event is also broadcast via
201 vcl::unohelper::NotifyAccessibleStateEventGlobally()
203 void BroadcastAccEvent( sal_Int16 nId,
204 const ::com::sun::star::uno::Any & rNew,
205 const ::com::sun::star::uno::Any & rOld,
206 bool bSendGlobally = false ) const;
208 /** Removes all children from the internal lists and broadcasts child remove
209 events.
211 This method cares about mutex locking, and thus should be called without
212 the mutex locked.
214 virtual void KillAllChildren();
216 /** Is called from getAccessibleChild(). Before this method is called, an
217 update of children is done if necessary.
219 virtual ::com::sun::star::uno::Reference<
220 ::com::sun::star::accessibility::XAccessible >
221 ImplGetAccessibleChildById( sal_Int32 i ) const
222 throw (::com::sun::star::lang::IndexOutOfBoundsException,
223 ::com::sun::star::uno::RuntimeException);
225 /** Is called from getAccessibleChildCount(). Before this method is called,
226 an update of children is done if necessary.
228 virtual sal_Int32 ImplGetAccessibleChildCount() const
229 throw (::com::sun::star::uno::RuntimeException);
231 AccessibleElementInfo GetInfo() const;
232 void SetInfo( const AccessibleElementInfo & rNewInfo );
233 AccessibleUniqueId GetId() const;
235 // ________ WeakComponentImplHelper (XComponent::dispose) ________
236 virtual void SAL_CALL disposing();
238 // ________ XAccessible ________
239 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext()
240 throw (::com::sun::star::uno::RuntimeException);
242 // ________ XAccessibleContext ________
243 virtual sal_Int32 SAL_CALL getAccessibleChildCount()
244 throw (::com::sun::star::uno::RuntimeException);
245 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
246 getAccessibleChild( sal_Int32 i )
247 throw (::com::sun::star::lang::IndexOutOfBoundsException,
248 ::com::sun::star::uno::RuntimeException);
249 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
250 getAccessibleParent()
251 throw (::com::sun::star::uno::RuntimeException);
252 virtual sal_Int32 SAL_CALL getAccessibleIndexInParent()
253 throw (::com::sun::star::uno::RuntimeException);
254 /// @return AccessibleRole.SHAPE
255 virtual sal_Int16 SAL_CALL getAccessibleRole()
256 throw (::com::sun::star::uno::RuntimeException);
257 // has to be implemented by derived classes
258 // virtual ::rtl::OUString SAL_CALL getAccessibleName()
259 // throw (::com::sun::star::uno::RuntimeException);
260 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL
261 getAccessibleRelationSet()
262 throw (::com::sun::star::uno::RuntimeException);
263 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL
264 getAccessibleStateSet()
265 throw (::com::sun::star::uno::RuntimeException);
266 virtual ::com::sun::star::lang::Locale SAL_CALL getLocale()
267 throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException,
268 ::com::sun::star::uno::RuntimeException);
269 // has to be implemented by derived classes
270 // virtual ::rtl::OUString SAL_CALL getAccessibleDescription()
271 // throw (::com::sun::star::uno::RuntimeException);
273 // ________ XAccessibleComponent ________
274 virtual sal_Bool SAL_CALL containsPoint(
275 const ::com::sun::star::awt::Point& aPoint )
276 throw (::com::sun::star::uno::RuntimeException);
277 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
278 getAccessibleAtPoint( const ::com::sun::star::awt::Point& aPoint )
279 throw (::com::sun::star::uno::RuntimeException);
280 // has to be defined in derived classes
281 virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds()
282 throw (::com::sun::star::uno::RuntimeException);
283 virtual ::com::sun::star::awt::Point SAL_CALL getLocation()
284 throw (::com::sun::star::uno::RuntimeException);
285 virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen()
286 throw (::com::sun::star::uno::RuntimeException);
287 virtual ::com::sun::star::awt::Size SAL_CALL getSize()
288 throw (::com::sun::star::uno::RuntimeException);
289 virtual void SAL_CALL grabFocus()
290 throw (::com::sun::star::uno::RuntimeException);
291 virtual sal_Int32 SAL_CALL getForeground()
292 throw (::com::sun::star::uno::RuntimeException);
293 virtual sal_Int32 SAL_CALL getBackground()
294 throw (::com::sun::star::uno::RuntimeException);
296 // ________ XServiceInfo ________
297 virtual ::rtl::OUString SAL_CALL getImplementationName()
298 throw (::com::sun::star::uno::RuntimeException);
299 virtual sal_Bool SAL_CALL supportsService(
300 const ::rtl::OUString& ServiceName )
301 throw (::com::sun::star::uno::RuntimeException);
302 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
303 throw (::com::sun::star::uno::RuntimeException);
305 // ________ XEventListener ________
306 virtual void SAL_CALL disposing(
307 const ::com::sun::star::lang::EventObject& Source )
308 throw (::com::sun::star::uno::RuntimeException);
310 using ::cppu::WeakComponentImplHelperBase::addEventListener;
311 using ::cppu::WeakComponentImplHelperBase::removeEventListener;
313 // ________ XAccessibleEventBroadcaster ________
314 virtual void SAL_CALL addEventListener(
315 const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener )
316 throw (::com::sun::star::uno::RuntimeException);
317 virtual void SAL_CALL removeEventListener(
318 const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener )
319 throw (::com::sun::star::uno::RuntimeException);
321 private:
322 enum eColorType
324 ACC_BASE_FOREGROUND,
325 ACC_BASE_BACKGROUND
327 sal_Int32 getColor( eColorType eColType );
329 private:
330 typedef ::com::sun::star::uno::Reference<
331 ::com::sun::star::accessibility::XAccessible > tAccessible;
332 /** type of the vector containing the accessible children
334 typedef ::std::vector< tAccessible > ChildListVectorType;
335 /** type of the hash containing a vector index for every AccessibleUniqueId
336 of the object in the child list
338 typedef ::std::map< ObjectIdentifier, tAccessible > ChildOIDMap;
340 bool m_bIsDisposed;
341 const bool m_bMayHaveChildren;
342 bool m_bChildrenInitialized;
343 ChildListVectorType m_aChildList;
345 ChildOIDMap m_aChildOIDMap;
347 ::comphelper::AccessibleEventNotifier::TClientId m_nEventNotifierId;
349 /** Implementation helper for getAccessibleStateSet()
351 Note: This member must come before m_aStateSet!
353 ::utl::AccessibleStateSetHelper * m_pStateSetHelper;
354 /** this is returned in getAccessibleStateSet().
356 The implementation is an ::utl::AccessibleStateSetHelper. To access
357 implementation methods use m_pStateSetHelper.
359 Note: Keeping this reference ensures, that the helper object is only
360 destroyed after this object has been disposed().
362 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet >
363 m_aStateSet;
365 AccessibleElementInfo m_aAccInfo;
366 const bool m_bAlwaysTransparent;
367 /** denotes if the state-set is initialized. On initialization the selected
368 state is checked.
370 This variable is monitored by the solar mutex!
372 Note: declared volatile to enable double-check-locking
374 volatile bool m_bStateSetInitialized;
377 } // namespace chart
379 #endif