fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / inc / AccessibleBase.hxx
blobfc16dd1ff2035e80ab199023d30dc229d8c7f3fb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_INC_ACCESSIBLEBASE_HXX
20 #define INCLUDED_CHART2_SOURCE_CONTROLLER_INC_ACCESSIBLEBASE_HXX
22 #include "ObjectIdentifier.hxx"
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>
39 #include <vector>
40 #include <map>
41 #include <boost/shared_ptr.hpp>
43 #include "MutexContainer.hxx"
45 class SdrView;
47 namespace accessibility
49 class IAccessibleViewForwarder;
52 namespace chart
55 class AccessibleBase;
56 class ObjectHierarchy;
58 typedef ObjectIdentifier AccessibleUniqueId;
60 struct AccessibleElementInfo
62 AccessibleUniqueId m_aOID;
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;
73 ::boost::shared_ptr< ObjectHierarchy > m_spObjectHierarchy;
75 AccessibleBase * m_pParent;
76 SdrView* m_pSdrView;
77 ::accessibility::IAccessibleViewForwarder* m_pViewForwarder;
80 namespace impl
82 typedef ::cppu::WeakComponentImplHelper6<
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;
92 /** Base class for all Chart Accessibility objects
94 class AccessibleBase :
95 public MutexContainer,
96 public impl::AccessibleBase_Base
98 public:
99 enum EventType
101 OBJECT_CHANGE,
102 GOT_SELECTION,
103 LOST_SELECTION,
104 PROPERTY_CHANGE
107 AccessibleBase( const AccessibleElementInfo & rAccInfo,
108 bool bMayHaveChildren,
109 bool bAlwaysTransparent = false );
110 virtual ~AccessibleBase();
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
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
121 bool CheckDisposeState( bool bThrowException = true ) const throw (::com::sun::star::lang::DisposedException);
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.
128 The default implementation iterates over all children and forwards the
129 event until the first child returns true.
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.
136 bool NotifyEvent( EventType eType, const AccessibleUniqueId & rId );
138 /** Adds a state to the set.
140 void AddState( sal_Int16 aState ) throw (::com::sun::star::uno::RuntimeException);
142 /** Removes a state from the set if the set contains the state, otherwise
143 nothing is done.
145 void RemoveState( sal_Int16 aState ) throw (::com::sun::star::uno::RuntimeException);
147 /** has to be overridden 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.
151 This method is called when access to any methods concerning children is
152 invoked for the first time.
154 bool UpdateChildren();
156 /** Is called by UpdateChildren. This method is only called if an update is
157 really necessary.
159 virtual bool ImplUpdateChildren();
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.
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).
169 void AddChild( AccessibleBase* pChild );
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.
175 void RemoveChildByOId( const ObjectIdentifier& rOId );
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.
182 @return the (x,y) pixel coordinates of the upper left corner
184 virtual ::com::sun::star::awt::Point GetUpperLeftOnScreen() const;
186 /** This method creates an AccessibleEventObject and sends it to all
187 listeners that are currently listening to this object
189 If bSendGlobally is true, the event is also broadcast via
190 vcl::unohelper::NotifyAccessibleStateEventGlobally()
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;
197 /** Removes all children from the internal lists and broadcasts child remove
198 events.
200 This method cares about mutex locking, and thus should be called without
201 the mutex locked.
203 void KillAllChildren();
205 /** Is called from getAccessibleChild(). Before this method is called, an
206 update of children is done if necessary.
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);
214 /** Is called from getAccessibleChildCount(). Before this method is called,
215 an update of children is done if necessary.
217 virtual sal_Int32 ImplGetAccessibleChildCount() const
218 throw (::com::sun::star::uno::RuntimeException);
220 AccessibleElementInfo GetInfo() const { return m_aAccInfo;}
221 void SetInfo( const AccessibleElementInfo & rNewInfo );
222 AccessibleUniqueId GetId() const { return m_aAccInfo.m_aOID;}
224 // ________ WeakComponentImplHelper (XComponent::dispose) ________
225 virtual void SAL_CALL disposing() SAL_OVERRIDE;
227 // ________ XAccessible ________
228 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext()
229 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
231 // ________ XAccessibleContext ________
232 virtual sal_Int32 SAL_CALL getAccessibleChildCount()
233 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
234 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
235 getAccessibleChild( sal_Int32 i )
236 throw (::com::sun::star::lang::IndexOutOfBoundsException,
237 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
238 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
239 getAccessibleParent()
240 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
241 virtual sal_Int32 SAL_CALL getAccessibleIndexInParent()
242 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
243 /// @return AccessibleRole.SHAPE
244 virtual sal_Int16 SAL_CALL getAccessibleRole()
245 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
246 // has to be implemented by derived classes
247 // virtual OUString SAL_CALL getAccessibleName()
248 // throw (::com::sun::star::uno::RuntimeException);
249 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL
250 getAccessibleRelationSet()
251 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
252 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL
253 getAccessibleStateSet()
254 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
255 virtual ::com::sun::star::lang::Locale SAL_CALL getLocale()
256 throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException,
257 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
258 // has to be implemented by derived classes
259 // virtual OUString SAL_CALL getAccessibleDescription()
260 // throw (::com::sun::star::uno::RuntimeException);
262 // ________ XAccessibleComponent ________
263 virtual sal_Bool SAL_CALL containsPoint(
264 const ::com::sun::star::awt::Point& aPoint )
265 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
266 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
267 getAccessibleAtPoint( const ::com::sun::star::awt::Point& aPoint )
268 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
269 // has to be defined in derived classes
270 virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds()
271 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
272 virtual ::com::sun::star::awt::Point SAL_CALL getLocation()
273 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
274 virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen()
275 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
276 virtual ::com::sun::star::awt::Size SAL_CALL getSize()
277 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
278 virtual void SAL_CALL grabFocus()
279 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
280 virtual sal_Int32 SAL_CALL getForeground()
281 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
282 virtual sal_Int32 SAL_CALL getBackground()
283 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
285 // ________ XServiceInfo ________
286 virtual OUString SAL_CALL getImplementationName()
287 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
288 virtual sal_Bool SAL_CALL supportsService(
289 const OUString& ServiceName )
290 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
291 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
292 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
294 // ________ XEventListener ________
295 virtual void SAL_CALL disposing(
296 const ::com::sun::star::lang::EventObject& Source )
297 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
299 // ________ XAccessibleEventBroadcaster ________
300 virtual void SAL_CALL addAccessibleEventListener(
301 const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener )
302 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
303 virtual void SAL_CALL removeAccessibleEventListener(
304 const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener )
305 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
307 private:
308 enum eColorType
310 ACC_BASE_FOREGROUND,
311 ACC_BASE_BACKGROUND
313 sal_Int32 getColor( eColorType eColType );
315 private:
316 typedef ::com::sun::star::uno::Reference<
317 ::com::sun::star::accessibility::XAccessible > tAccessible;
318 /** type of the vector containing the accessible children
320 typedef ::std::vector< tAccessible > ChildListVectorType;
321 /** type of the hash containing a vector index for every AccessibleUniqueId
322 of the object in the child list
324 typedef ::std::map< ObjectIdentifier, tAccessible > ChildOIDMap;
326 bool m_bIsDisposed;
327 const bool m_bMayHaveChildren;
328 bool m_bChildrenInitialized;
329 ChildListVectorType m_aChildList;
331 ChildOIDMap m_aChildOIDMap;
333 ::comphelper::AccessibleEventNotifier::TClientId m_nEventNotifierId;
335 /** Implementation helper for getAccessibleStateSet()
337 Note: This member must come before m_aStateSet!
339 ::utl::AccessibleStateSetHelper * m_pStateSetHelper;
340 /** this is returned in getAccessibleStateSet().
342 The implementation is an ::utl::AccessibleStateSetHelper. To access
343 implementation methods use m_pStateSetHelper.
345 Note: Keeping this reference ensures, that the helper object is only
346 destroyed after this object has been disposed().
348 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet >
349 m_aStateSet;
351 AccessibleElementInfo m_aAccInfo;
352 const bool m_bAlwaysTransparent;
353 /** denotes if the state-set is initialized. On initialization the selected
354 state is checked.
356 This variable is monitored by the solar mutex!
358 Note: declared volatile to enable double-check-locking
360 volatile bool m_bStateSetInitialized;
363 } // namespace chart
365 #endif
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */