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 ACCESSIBILITY_EXT_ACCESSIBLEGRIDCONTROLBASE_HXX
22 : #define ACCESSIBILITY_EXT_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 : 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();
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 );
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 );
104 :
105 : /** @return
106 : The description of this object.
107 : */
108 : virtual OUString SAL_CALL getAccessibleDescription()
109 : throw ( ::com::sun::star::uno::RuntimeException );
110 :
111 : /** @return
112 : The name of this object.
113 : */
114 : virtual OUString SAL_CALL getAccessibleName()
115 : throw ( ::com::sun::star::uno::RuntimeException );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
173 :
174 : /** @return <TRUE/>, if the object is showing. */
175 : virtual sal_Bool SAL_CALL isShowing()
176 : throw ( ::com::sun::star::uno::RuntimeException );
177 :
178 : /** @return <TRUE/>, if the object is visible. */
179 : virtual sal_Bool SAL_CALL isVisible()
180 : throw ( ::com::sun::star::uno::RuntimeException );
181 :
182 : /** @return <TRUE/>, if the object can accept the focus. */
183 : virtual sal_Bool SAL_CALL isFocusTraversable()
184 : throw ( ::com::sun::star::uno::RuntimeException );
185 :
186 : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException);
187 : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException);
188 :
189 :
190 : /* Derived classes have to implement:
191 : - getAccessibleAt,
192 : - grabFocus,
193 : - getAccessibleKeyBinding. */
194 :
195 : /** @return
196 : No key bindings supported by default.
197 : */
198 : virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding()
199 : throw ( ::com::sun::star::uno::RuntimeException );
200 : /** @return
201 : The accessible child rendered under the given point.
202 : */
203 : virtual ::com::sun::star::uno::Reference<
204 : ::com::sun::star::accessibility::XAccessible > SAL_CALL
205 : getAccessibleAtPoint( const ::com::sun::star::awt::Point& rPoint )
206 : throw ( ::com::sun::star::uno::RuntimeException );
207 :
208 : // XAccessibleEventBroadcaster --------------------------------------------
209 :
210 : /** Adds a new event listener */
211 : virtual void SAL_CALL addAccessibleEventListener(
212 : const ::com::sun::star::uno::Reference<
213 : ::com::sun::star::accessibility::XAccessibleEventListener>& rxListener )
214 : throw ( ::com::sun::star::uno::RuntimeException );
215 :
216 : /** Removes an event listener. */
217 : virtual void SAL_CALL removeAccessibleEventListener(
218 : const ::com::sun::star::uno::Reference<
219 : ::com::sun::star::accessibility::XAccessibleEventListener>& rxListener )
220 : throw ( ::com::sun::star::uno::RuntimeException );
221 :
222 : // XTypeProvider ----------------------------------------------------------
223 :
224 : /** @return An unique implementation ID. */
225 : virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
226 : throw ( ::com::sun::star::uno::RuntimeException );
227 :
228 : // XServiceInfo -----------------------------------------------------------
229 :
230 : /** @return Whether the specified service is supported by this class. */
231 : virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName )
232 : throw ( ::com::sun::star::uno::RuntimeException );
233 :
234 : /** @return A list of all supported services. */
235 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL
236 : getSupportedServiceNames()
237 : throw ( ::com::sun::star::uno::RuntimeException );
238 :
239 : /* Derived classes have to implement:
240 : - getImplementationName. */
241 :
242 : // helper methods ---------------------------------------------------------
243 :
244 : /** @return The GridControl object type. */
245 : inline ::svt::table::AccessibleTableControlObjType getType() const;
246 :
247 : /** Commits an event to all listeners. */
248 : void commitEvent(
249 : sal_Int16 nEventId,
250 : const ::com::sun::star::uno::Any& rNewValue,
251 :
252 : const ::com::sun::star::uno::Any& rOldValue );
253 : /** @return <TRUE/>, if the object is not disposed or disposing. */
254 : sal_Bool isAlive() const;
255 :
256 : protected:
257 : // internal virtual methods -----------------------------------------------
258 :
259 : /** Determines whether the Grid control is really showing inside of
260 : its parent accessible window. Derived classes may implement different
261 : behaviour.
262 : @attention This method requires locked mutex's and a living object.
263 : @return <TRUE/>, if the object is really showing. */
264 : virtual sal_Bool implIsShowing();
265 :
266 : /** Derived classes return the bounding box relative to the parent window.
267 : @attention This method requires locked mutex's and a living object.
268 : @return The bounding box (VCL rect.) relative to the parent window. */
269 : virtual Rectangle implGetBoundingBox() = 0;
270 : ///** Derived classes return the bounding box in screen coordinates.
271 : // @attention This method requires locked mutex's and a living object.
272 : // @return The bounding box (VCL rect.) in screen coordinates. */
273 : virtual Rectangle implGetBoundingBoxOnScreen() = 0;
274 :
275 : /** Creates a new AccessibleStateSetHelper and fills it with states of the
276 : current object. This method calls FillStateSet at the GridControl which
277 : fills it with more states depending on the object type. Derived classes
278 : may overwrite this method and add more states.
279 : @attention This method requires locked mutex's.
280 : @return A filled AccessibleStateSetHelper. */
281 : virtual ::utl::AccessibleStateSetHelper* implCreateStateSetHelper();
282 :
283 : // internal helper methods ------------------------------------------------
284 :
285 : /** @throws <type>DisposedException</type> If the object is not alive. */
286 : void ensureIsAlive() const
287 : throw ( ::com::sun::star::lang::DisposedException );
288 :
289 : /** @return The ::osl::Mutex member provided by the class OBaseMutex. */
290 : inline ::osl::Mutex& getOslMutex();
291 : /** @return Pointer to the global ::osl::Mutex. */
292 : static inline ::osl::Mutex* getOslGlobalMutex();
293 :
294 : /** Changes the name of the object (flat assignment, no notify).
295 : @attention This method requires a locked mutex. */
296 : inline void implSetName( const OUString& rName );
297 : /** Changes the description of the object (flat assignment, no notify).
298 : @attention This method requires a locked mutex. */
299 : inline void implSetDescription( const OUString& rDescription );
300 :
301 : /** Locks all mutex's and calculates the bounding box relative to the
302 : parent window.
303 : @return The bounding box (VCL rect.) relative to the parent object. */
304 : Rectangle getBoundingBox()
305 : throw ( ::com::sun::star::lang::DisposedException );
306 : ///** Locks all mutex's and calculates the bounding box in screen
307 : // coordinates.
308 : // @return The bounding box (VCL rect.) in screen coordinates. */
309 : Rectangle getBoundingBoxOnScreen()
310 : throw ( ::com::sun::star::lang::DisposedException );
311 :
312 0 : ::comphelper::AccessibleEventNotifier::TClientId getClientId() const { return m_aClientId; }
313 0 : void setClientId(::comphelper::AccessibleEventNotifier::TClientId _aNewClientId) { m_aClientId = _aNewClientId; }
314 :
315 : public:
316 : // public versions of internal helper methods, with access control
317 : struct TC_AccessControl { friend class TC_SolarMethodGuard; private: TC_AccessControl() { } };
318 :
319 : inline ::osl::Mutex& getMutex( const TC_AccessControl& ) { return getOslMutex(); }
320 : inline void ensureIsAlive( const TC_AccessControl& ) { ensureIsAlive(); }
321 :
322 : protected:
323 : // members ----------------------------------------------------------------
324 :
325 : /** The parent accessible object. */
326 : ::com::sun::star::uno::Reference<
327 : ::com::sun::star::accessibility::XAccessible > m_xParent;
328 : /** The SVT Table control. */
329 : ::svt::table::IAccessibleTable& m_aTable;
330 : /** The type of this object (for names, descriptions, state sets, ...). */
331 : ::svt::table::AccessibleTableControlObjType m_eObjType;
332 :
333 : private:
334 : /** Localized name. */
335 : OUString m_aName;
336 : /** Localized description text. */
337 : OUString m_aDescription;
338 : ::comphelper::AccessibleEventNotifier::TClientId m_aClientId;
339 : };
340 :
341 : // ============================================================================
342 : // a version of AccessibleGridControlBase which implements not only the XAccessibleContext,
343 : // but also the XAccessible
344 :
345 : typedef ::cppu::ImplHelper1 < ::com::sun::star::accessibility::XAccessible
346 : > GridControlAccessibleElement_Base;
347 :
348 : class GridControlAccessibleElement
349 : :public AccessibleGridControlBase
350 : ,public GridControlAccessibleElement_Base
351 : {
352 : protected:
353 : /** Constructor sets specified name and description.
354 :
355 : @param rxParent XAccessible interface of the parent object.
356 : @param rTable The Table control.
357 : @param eNameText The constant for the name text.
358 : @param eDescrText The constant for the description text.
359 : */
360 : GridControlAccessibleElement(
361 : const ::com::sun::star::uno::Reference<
362 : ::com::sun::star::accessibility::XAccessible >& rxParent,
363 : ::svt::table::IAccessibleTable& rTable,
364 : ::svt::table::AccessibleTableControlObjType eObjType );
365 :
366 : public:
367 : // XInterface
368 : DECLARE_XINTERFACE( )
369 : // XTypeProvider
370 : DECLARE_XTYPEPROVIDER( )
371 :
372 : protected:
373 : virtual ~GridControlAccessibleElement();
374 :
375 : protected:
376 : // XAccessible ------------------------------------------------------------
377 :
378 : /** @return The XAccessibleContext interface of this object. */
379 : virtual ::com::sun::star::uno::Reference<
380 : ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL
381 : getAccessibleContext()
382 : throw ( ::com::sun::star::uno::RuntimeException );
383 :
384 : private:
385 : GridControlAccessibleElement(); // never implemented
386 : GridControlAccessibleElement( const GridControlAccessibleElement& ); // never implemented
387 : GridControlAccessibleElement& operator=( const GridControlAccessibleElement& ); // never implemented
388 : };
389 :
390 : // ============================================================================
391 : // a helper class for protecting methods which need to lock the solar mutex in addition to the own mutex
392 :
393 : typedef ::osl::MutexGuard OslMutexGuard;
394 :
395 : class TC_SolarMethodGuard : public SolarMutexGuard, public OslMutexGuard
396 : {
397 : public:
398 : inline TC_SolarMethodGuard( AccessibleGridControlBase& _rOwner, bool _bEnsureAlive = true )
399 : : SolarMutexGuard(),
400 : OslMutexGuard( _rOwner.getMutex( AccessibleGridControlBase::TC_AccessControl() ) )
401 : {
402 : if ( _bEnsureAlive )
403 : _rOwner.ensureIsAlive( AccessibleGridControlBase::TC_AccessControl() );
404 : }
405 : };
406 :
407 : // inlines --------------------------------------------------------------------
408 :
409 0 : inline ::svt::table::AccessibleTableControlObjType AccessibleGridControlBase::getType() const
410 : {
411 0 : return m_eObjType;
412 : }
413 :
414 0 : inline ::osl::Mutex& AccessibleGridControlBase::getOslMutex()
415 : {
416 0 : return m_aMutex;
417 : }
418 :
419 : inline ::osl::Mutex* AccessibleGridControlBase::getOslGlobalMutex()
420 : {
421 : return ::osl::Mutex::getGlobalMutex();
422 : }
423 :
424 0 : inline void AccessibleGridControlBase::implSetName(
425 : const OUString& rName )
426 : {
427 0 : m_aName = rName;
428 0 : }
429 :
430 : inline void AccessibleGridControlBase::implSetDescription(
431 : const OUString& rDescription )
432 : {
433 : m_aDescription = rDescription;
434 : }
435 :
436 : // ============================================================================
437 :
438 : } // namespace accessibility
439 :
440 : // ============================================================================
441 :
442 : #endif // ACCESSIBILITY_EXT_ACCESSIBILEGRIDCONTROLBASE_HXX
443 :
444 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|