Debian Codegraph @

chart2/source/controller/inc/AccessibleBase.hxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19 #pragma once
20
21 #include <ObjectIdentifier.hxx>
22
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 <comphelper/OAccessible.hxx>
27 #include <tools/color.hxx>
28 #include <unotools/weakref.hxx>
29 #include <vcl/window.hxx>
30
31 #include <map>
32 #include <vector>
33 #include <memory>
34
35 class SdrView;
36
37 namespace accessibility
38 {
39 class IAccessibleViewForwarder;
40 }
41
42 namespace chart
43 {
44
45 class AccessibleBase;
46 class ChartView;
47 class ObjectHierarchy;
48 class ChartController;
49
50 typedef ObjectIdentifier AccessibleUniqueId;
51
52 struct AccessibleElementInfo
53 {
54 AccessibleUniqueId m_aOID;
55
56 unotools::WeakReference< ::chart::ChartModel > m_xChartDocument;
57 unotools::WeakReference< ::chart::ChartController > m_xChartController;
58 unotools::WeakReference< ::chart::ChartView > m_xView;
59 VclPtr<vcl::Window> m_pWindow;
60
61 std::shared_ptr< ObjectHierarchy > m_spObjectHierarchy;
62
63 AccessibleBase * m_pParent;
64 SdrView* m_pSdrView;
65 ::accessibility::IAccessibleViewForwarder* m_pViewForwarder;
66 };
67
68 /** Base class for all Chart Accessibility objects
69 */
70 class AccessibleBase : public comphelper::OAccessible
71 {
72 public:
73 enum class EventType
74 {
75 GOT_SELECTION,
76 LOST_SELECTION
77 };
78
79 AccessibleBase( AccessibleElementInfo aAccInfo,
80 bool bMayHaveChildren,
81 bool bAlwaysTransparent );
82 virtual ~AccessibleBase() override;
83
84 protected:
85 // for all calls to protected methods it is assumed that the mutex is locked
86 // unless calls outside via UNO, e.g. event notification, are done
87
88 /** Events coming from the core have to be processed in this methods. The
89 default implementation returns false, which indicates that the object is
90 not interested in the event. To react on events you have to implement
91 this method in derived classes.
92
93 The default implementation iterates over all children and forwards the
94 event until the first child returns true.
95
96 @param nObjId contains the object id of chart objects. If the object is
97 no chart object, the event is not broadcast.
98 @return If an object is the addressee of the event it should return
99 true, false otherwise.
100 */
101 bool NotifyEvent( EventType eType, const AccessibleUniqueId & rId );
102
103 /** Adds a state to the set.
104
105 @throws css::uno::RuntimeException
106 */
107 void AddState( sal_Int64 aState );
108
109 /** Removes a state from the set if the set contains the state, otherwise
110 nothing is done.
111
112 @throws css::uno::RuntimeException
113 */
114 void RemoveState( sal_Int64 aState );
115
116 /** has to be overridden by derived classes that support child elements.
117 With this method a rescan is initiated that should result in a correct
118 list of children.
119
120 This method is called when access to any methods concerning children is
121 invoked for the first time.
122 */
123 bool UpdateChildren();
124
125 /** Is called by UpdateChildren. This method is only called if an update is
126 really necessary.
127 */
128 virtual bool ImplUpdateChildren();
129
130 /** adds a child to the end of the internal vector of children. As a
131 result, the child-count increases by one, but all existing children keep
132 their indices.
133
134 Important: as the implementation is needed, this should remain the only
135 method for adding children (i.e. there mustn't be an AddChild( Reference<
136 XAccessible > ) or the like).
137 */
138 void AddChild( AccessibleBase* pChild );
139
140 /** removes a child from the internal vector. All children with index
141 greater than the index of the removed element get an index one less than
142 before.
143 */
144 void RemoveChildByOId( const ObjectIdentifier& rOId );
145
146 /** Retrieve the pixel coordinates of logical coordinates (0,0) of the
147 current logic coordinate system. This can be used for
148 getLocationOnScreen, if the coordinates of an object are not relative to
149 its direct parent, but a parent higher up in hierarchy.
150
151 @return the (x,y) pixel coordinates of the upper left corner
152 */
153 virtual css::awt::Point GetUpperLeftOnScreen() const;
154
155 /** Removes all children from the internal lists and broadcasts child remove
156 events.
157
158 This method cares about mutex locking, and thus should be called without
159 the mutex locked.
160 */
161 void KillAllChildren();
162
163 /** Is called from getAccessibleChild(). Before this method is called, an
164 update of children is done if necessary.
165
166 @throws css::lang::IndexOutOfBoundsException
167 @throws css::uno::RuntimeException
168 */
169 virtual css::uno::Reference< css::accessibility::XAccessible >
170 ImplGetAccessibleChildById( sal_Int64 i ) const;
171
172 /** Is called from getAccessibleChildCount(). Before this method is called,
173 an update of children is done if necessary.
174
175 @throws css::uno::RuntimeException
176 */
177 virtual sal_Int64 ImplGetAccessibleChildCount() const;
178
179 const AccessibleElementInfo& GetInfo() const { return m_aAccInfo;}
180 void SetInfo( const AccessibleElementInfo & rNewInfo );
181 const AccessibleUniqueId& GetId() const { return m_aAccInfo.m_aOID;}
182
183 // ________ WeakComponentImplHelper (XComponent::dispose) ________
184 virtual void SAL_CALL disposing() override;
185
186 // ________ XAccessibleContext ________
187 virtual sal_Int64 SAL_CALL getAccessibleChildCount() override;
188 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
189 getAccessibleChild( sal_Int64 i ) override;
190 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
191 getAccessibleParent() override;
192 virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override;
193 /// @return AccessibleRole.SHAPE
194 virtual sal_Int16 SAL_CALL getAccessibleRole() override;
195 // has to be implemented by derived classes
196 // virtual OUString SAL_CALL getAccessibleName()
197 // throw (css::uno::RuntimeException);
198 virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL
199 getAccessibleRelationSet() override;
200 virtual sal_Int64 SAL_CALL getAccessibleStateSet() override;
201 virtual css::lang::Locale SAL_CALL getLocale() override;
202 // has to be implemented by derived classes
203 // virtual OUString SAL_CALL getAccessibleDescription()
204 // throw (css::uno::RuntimeException);
205
206 // OAccessible
207 virtual css::awt::Rectangle implGetBounds() override;
208
209 // ________ XAccessibleComponent ________
210 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
211 getAccessibleAtPoint( const css::awt::Point& aPoint ) override;
212 virtual void SAL_CALL grabFocus() override;
213 virtual sal_Int32 SAL_CALL getForeground() override;
214 virtual sal_Int32 SAL_CALL getBackground() override;
215
216 private:
217 enum eColorType
218 {
219 ACC_BASE_FOREGROUND,
220 ACC_BASE_BACKGROUND
221 };
222 Color getColor( eColorType eColType );
223
224 private:
225 /** type of the hash containing a vector index for every AccessibleUniqueId
226 of the object in the child list
227 */
228 typedef std::map<ObjectIdentifier, rtl::Reference<AccessibleBase>> ChildOIDMap;
229
230 const bool m_bMayHaveChildren;
231 bool m_bChildrenInitialized;
232 std::vector<rtl::Reference<AccessibleBase>> m_aChildList;
233
234 ChildOIDMap m_aChildOIDMap;
235
236 /** for getAccessibleStateSet()
237 */
238 sal_Int64 m_nStateSet;
239
240 AccessibleElementInfo m_aAccInfo;
241 const bool m_bAlwaysTransparent;
242 /** denotes if the state-set is initialized. On initialization the selected
243 state is checked.
244
245 This variable is monitored by the solar mutex!
246 */
247 bool m_bStateSetInitialized;
248 };
249
250 } // namespace chart
251
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */