1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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/basemutex.hxx>
31 #include <cppuhelper/compbase.hxx>
32 #include <rtl/ref.hxx>
33 #include <tools/color.hxx>
34 #include <unotools/weakref.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
; }
47 namespace accessibility
49 class IAccessibleViewForwarder
;
57 class ObjectHierarchy
;
58 class ChartController
;
60 typedef ObjectIdentifier AccessibleUniqueId
;
62 struct AccessibleElementInfo
64 AccessibleUniqueId m_aOID
;
66 unotools::WeakReference
< ::chart::ChartModel
> m_xChartDocument
;
67 unotools::WeakReference
< ::chart::ChartController
> m_xChartController
;
68 unotools::WeakReference
< ::chart::ChartView
> m_xView
;
69 css::uno::WeakReference
< css::awt::XWindow
> m_xWindow
;
71 std::shared_ptr
< ObjectHierarchy
> m_spObjectHierarchy
;
73 AccessibleBase
* m_pParent
;
75 ::accessibility::IAccessibleViewForwarder
* m_pViewForwarder
;
80 typedef ::cppu::WeakComponentImplHelper
<
81 css::accessibility::XAccessible
,
82 css::accessibility::XAccessibleContext
,
83 css::accessibility::XAccessibleComponent
,
84 css::accessibility::XAccessibleEventBroadcaster
,
85 css::lang::XServiceInfo
,
86 css::lang::XEventListener
87 > AccessibleBase_Base
;
90 /** Base class for all Chart Accessibility objects
92 class AccessibleBase
:
93 public cppu::BaseMutex
,
94 public impl::AccessibleBase_Base
103 AccessibleBase( AccessibleElementInfo aAccInfo
,
104 bool bMayHaveChildren
,
105 bool bAlwaysTransparent
);
106 virtual ~AccessibleBase() override
;
109 // for all calls to protected methods it is assumed that the mutex is locked
110 // unless calls outside via UNO, e.g. event notification, are done
112 /** @param bThrowException if true, a DisposedException is thrown if the
113 object is already disposed
114 @return true, if the component is already disposed and bThrowException is false,
116 @throws css::lang::DisposedException
118 bool CheckDisposeState( bool bThrowException
= true ) const;
120 /** Events coming from the core have to be processed in this methods. The
121 default implementation returns false, which indicates that the object is
122 not interested in the event. To react on events you have to implement
123 this method in derived classes.
125 The default implementation iterates over all children and forwards the
126 event until the first child returns true.
128 @param nObjId contains the object id of chart objects. If the object is
129 no chart object, the event is not broadcast.
130 @return If an object is the addressee of the event it should return
131 true, false otherwise.
133 bool NotifyEvent( EventType eType
, const AccessibleUniqueId
& rId
);
135 /** Adds a state to the set.
137 @throws css::uno::RuntimeException
139 void AddState( sal_Int64 aState
);
141 /** Removes a state from the set if the set contains the state, otherwise
144 @throws css::uno::RuntimeException
146 void RemoveState( sal_Int64 aState
);
148 /** has to be overridden by derived classes that support child elements.
149 With this method a rescan is initiated that should result in a correct
152 This method is called when access to any methods concerning children is
153 invoked for the first time.
155 bool UpdateChildren();
157 /** Is called by UpdateChildren. This method is only called if an update is
160 virtual bool ImplUpdateChildren();
162 /** adds a child to the end of the internal vector of children. As a
163 result, the child-count increases by one, but all existing children keep
166 Important: as the implementation is needed, this should remain the only
167 method for adding children (i.e. there mustn't be an AddChild( Reference<
168 XAccessible > ) or the like).
170 void AddChild( AccessibleBase
* pChild
);
172 /** removes a child from the internal vector. All children with index
173 greater than the index of the removed element get an index one less than
176 void RemoveChildByOId( const ObjectIdentifier
& rOId
);
178 /** Retrieve the pixel coordinates of logical coordinates (0,0) of the
179 current logic coordinate system. This can be used for
180 getLocationOnScreen, if the coordinates of an object are not relative to
181 its direct parent, but a parent higher up in hierarchy.
183 @return the (x,y) pixel coordinates of the upper left corner
185 virtual css::awt::Point
GetUpperLeftOnScreen() const;
187 /** This method creates an AccessibleEventObject and sends it to all
188 listeners that are currently listening to this object
190 void BroadcastAccEvent( sal_Int16 nId
,
191 const css::uno::Any
& rNew
,
192 const css::uno::Any
& rOld
) const;
194 /** Removes all children from the internal lists and broadcasts child remove
197 This method cares about mutex locking, and thus should be called without
200 void KillAllChildren();
202 /** Is called from getAccessibleChild(). Before this method is called, an
203 update of children is done if necessary.
205 @throws css::lang::IndexOutOfBoundsException
206 @throws css::uno::RuntimeException
208 virtual css::uno::Reference
< css::accessibility::XAccessible
>
209 ImplGetAccessibleChildById( sal_Int64 i
) const;
211 /** Is called from getAccessibleChildCount(). Before this method is called,
212 an update of children is done if necessary.
214 @throws css::uno::RuntimeException
216 virtual sal_Int64
ImplGetAccessibleChildCount() const;
218 const AccessibleElementInfo
& GetInfo() const { return m_aAccInfo
;}
219 void SetInfo( const AccessibleElementInfo
& rNewInfo
);
220 const AccessibleUniqueId
& GetId() const { return m_aAccInfo
.m_aOID
;}
222 // ________ WeakComponentImplHelper (XComponent::dispose) ________
223 virtual void SAL_CALL
disposing() override
;
225 // ________ XAccessible ________
226 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
getAccessibleContext() override
;
228 // ________ XAccessibleContext ________
229 virtual sal_Int64 SAL_CALL
getAccessibleChildCount() override
;
230 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
231 getAccessibleChild( sal_Int64 i
) override
;
232 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
233 getAccessibleParent() override
;
234 virtual sal_Int64 SAL_CALL
getAccessibleIndexInParent() override
;
235 /// @return AccessibleRole.SHAPE
236 virtual sal_Int16 SAL_CALL
getAccessibleRole() override
;
237 // has to be implemented by derived classes
238 // virtual OUString SAL_CALL getAccessibleName()
239 // throw (css::uno::RuntimeException);
240 virtual css::uno::Reference
< css::accessibility::XAccessibleRelationSet
> SAL_CALL
241 getAccessibleRelationSet() override
;
242 virtual sal_Int64 SAL_CALL
getAccessibleStateSet() override
;
243 virtual css::lang::Locale SAL_CALL
getLocale() override
;
244 // has to be implemented by derived classes
245 // virtual OUString SAL_CALL getAccessibleDescription()
246 // throw (css::uno::RuntimeException);
248 // ________ XAccessibleComponent ________
249 virtual sal_Bool SAL_CALL
containsPoint(
250 const css::awt::Point
& aPoint
) override
;
251 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
252 getAccessibleAtPoint( const css::awt::Point
& aPoint
) override
;
253 // has to be defined in derived classes
254 virtual css::awt::Rectangle SAL_CALL
getBounds() override
;
255 virtual css::awt::Point SAL_CALL
getLocation() override
;
256 virtual css::awt::Point SAL_CALL
getLocationOnScreen() override
;
257 virtual css::awt::Size SAL_CALL
getSize() override
;
258 virtual void SAL_CALL
grabFocus() override
;
259 virtual sal_Int32 SAL_CALL
getForeground() override
;
260 virtual sal_Int32 SAL_CALL
getBackground() override
;
262 // ________ XServiceInfo ________
263 virtual OUString SAL_CALL
getImplementationName() override
;
264 virtual sal_Bool SAL_CALL
supportsService(
265 const OUString
& ServiceName
) override
;
266 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
268 // ________ XEventListener ________
269 virtual void SAL_CALL
disposing(
270 const css::lang::EventObject
& Source
) override
;
272 // ________ XAccessibleEventBroadcaster ________
273 virtual void SAL_CALL
addAccessibleEventListener(
274 const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& xListener
) override
;
275 virtual void SAL_CALL
removeAccessibleEventListener(
276 const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& xListener
) override
;
284 Color
getColor( eColorType eColType
);
287 /** type of the vector containing the accessible children
289 typedef std::vector
< css::uno::Reference
< css::accessibility::XAccessible
> > ChildListVectorType
;
290 /** type of the hash containing a vector index for every AccessibleUniqueId
291 of the object in the child list
293 typedef std::map
< ObjectIdentifier
, css::uno::Reference
< css::accessibility::XAccessible
> > ChildOIDMap
;
296 const bool m_bMayHaveChildren
;
297 bool m_bChildrenInitialized
;
298 ChildListVectorType m_aChildList
;
300 ChildOIDMap m_aChildOIDMap
;
302 ::comphelper::AccessibleEventNotifier::TClientId m_nEventNotifierId
;
304 /** for getAccessibleStateSet()
306 sal_Int64 m_nStateSet
;
308 AccessibleElementInfo m_aAccInfo
;
309 const bool m_bAlwaysTransparent
;
310 /** denotes if the state-set is initialized. On initialization the selected
313 This variable is monitored by the solar mutex!
315 Note: declared volatile to enable double-check-locking
317 volatile bool m_bStateSetInitialized
;
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */