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