nss: upgrade to release 3.73
[LibreOffice.git] / chart2 / source / controller / inc / AccessibleBase.hxx
blob88f4ef79ffb2cdf04c886c5a09169661d12ca108
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 #pragma once
21 #include <ObjectIdentifier.hxx>
23 #include <com/sun/star/accessibility/XAccessible.hpp>
24 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
25 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/lang/XEventListener.hpp>
28 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
29 #include <comphelper/accessibleeventnotifier.hxx>
30 #include <cppuhelper/compbase.hxx>
31 #include <rtl/ref.hxx>
32 #include <tools/color.hxx>
34 #include <map>
35 #include <vector>
36 #include <memory>
38 #include <MutexContainer.hxx>
40 namespace com::sun::star::awt { class XWindow; }
41 namespace com::sun::star::chart2 { class XChartDocument; }
42 namespace com::sun::star::view { class XSelectionSupplier; }
43 namespace utl { class AccessibleStateSetHelper; }
46 class SdrView;
48 namespace accessibility
50 class IAccessibleViewForwarder;
53 namespace chart
56 class AccessibleBase;
57 class ObjectHierarchy;
59 typedef ObjectIdentifier AccessibleUniqueId;
61 struct AccessibleElementInfo
63 AccessibleUniqueId m_aOID;
65 css::uno::WeakReference< css::chart2::XChartDocument > m_xChartDocument;
66 css::uno::WeakReference< css::view::XSelectionSupplier > m_xSelectionSupplier;
67 css::uno::WeakReference< css::uno::XInterface > m_xView;
68 css::uno::WeakReference< css::awt::XWindow > m_xWindow;
70 std::shared_ptr< ObjectHierarchy > m_spObjectHierarchy;
72 AccessibleBase * m_pParent;
73 SdrView* m_pSdrView;
74 ::accessibility::IAccessibleViewForwarder* m_pViewForwarder;
77 namespace impl
79 typedef ::cppu::WeakComponentImplHelper<
80 css::accessibility::XAccessible,
81 css::accessibility::XAccessibleContext,
82 css::accessibility::XAccessibleComponent,
83 css::accessibility::XAccessibleEventBroadcaster,
84 css::lang::XServiceInfo,
85 css::lang::XEventListener
86 > AccessibleBase_Base;
89 /** Base class for all Chart Accessibility objects
91 class AccessibleBase :
92 public MutexContainer,
93 public impl::AccessibleBase_Base
95 public:
96 enum class EventType
98 GOT_SELECTION,
99 LOST_SELECTION
102 AccessibleBase( const AccessibleElementInfo & rAccInfo,
103 bool bMayHaveChildren,
104 bool bAlwaysTransparent );
105 virtual ~AccessibleBase() override;
107 protected:
108 // for all calls to protected methods it is assumed that the mutex is locked
109 // unless calls outside via UNO, e.g. event notification, are done
111 /** @param bThrowException if true, a DisposedException is thrown if the
112 object is already disposed
113 @return true, if the component is already disposed and bThrowException is false,
114 false otherwise
115 @throws css::lang::DisposedException
117 bool CheckDisposeState( bool bThrowException = true ) const;
119 /** Events coming from the core have to be processed in this methods. The
120 default implementation returns false, which indicates that the object is
121 not interested in the event. To react on events you have to implement
122 this method in derived classes.
124 The default implementation iterates over all children and forwards the
125 event until the first child returns true.
127 @param nObjId contains the object id of chart objects. If the object is
128 no chart object, the event is not broadcast.
129 @return If an object is the addressee of the event it should return
130 true, false otherwise.
132 bool NotifyEvent( EventType eType, const AccessibleUniqueId & rId );
134 /** Adds a state to the set.
136 @throws css::uno::RuntimeException
138 void AddState( sal_Int16 aState );
140 /** Removes a state from the set if the set contains the state, otherwise
141 nothing is done.
143 @throws css::uno::RuntimeException
145 void RemoveState( sal_Int16 aState );
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 css::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 css::uno::Any & rNew,
194 const css::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 @throws css::lang::IndexOutOfBoundsException
209 @throws css::uno::RuntimeException
211 virtual css::uno::Reference< css::accessibility::XAccessible >
212 ImplGetAccessibleChildById( sal_Int32 i ) const;
214 /** Is called from getAccessibleChildCount(). Before this method is called,
215 an update of children is done if necessary.
217 @throws css::uno::RuntimeException
219 virtual sal_Int32 ImplGetAccessibleChildCount() const;
221 const AccessibleElementInfo& GetInfo() const { return m_aAccInfo;}
222 void SetInfo( const AccessibleElementInfo & rNewInfo );
223 const AccessibleUniqueId& GetId() const { return m_aAccInfo.m_aOID;}
225 // ________ WeakComponentImplHelper (XComponent::dispose) ________
226 virtual void SAL_CALL disposing() override;
228 // ________ XAccessible ________
229 virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override;
231 // ________ XAccessibleContext ________
232 virtual sal_Int32 SAL_CALL getAccessibleChildCount() override;
233 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
234 getAccessibleChild( sal_Int32 i ) override;
235 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
236 getAccessibleParent() override;
237 virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() override;
238 /// @return AccessibleRole.SHAPE
239 virtual sal_Int16 SAL_CALL getAccessibleRole() override;
240 // has to be implemented by derived classes
241 // virtual OUString SAL_CALL getAccessibleName()
242 // throw (css::uno::RuntimeException);
243 virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL
244 getAccessibleRelationSet() override;
245 virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL
246 getAccessibleStateSet() override;
247 virtual css::lang::Locale SAL_CALL getLocale() override;
248 // has to be implemented by derived classes
249 // virtual OUString SAL_CALL getAccessibleDescription()
250 // throw (css::uno::RuntimeException);
252 // ________ XAccessibleComponent ________
253 virtual sal_Bool SAL_CALL containsPoint(
254 const css::awt::Point& aPoint ) override;
255 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
256 getAccessibleAtPoint( const css::awt::Point& aPoint ) override;
257 // has to be defined in derived classes
258 virtual css::awt::Rectangle SAL_CALL getBounds() override;
259 virtual css::awt::Point SAL_CALL getLocation() override;
260 virtual css::awt::Point SAL_CALL getLocationOnScreen() override;
261 virtual css::awt::Size SAL_CALL getSize() override;
262 virtual void SAL_CALL grabFocus() override;
263 virtual sal_Int32 SAL_CALL getForeground() override;
264 virtual sal_Int32 SAL_CALL getBackground() override;
266 // ________ XServiceInfo ________
267 virtual OUString SAL_CALL getImplementationName() override;
268 virtual sal_Bool SAL_CALL supportsService(
269 const OUString& ServiceName ) override;
270 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
272 // ________ XEventListener ________
273 virtual void SAL_CALL disposing(
274 const css::lang::EventObject& Source ) override;
276 // ________ XAccessibleEventBroadcaster ________
277 virtual void SAL_CALL addAccessibleEventListener(
278 const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
279 virtual void SAL_CALL removeAccessibleEventListener(
280 const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
282 private:
283 enum eColorType
285 ACC_BASE_FOREGROUND,
286 ACC_BASE_BACKGROUND
288 Color getColor( eColorType eColType );
290 private:
291 /** type of the vector containing the accessible children
293 typedef std::vector< css::uno::Reference< css::accessibility::XAccessible > > ChildListVectorType;
294 /** type of the hash containing a vector index for every AccessibleUniqueId
295 of the object in the child list
297 typedef std::map< ObjectIdentifier, css::uno::Reference< css::accessibility::XAccessible > > ChildOIDMap;
299 bool m_bIsDisposed;
300 const bool m_bMayHaveChildren;
301 bool m_bChildrenInitialized;
302 ChildListVectorType m_aChildList;
304 ChildOIDMap m_aChildOIDMap;
306 ::comphelper::AccessibleEventNotifier::TClientId m_nEventNotifierId;
308 /** Implementation helper for getAccessibleStateSet()
310 Note: This member must come before m_aStateSet!
312 rtl::Reference<::utl::AccessibleStateSetHelper> m_xStateSetHelper;
314 AccessibleElementInfo m_aAccInfo;
315 const bool m_bAlwaysTransparent;
316 /** denotes if the state-set is initialized. On initialization the selected
317 state is checked.
319 This variable is monitored by the solar mutex!
321 Note: declared volatile to enable double-check-locking
323 volatile bool m_bStateSetInitialized;
326 } // namespace chart
328 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */