Line data Source code
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 :
20 :
21 : #ifndef INCLUDED_ACCESSIBILITY_INC_ACCESSIBILITY_EXTENDED_ACCESSIBLEGRIDCONTROLBASE_HXX
22 : #define INCLUDED_ACCESSIBILITY_INC_ACCESSIBILITY_EXTENDED_ACCESSIBLEGRIDCONTROLBASE_HXX
23 :
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 <comphelper/broadcasthelper.hxx>
30 : #include <unotools/accessiblestatesethelper.hxx>
31 : #include <toolkit/helper/convert.hxx>
32 : #include <com/sun/star/lang/XServiceInfo.hpp>
33 : #include <com/sun/star/lang/DisposedException.hpp>
34 : #include <com/sun/star/awt/XWindow.hpp>
35 : #include <com/sun/star/accessibility/XAccessible.hpp>
36 : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
37 : #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
38 : #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
39 : #include <com/sun/star/accessibility/AccessibleRole.hpp>
40 : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
41 : #include <comphelper/accessibleeventnotifier.hxx>
42 : #include <comphelper/uno3.hxx>
43 :
44 :
45 :
46 : namespace vcl { class Window; }
47 :
48 : namespace utl {
49 : class AccessibleStateSetHelper;
50 : }
51 :
52 :
53 :
54 : namespace accessibility {
55 :
56 :
57 :
58 :
59 :
60 : typedef ::cppu::WeakAggComponentImplHelper4<
61 : ::com::sun::star::accessibility::XAccessibleContext,
62 : ::com::sun::star::accessibility::XAccessibleComponent,
63 : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
64 : ::com::sun::star::lang::XServiceInfo >
65 : AccessibleGridControlImplHelper;
66 :
67 : /** The GridControl accessible objects inherit from this base class. It
68 : implements basic functionality for various Accessibility interfaces and
69 : the event broadcaster and contains the ::osl::Mutex. */
70 : class AccessibleGridControlBase :
71 : public ::comphelper::OBaseMutex,
72 : public AccessibleGridControlImplHelper
73 : {
74 : public:
75 : /** Constructor sets specified name and description.
76 : @param rxParent XAccessible interface of the parent object.
77 : @param rTable The Table control.
78 : @param eNameText The constant for the name text.
79 : @param eDescrText The constant for the description text. */
80 : AccessibleGridControlBase(
81 : const ::com::sun::star::uno::Reference<
82 : ::com::sun::star::accessibility::XAccessible >& rxParent,
83 : ::svt::table::IAccessibleTable& rTable,
84 : ::svt::table::AccessibleTableControlObjType eObjType );
85 :
86 : protected:
87 : virtual ~AccessibleGridControlBase();
88 :
89 : /** Commits DeFunc event to listeners and cleans up members. */
90 : virtual void SAL_CALL disposing() SAL_OVERRIDE;
91 :
92 : public:
93 : // XAccessibleContext -----------------------------------------------------
94 :
95 : /** @return A reference to the parent accessible object. */
96 : virtual ::com::sun::star::uno::Reference<
97 : ::com::sun::star::accessibility::XAccessible > SAL_CALL
98 : getAccessibleParent()
99 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
100 :
101 : /** @return The index of this object among the parent's children. */
102 : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent()
103 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
104 :
105 : /** @return
106 : The description of this object.
107 : */
108 : virtual OUString SAL_CALL getAccessibleDescription()
109 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
110 :
111 : /** @return
112 : The name of this object.
113 : */
114 : virtual OUString SAL_CALL getAccessibleName()
115 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
116 :
117 : /** @return
118 : The relation set (the GridControl does not have one).
119 : */
120 : virtual ::com::sun::star::uno::Reference<
121 : ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL
122 : getAccessibleRelationSet()
123 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
124 :
125 : /** @return The set of current states. */
126 : virtual ::com::sun::star::uno::Reference<
127 : ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL
128 : getAccessibleStateSet()
129 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
130 :
131 : /** @return The parent's locale. */
132 : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale()
133 : throw ( ::com::sun::star::accessibility::IllegalAccessibleComponentStateException,
134 : ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
135 :
136 : /** @return
137 : The role of this object. Panel, ROWHEADER, COLUMNHEADER, TABLE, TABLE_CELL are supported.
138 : */
139 : virtual sal_Int16 SAL_CALL getAccessibleRole()
140 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
141 :
142 : /* Derived classes have to implement:
143 : - getAccessibleChildCount,
144 : - getAccessibleChild,
145 : - getAccessibleRole.
146 : Derived classes may overwrite getAccessibleIndexInParent to increase
147 : performance. */
148 :
149 : // XAccessibleComponent ---------------------------------------------------
150 :
151 : /** @return
152 : <TRUE/>, if the point lies within the bounding box of this object. */
153 : virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& rPoint )
154 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
155 :
156 : /** @return The bounding box of this object. */
157 : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds()
158 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
159 :
160 : /** @return
161 : The upper left corner of the bounding box relative to the parent. */
162 : virtual ::com::sun::star::awt::Point SAL_CALL getLocation()
163 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
164 :
165 : /** @return
166 : The upper left corner of the bounding box in screen coordinates. */
167 : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen()
168 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
169 :
170 : /** @return The size of the bounding box. */
171 : virtual ::com::sun::star::awt::Size SAL_CALL getSize()
172 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
173 :
174 : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
175 : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
176 :
177 :
178 : /* Derived classes have to implement:
179 : - getAccessibleAt,
180 : - grabFocus. */
181 :
182 : /** @return
183 : The accessible child rendered under the given point.
184 : */
185 : virtual ::com::sun::star::uno::Reference<
186 : ::com::sun::star::accessibility::XAccessible > SAL_CALL
187 : getAccessibleAtPoint( const ::com::sun::star::awt::Point& rPoint )
188 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
189 :
190 : // XAccessibleEventBroadcaster --------------------------------------------
191 :
192 : /** Adds a new event listener */
193 : virtual void SAL_CALL addAccessibleEventListener(
194 : const ::com::sun::star::uno::Reference<
195 : ::com::sun::star::accessibility::XAccessibleEventListener>& rxListener )
196 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
197 :
198 : /** Removes an event listener. */
199 : virtual void SAL_CALL removeAccessibleEventListener(
200 : const ::com::sun::star::uno::Reference<
201 : ::com::sun::star::accessibility::XAccessibleEventListener>& rxListener )
202 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
203 :
204 : // XTypeProvider ----------------------------------------------------------
205 :
206 : /** @return An unique implementation ID. */
207 : virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
208 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
209 :
210 : // XServiceInfo -----------------------------------------------------------
211 :
212 : /** @return Whether the specified service is supported by this class. */
213 : virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName )
214 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
215 :
216 : /** @return A list of all supported services. */
217 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL
218 : getSupportedServiceNames()
219 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
220 :
221 : /* Derived classes have to implement:
222 : - getImplementationName. */
223 :
224 : // helper methods ---------------------------------------------------------
225 :
226 : /** @return The GridControl object type. */
227 : inline ::svt::table::AccessibleTableControlObjType getType() const;
228 :
229 : /** Commits an event to all listeners. */
230 : void commitEvent(
231 : sal_Int16 nEventId,
232 : const ::com::sun::star::uno::Any& rNewValue,
233 :
234 : const ::com::sun::star::uno::Any& rOldValue );
235 : /** @return <TRUE/>, if the object is not disposed or disposing. */
236 : bool isAlive() const;
237 :
238 : protected:
239 : // internal virtual methods -----------------------------------------------
240 :
241 : /** Determines whether the Grid control is really showing inside of
242 : its parent accessible window. Derived classes may implement different
243 : behaviour.
244 : @attention This method requires locked mutex's and a living object.
245 : @return <TRUE/>, if the object is really showing. */
246 : bool implIsShowing();
247 :
248 : /** Derived classes return the bounding box relative to the parent window.
249 : @attention This method requires locked mutex's and a living object.
250 : @return The bounding box (VCL rect.) relative to the parent window. */
251 : virtual Rectangle implGetBoundingBox() = 0;
252 : ///** Derived classes return the bounding box in screen coordinates.
253 : // @attention This method requires locked mutex's and a living object.
254 : // @return The bounding box (VCL rect.) in screen coordinates. */
255 : virtual Rectangle implGetBoundingBoxOnScreen() = 0;
256 :
257 : /** Creates a new AccessibleStateSetHelper and fills it with states of the
258 : current object. This method calls FillStateSet at the GridControl which
259 : fills it with more states depending on the object type. Derived classes
260 : may overwrite this method and add more states.
261 : @attention This method requires locked mutex's.
262 : @return A filled AccessibleStateSetHelper. */
263 : virtual ::utl::AccessibleStateSetHelper* implCreateStateSetHelper();
264 :
265 : // internal helper methods ------------------------------------------------
266 :
267 : /** @throws <type>DisposedException</type> If the object is not alive. */
268 : void ensureIsAlive() const
269 : throw ( ::com::sun::star::lang::DisposedException );
270 :
271 : /** Changes the name of the object (flat assignment, no notify).
272 : @attention This method requires a locked mutex. */
273 : inline void implSetName( const OUString& rName );
274 : /** Changes the description of the object (flat assignment, no notify).
275 : @attention This method requires a locked mutex. */
276 : inline void implSetDescription( const OUString& rDescription );
277 :
278 : /** Locks all mutex's and calculates the bounding box relative to the
279 : parent window.
280 : @return The bounding box (VCL rect.) relative to the parent object. */
281 : Rectangle getBoundingBox()
282 : throw ( ::com::sun::star::lang::DisposedException );
283 : ///** Locks all mutex's and calculates the bounding box in screen
284 : // coordinates.
285 : // @return The bounding box (VCL rect.) in screen coordinates. */
286 : Rectangle getBoundingBoxOnScreen()
287 : throw ( ::com::sun::star::lang::DisposedException );
288 :
289 0 : ::comphelper::AccessibleEventNotifier::TClientId getClientId() const { return m_aClientId; }
290 0 : void setClientId(::comphelper::AccessibleEventNotifier::TClientId _aNewClientId) { m_aClientId = _aNewClientId; }
291 :
292 : protected:
293 : // members ----------------------------------------------------------------
294 :
295 : /** The parent accessible object. */
296 : ::com::sun::star::uno::Reference<
297 : ::com::sun::star::accessibility::XAccessible > m_xParent;
298 : /** The SVT Table control. */
299 : ::svt::table::IAccessibleTable& m_aTable;
300 : /** The type of this object (for names, descriptions, state sets, ...). */
301 : ::svt::table::AccessibleTableControlObjType m_eObjType;
302 :
303 : private:
304 : /** Localized name. */
305 : OUString m_aName;
306 : /** Localized description text. */
307 : OUString m_aDescription;
308 : ::comphelper::AccessibleEventNotifier::TClientId m_aClientId;
309 : };
310 :
311 :
312 : // a version of AccessibleGridControlBase which implements not only the XAccessibleContext,
313 : // but also the XAccessible
314 :
315 : typedef ::cppu::ImplHelper1 < ::com::sun::star::accessibility::XAccessible
316 : > GridControlAccessibleElement_Base;
317 :
318 : class GridControlAccessibleElement
319 : :public AccessibleGridControlBase
320 : ,public GridControlAccessibleElement_Base
321 : {
322 : protected:
323 : /** Constructor sets specified name and description.
324 :
325 : @param rxParent XAccessible interface of the parent object.
326 : @param rTable The Table control.
327 : @param eNameText The constant for the name text.
328 : @param eDescrText The constant for the description text.
329 : */
330 : GridControlAccessibleElement(
331 : const ::com::sun::star::uno::Reference<
332 : ::com::sun::star::accessibility::XAccessible >& rxParent,
333 : ::svt::table::IAccessibleTable& rTable,
334 : ::svt::table::AccessibleTableControlObjType eObjType );
335 :
336 : public:
337 : // XInterface
338 : DECLARE_XINTERFACE( )
339 : // XTypeProvider
340 : DECLARE_XTYPEPROVIDER( )
341 :
342 : protected:
343 : virtual ~GridControlAccessibleElement();
344 :
345 : protected:
346 : // XAccessible ------------------------------------------------------------
347 :
348 : /** @return The XAccessibleContext interface of this object. */
349 : virtual ::com::sun::star::uno::Reference<
350 : ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL
351 : getAccessibleContext()
352 : throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
353 :
354 : private:
355 : GridControlAccessibleElement( const GridControlAccessibleElement& ) SAL_DELETED_FUNCTION;
356 : GridControlAccessibleElement& operator=( const GridControlAccessibleElement& ) SAL_DELETED_FUNCTION;
357 : };
358 :
359 : // inlines --------------------------------------------------------------------
360 :
361 0 : inline ::svt::table::AccessibleTableControlObjType AccessibleGridControlBase::getType() const
362 : {
363 0 : return m_eObjType;
364 : }
365 :
366 0 : inline void AccessibleGridControlBase::implSetName(
367 : const OUString& rName )
368 : {
369 0 : m_aName = rName;
370 0 : }
371 :
372 : inline void AccessibleGridControlBase::implSetDescription(
373 : const OUString& rDescription )
374 : {
375 : m_aDescription = rDescription;
376 : }
377 :
378 :
379 :
380 : } // namespace accessibility
381 :
382 :
383 :
384 : #endif // ACCESSIBILITY_EXT_ACCESSIBILEGRIDCONTROLBASE_HXX
385 :
386 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|