Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / accessibility / inc / extended / AccessibleGridControlBase.hxx
blob2c9cbd42fae1ed4a2f49d67d0245f0425fee19cf
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 .
21 #ifndef INCLUDED_ACCESSIBILITY_INC_EXTENDED_ACCESSIBLEGRIDCONTROLBASE_HXX
22 #define INCLUDED_ACCESSIBILITY_INC_EXTENDED_ACCESSIBLEGRIDCONTROLBASE_HXX
24 #include <svtools/accessibletable.hxx>
25 #include <rtl/ustring.hxx>
26 #include <tools/gen.hxx>
27 #include <vcl/svapp.hxx>
28 #include <cppuhelper/compbase4.hxx>
29 #include <cppuhelper/implbase1.hxx>
30 #include <cppuhelper/basemutex.hxx>
31 #include <unotools/accessiblestatesethelper.hxx>
32 #include <toolkit/helper/convert.hxx>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/lang/DisposedException.hpp>
35 #include <com/sun/star/awt/XWindow.hpp>
36 #include <com/sun/star/accessibility/XAccessible.hpp>
37 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
38 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
39 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
40 #include <com/sun/star/accessibility/AccessibleRole.hpp>
41 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
42 #include <comphelper/accessibleeventnotifier.hxx>
43 #include <comphelper/uno3.hxx>
46 namespace vcl { class Window; }
48 namespace utl {
49 class AccessibleStateSetHelper;
53 namespace accessibility {
55 typedef ::cppu::WeakAggComponentImplHelper4<
56 css::accessibility::XAccessibleContext,
57 css::accessibility::XAccessibleComponent,
58 css::accessibility::XAccessibleEventBroadcaster,
59 css::lang::XServiceInfo >
60 AccessibleGridControlImplHelper;
62 /** The GridControl accessible objects inherit from this base class. It
63 implements basic functionality for various Accessibility interfaces and
64 the event broadcaster and contains the osl::Mutex. */
65 class AccessibleGridControlBase :
66 public ::cppu::BaseMutex,
67 public AccessibleGridControlImplHelper
69 public:
70 /** Constructor sets specified name and description.
71 @param rxParent XAccessible interface of the parent object.
72 @param rTable The Table control.
73 @param eObjType Type of accessible table control. */
74 AccessibleGridControlBase(
75 const css::uno::Reference< css::accessibility::XAccessible >& rxParent,
76 ::svt::table::IAccessibleTable& rTable,
77 ::svt::table::AccessibleTableControlObjType eObjType );
79 protected:
80 virtual ~AccessibleGridControlBase() override;
82 /** Commits DeFunc event to listeners and cleans up members. */
83 virtual void SAL_CALL disposing() override;
85 public:
86 // XAccessibleContext
88 /** @return A reference to the parent accessible object. */
89 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
90 getAccessibleParent() override;
92 /** @return The index of this object among the parent's children. */
93 virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() override;
95 /** @return
96 The description of this object.
98 virtual OUString SAL_CALL getAccessibleDescription() override;
100 /** @return
101 The name of this object.
103 virtual OUString SAL_CALL getAccessibleName() override;
105 /** @return
106 The relation set (the GridControl does not have one).
108 virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL
109 getAccessibleRelationSet() override;
111 /** @return The set of current states. */
112 virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL
113 getAccessibleStateSet() override;
115 /** @return The parent's locale. */
116 virtual css::lang::Locale SAL_CALL getLocale() override;
118 /** @return
119 The role of this object. Panel, ROWHEADER, COLUMNHEADER, TABLE, TABLE_CELL are supported.
121 virtual sal_Int16 SAL_CALL getAccessibleRole() override;
123 /* Derived classes have to implement:
124 - getAccessibleChildCount,
125 - getAccessibleChild,
126 - getAccessibleRole.
127 Derived classes may overwrite getAccessibleIndexInParent to increase
128 performance. */
130 // XAccessibleComponent
132 /** @return
133 TRUE, if the point lies within the bounding box of this object. */
134 virtual sal_Bool SAL_CALL containsPoint( const css::awt::Point& rPoint ) override;
136 /** @return The bounding box of this object. */
137 virtual css::awt::Rectangle SAL_CALL getBounds() override;
139 /** @return
140 The upper left corner of the bounding box relative to the parent. */
141 virtual css::awt::Point SAL_CALL getLocation() override;
143 /** @return
144 The upper left corner of the bounding box in screen coordinates. */
145 virtual css::awt::Point SAL_CALL getLocationOnScreen() override;
147 /** @return The size of the bounding box. */
148 virtual css::awt::Size SAL_CALL getSize() override;
150 virtual sal_Int32 SAL_CALL getForeground( ) override;
151 virtual sal_Int32 SAL_CALL getBackground( ) override;
154 /* Derived classes have to implement:
155 - getAccessibleAt,
156 - grabFocus. */
158 /** @return
159 The accessible child rendered under the given point.
161 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
162 getAccessibleAtPoint( const css::awt::Point& rPoint ) override;
164 // XAccessibleEventBroadcaster
166 /** Adds a new event listener */
167 virtual void SAL_CALL addAccessibleEventListener(
168 const css::uno::Reference< css::accessibility::XAccessibleEventListener>& rxListener ) override;
170 /** Removes an event listener. */
171 virtual void SAL_CALL removeAccessibleEventListener(
172 const css::uno::Reference< css::accessibility::XAccessibleEventListener>& rxListener ) override;
174 // XTypeProvider
176 /** @return An unique implementation ID. */
177 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
179 // XServiceInfo
181 /** @return Whether the specified service is supported by this class. */
182 virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override;
184 /** @return A list of all supported services. */
185 virtual css::uno::Sequence< OUString > SAL_CALL
186 getSupportedServiceNames() override;
188 /* Derived classes have to implement:
189 - getImplementationName. */
191 // helper methods
193 /** @return The GridControl object type. */
194 inline ::svt::table::AccessibleTableControlObjType getType() const;
196 /** Commits an event to all listeners. */
197 void commitEvent(
198 sal_Int16 nEventId,
199 const css::uno::Any& rNewValue,
200 const css::uno::Any& rOldValue );
201 /** @return TRUE, if the object is not disposed or disposing. */
202 bool isAlive() const;
204 protected:
205 // internal virtual methods
207 /** Determines whether the Grid control is really showing inside of
208 its parent accessible window. Derived classes may implement different
209 behaviour.
210 @attention This method requires locked mutex's and a living object.
211 @return TRUE, if the object is really showing. */
212 bool implIsShowing();
214 /** Derived classes return the bounding box relative to the parent window.
215 @attention This method requires locked mutex's and a living object.
216 @return The bounding box (VCL rect.) relative to the parent window. */
217 virtual tools::Rectangle implGetBoundingBox() = 0;
218 ///** Derived classes return the bounding box in screen coordinates.
219 // @attention This method requires locked mutex's and a living object.
220 // @return The bounding box (VCL rect.) in screen coordinates. */
221 virtual tools::Rectangle implGetBoundingBoxOnScreen() = 0;
223 /** Creates a new AccessibleStateSetHelper and fills it with states of the
224 current object. This method calls FillStateSet at the GridControl which
225 fills it with more states depending on the object type. Derived classes
226 may overwrite this method and add more states.
227 @attention This method requires locked mutex's.
228 @return A filled AccessibleStateSetHelper. */
229 virtual ::utl::AccessibleStateSetHelper* implCreateStateSetHelper();
231 // internal helper methods
233 /** @throws <type>DisposedException</type> If the object is not alive. */
234 void ensureIsAlive() const;
236 /** Changes the name of the object (flat assignment, no notify).
237 @attention This method requires a locked mutex. */
238 inline void implSetName( const OUString& rName );
240 /** Locks all mutex's and calculates the bounding box relative to the
241 parent window.
242 @return The bounding box (VCL rect.) relative to the parent object.
243 @throws css::lang::DisposedException
245 tools::Rectangle getBoundingBox();
246 ///** Locks all mutex's and calculates the bounding box in screen
247 // coordinates.
248 // @return The bounding box (VCL rect.) in screen coordinates. */
249 /// @throws css::lang::DisposedException
250 tools::Rectangle getBoundingBoxOnScreen();
252 ::comphelper::AccessibleEventNotifier::TClientId getClientId() const { return m_aClientId; }
253 void setClientId(::comphelper::AccessibleEventNotifier::TClientId _aNewClientId) { m_aClientId = _aNewClientId; }
255 protected:
256 // members
258 /** The parent accessible object. */
259 css::uno::Reference< css::accessibility::XAccessible > m_xParent;
260 /** The SVT Table control. */
261 ::svt::table::IAccessibleTable& m_aTable;
262 /** The type of this object (for names, descriptions, state sets, ...). */
263 ::svt::table::AccessibleTableControlObjType m_eObjType;
265 private:
266 /** Localized name. */
267 OUString m_aName;
268 /** Localized description text. */
269 OUString m_aDescription;
270 ::comphelper::AccessibleEventNotifier::TClientId m_aClientId;
274 // a version of AccessibleGridControlBase which implements not only the XAccessibleContext,
275 // but also the XAccessible
277 typedef ::cppu::ImplHelper1 < css::accessibility::XAccessible
278 > GridControlAccessibleElement_Base;
280 class GridControlAccessibleElement
281 :public AccessibleGridControlBase
282 ,public GridControlAccessibleElement_Base
284 protected:
285 /** Constructor sets specified name and description.
287 @param rxParent XAccessible interface of the parent object.
288 @param rTable The Table control.
289 @param eObjType Type of table control
291 GridControlAccessibleElement(
292 const css::uno::Reference< css::accessibility::XAccessible >& rxParent,
293 ::svt::table::IAccessibleTable& rTable,
294 ::svt::table::AccessibleTableControlObjType eObjType );
296 public:
297 // XInterface
298 DECLARE_XINTERFACE( )
299 // XTypeProvider
300 DECLARE_XTYPEPROVIDER( )
302 protected:
303 virtual ~GridControlAccessibleElement() override;
305 protected:
306 // XAccessible
308 /** @return The XAccessibleContext interface of this object. */
309 virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL
310 getAccessibleContext() override;
312 private:
313 GridControlAccessibleElement( const GridControlAccessibleElement& ) = delete;
314 GridControlAccessibleElement& operator=( const GridControlAccessibleElement& ) = delete;
317 // inlines
319 inline ::svt::table::AccessibleTableControlObjType AccessibleGridControlBase::getType() const
321 return m_eObjType;
324 inline void AccessibleGridControlBase::implSetName(
325 const OUString& rName )
327 m_aName = rName;
331 } // namespace accessibility
334 #endif // ACCESSIBILITY_EXT_ACCESSIBILEGRIDCONTROLBASE_HXX
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */