Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #ifndef ACCESSIBILITY_EXT_ACCESSIBLEGRIDCONTROLBASE_HXX
31 : : #define ACCESSIBILITY_EXT_ACCESSIBLEGRIDCONTROLBASE_HXX
32 : :
33 : : #include <svtools/accessibletable.hxx>
34 : : #include <rtl/ustring.hxx>
35 : : #include <tools/gen.hxx>
36 : : #include <vcl/svapp.hxx>
37 : : #include <cppuhelper/compbase4.hxx>
38 : : #include <comphelper/broadcasthelper.hxx>
39 : : #include <unotools/accessiblestatesethelper.hxx>
40 : : #include <toolkit/helper/convert.hxx>
41 : : #include <com/sun/star/lang/XServiceInfo.hpp>
42 : : #include <com/sun/star/lang/DisposedException.hpp>
43 : : #include <com/sun/star/awt/XWindow.hpp>
44 : : #include <com/sun/star/accessibility/XAccessible.hpp>
45 : : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
46 : : #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
47 : : #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
48 : : #include <com/sun/star/accessibility/AccessibleRole.hpp>
49 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
50 : : #include <com/sun/star/awt/XFocusListener.hpp>
51 : : #include <comphelper/accessibleeventnotifier.hxx>
52 : : #include <comphelper/uno3.hxx>
53 : :
54 : : // ============================================================================
55 : :
56 : : class Window;
57 : :
58 : : namespace utl {
59 : : class AccessibleStateSetHelper;
60 : : }
61 : :
62 : : // ============================================================================
63 : :
64 : : namespace accessibility {
65 : :
66 : : // ============================================================================
67 : :
68 : : // ============================================================================
69 : :
70 : : typedef ::cppu::WeakAggComponentImplHelper4<
71 : : ::com::sun::star::accessibility::XAccessibleContext,
72 : : ::com::sun::star::accessibility::XAccessibleComponent,
73 : : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
74 : : ::com::sun::star::lang::XServiceInfo >
75 : : AccessibleGridControlImplHelper;
76 : :
77 : : /** The GridControl accessible objects inherit from this base class. It
78 : : implements basic functionality for various Accessibility interfaces and
79 : : the event broadcaster and contains the ::osl::Mutex. */
80 : : class AccessibleGridControlBase :
81 : : public ::comphelper::OBaseMutex,
82 : : public AccessibleGridControlImplHelper
83 : : {
84 : : public:
85 : : /** Constructor sets specified name and description.
86 : : @param rxParent XAccessible interface of the parent object.
87 : : @param rTable The Table control.
88 : : @param eNameText The constant for the name text.
89 : : @param eDescrText The constant for the description text. */
90 : : AccessibleGridControlBase(
91 : : const ::com::sun::star::uno::Reference<
92 : : ::com::sun::star::accessibility::XAccessible >& rxParent,
93 : : ::svt::table::IAccessibleTable& rTable,
94 : : ::svt::table::AccessibleTableControlObjType eObjType );
95 : :
96 : : protected:
97 : : virtual ~AccessibleGridControlBase();
98 : :
99 : : /** Commits DeFunc event to listeners and cleans up members. */
100 : : virtual void SAL_CALL disposing();
101 : :
102 : : public:
103 : : // XAccessibleContext -----------------------------------------------------
104 : :
105 : : /** @return A reference to the parent accessible object. */
106 : : virtual ::com::sun::star::uno::Reference<
107 : : ::com::sun::star::accessibility::XAccessible > SAL_CALL
108 : : getAccessibleParent()
109 : : throw ( ::com::sun::star::uno::RuntimeException );
110 : :
111 : : /** @return The index of this object among the parent's children. */
112 : : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent()
113 : : throw ( ::com::sun::star::uno::RuntimeException );
114 : :
115 : : /** @return
116 : : The description of this object.
117 : : */
118 : : virtual ::rtl::OUString SAL_CALL getAccessibleDescription()
119 : : throw ( ::com::sun::star::uno::RuntimeException );
120 : :
121 : : /** @return
122 : : The name of this object.
123 : : */
124 : : virtual ::rtl::OUString SAL_CALL getAccessibleName()
125 : : throw ( ::com::sun::star::uno::RuntimeException );
126 : :
127 : : /** @return
128 : : The relation set (the GridControl does not have one).
129 : : */
130 : : virtual ::com::sun::star::uno::Reference<
131 : : ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL
132 : : getAccessibleRelationSet()
133 : : throw ( ::com::sun::star::uno::RuntimeException );
134 : :
135 : : /** @return The set of current states. */
136 : : virtual ::com::sun::star::uno::Reference<
137 : : ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL
138 : : getAccessibleStateSet()
139 : : throw ( ::com::sun::star::uno::RuntimeException );
140 : :
141 : : /** @return The parent's locale. */
142 : : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale()
143 : : throw ( ::com::sun::star::accessibility::IllegalAccessibleComponentStateException,
144 : : ::com::sun::star::uno::RuntimeException );
145 : :
146 : : /** @return
147 : : The role of this object. Panel, ROWHEADER, COLUMNHEADER, TABLE, TABLE_CELL are supported.
148 : : */
149 : : virtual sal_Int16 SAL_CALL getAccessibleRole()
150 : : throw ( ::com::sun::star::uno::RuntimeException );
151 : :
152 : : /* Derived classes have to implement:
153 : : - getAccessibleChildCount,
154 : : - getAccessibleChild,
155 : : - getAccessibleRole.
156 : : Derived classes may overwrite getAccessibleIndexInParent to increase
157 : : performance. */
158 : :
159 : : // XAccessibleComponent ---------------------------------------------------
160 : :
161 : : /** @return
162 : : <TRUE/>, if the point lies within the bounding box of this object. */
163 : : virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& rPoint )
164 : : throw ( ::com::sun::star::uno::RuntimeException );
165 : :
166 : : /** @return The bounding box of this object. */
167 : : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds()
168 : : throw ( ::com::sun::star::uno::RuntimeException );
169 : :
170 : : /** @return
171 : : The upper left corner of the bounding box relative to the parent. */
172 : : virtual ::com::sun::star::awt::Point SAL_CALL getLocation()
173 : : throw ( ::com::sun::star::uno::RuntimeException );
174 : :
175 : : /** @return
176 : : The upper left corner of the bounding box in screen coordinates. */
177 : : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen()
178 : : throw ( ::com::sun::star::uno::RuntimeException );
179 : :
180 : : /** @return The size of the bounding box. */
181 : : virtual ::com::sun::star::awt::Size SAL_CALL getSize()
182 : : throw ( ::com::sun::star::uno::RuntimeException );
183 : :
184 : : /** @return <TRUE/>, if the object is showing. */
185 : : virtual sal_Bool SAL_CALL isShowing()
186 : : throw ( ::com::sun::star::uno::RuntimeException );
187 : :
188 : : /** @return <TRUE/>, if the object is visible. */
189 : : virtual sal_Bool SAL_CALL isVisible()
190 : : throw ( ::com::sun::star::uno::RuntimeException );
191 : :
192 : : /** @return <TRUE/>, if the object can accept the focus. */
193 : : virtual sal_Bool SAL_CALL isFocusTraversable()
194 : : throw ( ::com::sun::star::uno::RuntimeException );
195 : :
196 : : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException);
197 : : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException);
198 : :
199 : :
200 : : /* Derived classes have to implement:
201 : : - getAccessibleAt,
202 : : - grabFocus,
203 : : - getAccessibleKeyBinding. */
204 : :
205 : : /** @return
206 : : No key bindings supported by default.
207 : : */
208 : : virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding()
209 : : throw ( ::com::sun::star::uno::RuntimeException );
210 : : /** @return
211 : : The accessible child rendered under the given point.
212 : : */
213 : : virtual ::com::sun::star::uno::Reference<
214 : : ::com::sun::star::accessibility::XAccessible > SAL_CALL
215 : : getAccessibleAtPoint( const ::com::sun::star::awt::Point& rPoint )
216 : : throw ( ::com::sun::star::uno::RuntimeException );
217 : :
218 : : // XAccessibleEventBroadcaster --------------------------------------------
219 : :
220 : : /** Adds a new event listener */
221 : : using cppu::WeakAggComponentImplHelperBase::addEventListener;
222 : : virtual void SAL_CALL addEventListener(
223 : : const ::com::sun::star::uno::Reference<
224 : : ::com::sun::star::accessibility::XAccessibleEventListener>& rxListener )
225 : : throw ( ::com::sun::star::uno::RuntimeException );
226 : :
227 : : /** Removes an event listener. */
228 : : using cppu::WeakAggComponentImplHelperBase::removeEventListener;
229 : : virtual void SAL_CALL removeEventListener(
230 : : const ::com::sun::star::uno::Reference<
231 : : ::com::sun::star::accessibility::XAccessibleEventListener>& rxListener )
232 : : throw ( ::com::sun::star::uno::RuntimeException );
233 : :
234 : : // XTypeProvider ----------------------------------------------------------
235 : :
236 : : /** @return An unique implementation ID. */
237 : : virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
238 : : throw ( ::com::sun::star::uno::RuntimeException );
239 : :
240 : : // XServiceInfo -----------------------------------------------------------
241 : :
242 : : /** @return Whether the specified service is supported by this class. */
243 : : virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& rServiceName )
244 : : throw ( ::com::sun::star::uno::RuntimeException );
245 : :
246 : : /** @return A list of all supported services. */
247 : : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
248 : : getSupportedServiceNames()
249 : : throw ( ::com::sun::star::uno::RuntimeException );
250 : :
251 : : /* Derived classes have to implement:
252 : : - getImplementationName. */
253 : :
254 : : // helper methods ---------------------------------------------------------
255 : :
256 : : /** @return The GridControl object type. */
257 : : inline ::svt::table::AccessibleTableControlObjType getType() const;
258 : :
259 : : /** Commits an event to all listeners. */
260 : : void commitEvent(
261 : : sal_Int16 nEventId,
262 : : const ::com::sun::star::uno::Any& rNewValue,
263 : :
264 : : const ::com::sun::star::uno::Any& rOldValue );
265 : : /** @return <TRUE/>, if the object is not disposed or disposing. */
266 : : sal_Bool isAlive() const;
267 : :
268 : : protected:
269 : : // internal virtual methods -----------------------------------------------
270 : :
271 : : /** Determines whether the Grid control is really showing inside of
272 : : its parent accessible window. Derived classes may implement different
273 : : behaviour.
274 : : @attention This method requires locked mutex's and a living object.
275 : : @return <TRUE/>, if the object is really showing. */
276 : : virtual sal_Bool implIsShowing();
277 : :
278 : : /** Derived classes return the bounding box relative to the parent window.
279 : : @attention This method requires locked mutex's and a living object.
280 : : @return The bounding box (VCL rect.) relative to the parent window. */
281 : : virtual Rectangle implGetBoundingBox() = 0;
282 : : ///** Derived classes return the bounding box in screen coordinates.
283 : : // @attention This method requires locked mutex's and a living object.
284 : : // @return The bounding box (VCL rect.) in screen coordinates. */
285 : : virtual Rectangle implGetBoundingBoxOnScreen() = 0;
286 : :
287 : : /** Creates a new AccessibleStateSetHelper and fills it with states of the
288 : : current object. This method calls FillStateSet at the GridControl which
289 : : fills it with more states depending on the object type. Derived classes
290 : : may overwrite this method and add more states.
291 : : @attention This method requires locked mutex's.
292 : : @return A filled AccessibleStateSetHelper. */
293 : : virtual ::utl::AccessibleStateSetHelper* implCreateStateSetHelper();
294 : :
295 : : // internal helper methods ------------------------------------------------
296 : :
297 : : /** @throws <type>DisposedException</type> If the object is not alive. */
298 : : void ensureIsAlive() const
299 : : throw ( ::com::sun::star::lang::DisposedException );
300 : :
301 : : /** @return The ::osl::Mutex member provided by the class OBaseMutex. */
302 : : inline ::osl::Mutex& getOslMutex();
303 : : /** @return Pointer to the global ::osl::Mutex. */
304 : : static inline ::osl::Mutex* getOslGlobalMutex();
305 : :
306 : : /** Changes the name of the object (flat assignment, no notify).
307 : : @attention This method requires a locked mutex. */
308 : : inline void implSetName( const ::rtl::OUString& rName );
309 : : /** Changes the description of the object (flat assignment, no notify).
310 : : @attention This method requires a locked mutex. */
311 : : inline void implSetDescription( const ::rtl::OUString& rDescription );
312 : :
313 : : /** Locks all mutex's and calculates the bounding box relative to the
314 : : parent window.
315 : : @return The bounding box (VCL rect.) relative to the parent object. */
316 : : Rectangle getBoundingBox()
317 : : throw ( ::com::sun::star::lang::DisposedException );
318 : : ///** Locks all mutex's and calculates the bounding box in screen
319 : : // coordinates.
320 : : // @return The bounding box (VCL rect.) in screen coordinates. */
321 : : Rectangle getBoundingBoxOnScreen()
322 : : throw ( ::com::sun::star::lang::DisposedException );
323 : :
324 : 0 : ::comphelper::AccessibleEventNotifier::TClientId getClientId() const { return m_aClientId; }
325 : 0 : void setClientId(::comphelper::AccessibleEventNotifier::TClientId _aNewClientId) { m_aClientId = _aNewClientId; }
326 : :
327 : : public:
328 : : // public versions of internal helper methods, with access control
329 : : struct TC_AccessControl { friend class TC_SolarMethodGuard; private: TC_AccessControl() { } };
330 : :
331 : : inline ::osl::Mutex& getMutex( const TC_AccessControl& ) { return getOslMutex(); }
332 : : inline void ensureIsAlive( const TC_AccessControl& ) { ensureIsAlive(); }
333 : :
334 : : protected:
335 : : // members ----------------------------------------------------------------
336 : :
337 : : /** The parent accessible object. */
338 : : ::com::sun::star::uno::Reference<
339 : : ::com::sun::star::accessibility::XAccessible > m_xParent;
340 : : /** The SVT Table control. */
341 : : ::svt::table::IAccessibleTable& m_aTable;
342 : : /** The type of this object (for names, descriptions, state sets, ...). */
343 : : ::svt::table::AccessibleTableControlObjType m_eObjType;
344 : :
345 : : private:
346 : : /** Localized name. */
347 : : ::rtl::OUString m_aName;
348 : : /** Localized description text. */
349 : : ::rtl::OUString m_aDescription;
350 : : ::comphelper::AccessibleEventNotifier::TClientId m_aClientId;
351 : : };
352 : :
353 : : // ============================================================================
354 : : // a version of AccessibleGridControlBase which implements not only the XAccessibleContext,
355 : : // but also the XAccessible
356 : :
357 : : typedef ::cppu::ImplHelper1 < ::com::sun::star::accessibility::XAccessible
358 : : > GridControlAccessibleElement_Base;
359 : :
360 : : class GridControlAccessibleElement
361 : : :public AccessibleGridControlBase
362 : : ,public GridControlAccessibleElement_Base
363 : : {
364 : : protected:
365 : : /** Constructor sets specified name and description.
366 : :
367 : : @param rxParent XAccessible interface of the parent object.
368 : : @param rTable The Table control.
369 : : @param eNameText The constant for the name text.
370 : : @param eDescrText The constant for the description text.
371 : : */
372 : : GridControlAccessibleElement(
373 : : const ::com::sun::star::uno::Reference<
374 : : ::com::sun::star::accessibility::XAccessible >& rxParent,
375 : : ::svt::table::IAccessibleTable& rTable,
376 : : ::svt::table::AccessibleTableControlObjType eObjType );
377 : :
378 : : public:
379 : : // XInterface
380 : : DECLARE_XINTERFACE( )
381 : : // XTypeProvider
382 : : DECLARE_XTYPEPROVIDER( )
383 : :
384 : : protected:
385 : : virtual ~GridControlAccessibleElement();
386 : :
387 : : protected:
388 : : // XAccessible ------------------------------------------------------------
389 : :
390 : : /** @return The XAccessibleContext interface of this object. */
391 : : virtual ::com::sun::star::uno::Reference<
392 : : ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL
393 : : getAccessibleContext()
394 : : throw ( ::com::sun::star::uno::RuntimeException );
395 : :
396 : : private:
397 : : GridControlAccessibleElement(); // never implemented
398 : : GridControlAccessibleElement( const GridControlAccessibleElement& ); // never implemented
399 : : GridControlAccessibleElement& operator=( const GridControlAccessibleElement& ); // never implemented
400 : : };
401 : :
402 : : // ============================================================================
403 : : // a helper class for protecting methods which need to lock the solar mutex in addition to the own mutex
404 : :
405 : : typedef ::osl::MutexGuard OslMutexGuard;
406 : :
407 : : class TC_SolarMethodGuard : public SolarMutexGuard, public OslMutexGuard
408 : : {
409 : : public:
410 : : inline TC_SolarMethodGuard( AccessibleGridControlBase& _rOwner, bool _bEnsureAlive = true )
411 : : : SolarMutexGuard(),
412 : : OslMutexGuard( _rOwner.getMutex( AccessibleGridControlBase::TC_AccessControl() ) )
413 : : {
414 : : if ( _bEnsureAlive )
415 : : _rOwner.ensureIsAlive( AccessibleGridControlBase::TC_AccessControl() );
416 : : }
417 : : };
418 : :
419 : : // inlines --------------------------------------------------------------------
420 : :
421 : 0 : inline ::svt::table::AccessibleTableControlObjType AccessibleGridControlBase::getType() const
422 : : {
423 : 0 : return m_eObjType;
424 : : }
425 : :
426 : 0 : inline ::osl::Mutex& AccessibleGridControlBase::getOslMutex()
427 : : {
428 : 0 : return m_aMutex;
429 : : }
430 : :
431 : : inline ::osl::Mutex* AccessibleGridControlBase::getOslGlobalMutex()
432 : : {
433 : : return ::osl::Mutex::getGlobalMutex();
434 : : }
435 : :
436 : 0 : inline void AccessibleGridControlBase::implSetName(
437 : : const ::rtl::OUString& rName )
438 : : {
439 : 0 : m_aName = rName;
440 : 0 : }
441 : :
442 : : inline void AccessibleGridControlBase::implSetDescription(
443 : : const ::rtl::OUString& rDescription )
444 : : {
445 : : m_aDescription = rDescription;
446 : : }
447 : :
448 : : // ============================================================================
449 : :
450 : : } // namespace accessibility
451 : :
452 : : // ============================================================================
453 : :
454 : : #endif // ACCESSIBILITY_EXT_ACCESSIBILEGRIDCONTROLBASE_HXX
455 : :
456 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|