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 <tools/color.hxx>
33 #include <unotools/weakref.hxx>
39 namespace com::sun::star::awt
{ class XWindow
; }
40 namespace com::sun::star::chart2
{ class XChartDocument
; }
41 namespace com::sun::star::view
{ class XSelectionSupplier
; }
46 namespace accessibility
48 class IAccessibleViewForwarder
;
56 class ObjectHierarchy
;
57 class ChartController
;
59 typedef ObjectIdentifier AccessibleUniqueId
;
61 struct AccessibleElementInfo
63 AccessibleUniqueId m_aOID
;
65 unotools::WeakReference
< ::chart::ChartModel
> m_xChartDocument
;
66 unotools::WeakReference
< ::chart::ChartController
> m_xChartController
;
67 unotools::WeakReference
< ::chart::ChartView
> m_xView
;
68 css::uno::WeakReference
< css::awt::XWindow
> m_xWindow
;
70 std::shared_ptr
< ObjectHierarchy
> m_spObjectHierarchy
;
72 AccessibleBase
* m_pParent
;
74 ::accessibility::IAccessibleViewForwarder
* m_pViewForwarder
;
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 cppu::BaseMutex
,
93 public impl::AccessibleBase_Base
102 AccessibleBase( AccessibleElementInfo aAccInfo
,
103 bool bMayHaveChildren
,
104 bool bAlwaysTransparent
);
105 virtual ~AccessibleBase() override
;
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,
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_Int64 aState
);
140 /** Removes a state from the set if the set contains the state, otherwise
143 @throws css::uno::RuntimeException
145 void RemoveState( sal_Int64 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
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
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
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
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 void BroadcastAccEvent( sal_Int16 nId
,
190 const css::uno::Any
& rNew
,
191 const css::uno::Any
& rOld
) const;
193 /** Removes all children from the internal lists and broadcasts child remove
196 This method cares about mutex locking, and thus should be called without
199 void KillAllChildren();
201 /** Is called from getAccessibleChild(). Before this method is called, an
202 update of children is done if necessary.
204 @throws css::lang::IndexOutOfBoundsException
205 @throws css::uno::RuntimeException
207 virtual css::uno::Reference
< css::accessibility::XAccessible
>
208 ImplGetAccessibleChildById( sal_Int64 i
) const;
210 /** Is called from getAccessibleChildCount(). Before this method is called,
211 an update of children is done if necessary.
213 @throws css::uno::RuntimeException
215 virtual sal_Int64
ImplGetAccessibleChildCount() const;
217 const AccessibleElementInfo
& GetInfo() const { return m_aAccInfo
;}
218 void SetInfo( const AccessibleElementInfo
& rNewInfo
);
219 const AccessibleUniqueId
& GetId() const { return m_aAccInfo
.m_aOID
;}
221 // ________ WeakComponentImplHelper (XComponent::dispose) ________
222 virtual void SAL_CALL
disposing() override
;
224 // ________ XAccessible ________
225 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
getAccessibleContext() override
;
227 // ________ XAccessibleContext ________
228 virtual sal_Int64 SAL_CALL
getAccessibleChildCount() override
;
229 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
230 getAccessibleChild( sal_Int64 i
) override
;
231 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
232 getAccessibleParent() override
;
233 virtual sal_Int64 SAL_CALL
getAccessibleIndexInParent() override
;
234 /// @return AccessibleRole.SHAPE
235 virtual sal_Int16 SAL_CALL
getAccessibleRole() override
;
236 // has to be implemented by derived classes
237 // virtual OUString SAL_CALL getAccessibleName()
238 // throw (css::uno::RuntimeException);
239 virtual css::uno::Reference
< css::accessibility::XAccessibleRelationSet
> SAL_CALL
240 getAccessibleRelationSet() override
;
241 virtual sal_Int64 SAL_CALL
getAccessibleStateSet() override
;
242 virtual css::lang::Locale SAL_CALL
getLocale() override
;
243 // has to be implemented by derived classes
244 // virtual OUString SAL_CALL getAccessibleDescription()
245 // throw (css::uno::RuntimeException);
247 // ________ XAccessibleComponent ________
248 virtual sal_Bool SAL_CALL
containsPoint(
249 const css::awt::Point
& aPoint
) override
;
250 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
251 getAccessibleAtPoint( const css::awt::Point
& aPoint
) override
;
252 // has to be defined in derived classes
253 virtual css::awt::Rectangle SAL_CALL
getBounds() override
;
254 virtual css::awt::Point SAL_CALL
getLocation() override
;
255 virtual css::awt::Point SAL_CALL
getLocationOnScreen() override
;
256 virtual css::awt::Size SAL_CALL
getSize() override
;
257 virtual void SAL_CALL
grabFocus() override
;
258 virtual sal_Int32 SAL_CALL
getForeground() override
;
259 virtual sal_Int32 SAL_CALL
getBackground() override
;
261 // ________ XServiceInfo ________
262 virtual OUString SAL_CALL
getImplementationName() override
;
263 virtual sal_Bool SAL_CALL
supportsService(
264 const OUString
& ServiceName
) override
;
265 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
267 // ________ XEventListener ________
268 virtual void SAL_CALL
disposing(
269 const css::lang::EventObject
& Source
) override
;
271 // ________ XAccessibleEventBroadcaster ________
272 virtual void SAL_CALL
addAccessibleEventListener(
273 const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& xListener
) override
;
274 virtual void SAL_CALL
removeAccessibleEventListener(
275 const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& xListener
) override
;
283 Color
getColor( eColorType eColType
);
286 /** type of the hash containing a vector index for every AccessibleUniqueId
287 of the object in the child list
289 typedef std::map
< ObjectIdentifier
, css::uno::Reference
< css::accessibility::XAccessible
> > ChildOIDMap
;
292 const bool m_bMayHaveChildren
;
293 bool m_bChildrenInitialized
;
294 std::vector
<css::uno::Reference
<css::accessibility::XAccessible
>> m_aChildList
;
296 ChildOIDMap m_aChildOIDMap
;
298 ::comphelper::AccessibleEventNotifier::TClientId m_nEventNotifierId
;
300 /** for getAccessibleStateSet()
302 sal_Int64 m_nStateSet
;
304 AccessibleElementInfo m_aAccInfo
;
305 const bool m_bAlwaysTransparent
;
306 /** denotes if the state-set is initialized. On initialization the selected
309 This variable is monitored by the solar mutex!
311 Note: declared volatile to enable double-check-locking
313 volatile bool m_bStateSetInitialized
;
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */