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_ACCESSIBLEBROWSEBOXBASE_HXX
22 : #define ACCESSIBILITY_EXT_ACCESSIBLEBROWSEBOXBASE_HXX
23 :
24 : #include <svtools/AccessibleBrowseBoxObjType.hxx>
25 : #include <rtl/ustring.hxx>
26 : #include <tools/gen.hxx>
27 : #include <vcl/svapp.hxx>
28 : #include <cppuhelper/compbase5.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 <com/sun/star/awt/XFocusListener.hpp>
42 : #include <comphelper/accessibleeventnotifier.hxx>
43 : #include <comphelper/uno3.hxx>
44 :
45 : // ============================================================================
46 :
47 : class Window;
48 :
49 : namespace utl {
50 : class AccessibleStateSetHelper;
51 : }
52 :
53 : namespace svt {
54 : class IAccessibleTableProvider;
55 : }
56 :
57 : // ============================================================================
58 :
59 : namespace accessibility {
60 :
61 : // ============================================================================
62 :
63 : typedef ::cppu::WeakAggComponentImplHelper5<
64 : ::com::sun::star::accessibility::XAccessibleContext,
65 : ::com::sun::star::accessibility::XAccessibleComponent,
66 : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
67 : ::com::sun::star::awt::XFocusListener,
68 : ::com::sun::star::lang::XServiceInfo >
69 : AccessibleBrowseBoxImplHelper;
70 :
71 : /** The BrowseBox accessible objects inherit from this base class. It
72 : implements basic functionality for various Accessibility interfaces and
73 : the event broadcaster and contains the ::osl::Mutex. */
74 : class AccessibleBrowseBoxBase :
75 : public ::comphelper::OBaseMutex,
76 : public AccessibleBrowseBoxImplHelper
77 : {
78 : public:
79 : /** Constructor sets specified name and description. If the constant of a
80 : text is BBTEXT_NONE, the derived class has to set the text via
81 : implSetName() and implSetDescription() (in Ctor) or later via
82 : setAccessibleName() and setAccessibleDescription() (these methods
83 : notify the listeners about the change).
84 : @param rxParent XAccessible interface of the parent object.
85 : @param rBrowseBox The BrowseBox control.
86 : @param eNameText The constant for the name text.
87 : @param eDescrText The constant for the description text. */
88 : AccessibleBrowseBoxBase(
89 : const ::com::sun::star::uno::Reference<
90 : ::com::sun::star::accessibility::XAccessible >& rxParent,
91 : ::svt::IAccessibleTableProvider& rBrowseBox,
92 : const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& _xFocusWindow,
93 : ::svt::AccessibleBrowseBoxObjType eObjType );
94 :
95 : /** Constructor sets specified name and description.
96 : @param rxParent XAccessible interface of the parent object.
97 : @param rBrowseBox The BrowseBox control.
98 : @param rName The name of this object.
99 : @param rDescription The description text of this object. */
100 : AccessibleBrowseBoxBase(
101 : const ::com::sun::star::uno::Reference<
102 : ::com::sun::star::accessibility::XAccessible >& rxParent,
103 : ::svt::IAccessibleTableProvider& rBrowseBox,
104 : const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& _xFocusWindow,
105 : ::svt::AccessibleBrowseBoxObjType eObjType,
106 : const OUString& rName,
107 : const OUString& rDescription );
108 :
109 : protected:
110 : virtual ~AccessibleBrowseBoxBase();
111 :
112 : /** Commits DeFunc event to listeners and cleans up members. */
113 : virtual void SAL_CALL disposing();
114 :
115 : public:
116 : // XAccessibleContext -----------------------------------------------------
117 :
118 : /** @return A reference to the parent accessible object. */
119 : virtual ::com::sun::star::uno::Reference<
120 : ::com::sun::star::accessibility::XAccessible > SAL_CALL
121 : getAccessibleParent()
122 : throw ( ::com::sun::star::uno::RuntimeException );
123 :
124 : /** @return The index of this object among the parent's children. */
125 : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent()
126 : throw ( ::com::sun::star::uno::RuntimeException );
127 :
128 : /** @return
129 : The description of this object.
130 : */
131 : virtual OUString SAL_CALL getAccessibleDescription()
132 : throw ( ::com::sun::star::uno::RuntimeException );
133 :
134 : /** @return
135 : The name of this object.
136 : */
137 : virtual OUString SAL_CALL getAccessibleName()
138 : throw ( ::com::sun::star::uno::RuntimeException );
139 :
140 : /** @return
141 : The relation set (the BrowseBox does not have one).
142 : */
143 : virtual ::com::sun::star::uno::Reference<
144 : ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL
145 : getAccessibleRelationSet()
146 : throw ( ::com::sun::star::uno::RuntimeException );
147 :
148 : /** @return The set of current states. */
149 : virtual ::com::sun::star::uno::Reference<
150 : ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL
151 : getAccessibleStateSet()
152 : throw ( ::com::sun::star::uno::RuntimeException );
153 :
154 : /** @return The parent's locale. */
155 : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale()
156 : throw ( ::com::sun::star::accessibility::IllegalAccessibleComponentStateException,
157 : ::com::sun::star::uno::RuntimeException );
158 :
159 : /** @return
160 : The role of this object. Panel, ROWHEADER, COLUMNHEADER, TABLE, TABLE_CELL are supported.
161 : */
162 : virtual sal_Int16 SAL_CALL getAccessibleRole()
163 : throw ( ::com::sun::star::uno::RuntimeException );
164 :
165 : /* Derived classes have to implement:
166 : - getAccessibleChildCount,
167 : - getAccessibleChild,
168 : - getAccessibleRole.
169 : Derived classes may overwrite getAccessibleIndexInParent to increase
170 : performance. */
171 :
172 : // XAccessibleComponent ---------------------------------------------------
173 :
174 : /** @return
175 : <TRUE/>, if the point lies within the bounding box of this object. */
176 : virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& rPoint )
177 : throw ( ::com::sun::star::uno::RuntimeException );
178 :
179 : /** @return The bounding box of this object. */
180 : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds()
181 : throw ( ::com::sun::star::uno::RuntimeException );
182 :
183 : /** @return
184 : The upper left corner of the bounding box relative to the parent. */
185 : virtual ::com::sun::star::awt::Point SAL_CALL getLocation()
186 : throw ( ::com::sun::star::uno::RuntimeException );
187 :
188 : /** @return
189 : The upper left corner of the bounding box in screen coordinates. */
190 : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen()
191 : throw ( ::com::sun::star::uno::RuntimeException );
192 :
193 : /** @return The size of the bounding box. */
194 : virtual ::com::sun::star::awt::Size SAL_CALL getSize()
195 : throw ( ::com::sun::star::uno::RuntimeException );
196 :
197 : /** @return <TRUE/>, if the object is showing. */
198 : virtual sal_Bool SAL_CALL isShowing()
199 : throw ( ::com::sun::star::uno::RuntimeException );
200 :
201 : /** @return <TRUE/>, if the object is visible. */
202 : virtual sal_Bool SAL_CALL isVisible()
203 : throw ( ::com::sun::star::uno::RuntimeException );
204 :
205 : /** @return <TRUE/>, if the object can accept the focus. */
206 : virtual sal_Bool SAL_CALL isFocusTraversable()
207 : throw ( ::com::sun::star::uno::RuntimeException );
208 :
209 : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException);
210 : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException);
211 :
212 : // XFocusListener
213 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
214 : virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent& e ) throw (::com::sun::star::uno::RuntimeException);
215 : virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent& e ) throw (::com::sun::star::uno::RuntimeException);
216 :
217 : /* Derived classes have to implement:
218 : - getAccessibleAt,
219 : - grabFocus,
220 : - getAccessibleKeyBinding. */
221 :
222 : /** @return
223 : No key bindings supported by default.
224 : */
225 : virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding()
226 : throw ( ::com::sun::star::uno::RuntimeException );
227 : /** @return
228 : The accessible child rendered under the given point.
229 : */
230 : virtual ::com::sun::star::uno::Reference<
231 : ::com::sun::star::accessibility::XAccessible > SAL_CALL
232 : getAccessibleAtPoint( const ::com::sun::star::awt::Point& rPoint )
233 : throw ( ::com::sun::star::uno::RuntimeException );
234 :
235 : // XAccessibleEventBroadcaster --------------------------------------------
236 :
237 : /** Adds a new event listener */
238 : virtual void SAL_CALL addAccessibleEventListener(
239 : const ::com::sun::star::uno::Reference<
240 : ::com::sun::star::accessibility::XAccessibleEventListener>& rxListener )
241 : throw ( ::com::sun::star::uno::RuntimeException );
242 :
243 : /** Removes an event listener. */
244 : virtual void SAL_CALL removeAccessibleEventListener(
245 : const ::com::sun::star::uno::Reference<
246 : ::com::sun::star::accessibility::XAccessibleEventListener>& rxListener )
247 : throw ( ::com::sun::star::uno::RuntimeException );
248 :
249 : // XTypeProvider ----------------------------------------------------------
250 :
251 : /** @return An unique implementation ID. */
252 : virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
253 : throw ( ::com::sun::star::uno::RuntimeException );
254 :
255 : // XServiceInfo -----------------------------------------------------------
256 :
257 : /** @return Whether the specified service is supported by this class. */
258 : virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName )
259 : throw ( ::com::sun::star::uno::RuntimeException );
260 :
261 : /** @return A list of all supported services. */
262 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL
263 : getSupportedServiceNames()
264 : throw ( ::com::sun::star::uno::RuntimeException );
265 :
266 : /* Derived classes have to implement:
267 : - getImplementationName. */
268 :
269 : // helper methods ---------------------------------------------------------
270 :
271 : /** @return The BrowseBox object type. */
272 : inline ::svt::AccessibleBrowseBoxObjType getType() const;
273 :
274 : /** Changes the name of the object and notifies listeners. */
275 : void setAccessibleName( const OUString& rName );
276 : /** Changes the description of the object and notifies listeners. */
277 : void setAccessibleDescription( const OUString& rDescription );
278 :
279 : /** Commits an event to all listeners. */
280 : void commitEvent(
281 : sal_Int16 nEventId,
282 : const ::com::sun::star::uno::Any& rNewValue,
283 :
284 : const ::com::sun::star::uno::Any& rOldValue );
285 : /** @return <TRUE/>, if the object is not disposed or disposing. */
286 : sal_Bool isAlive() const;
287 :
288 : protected:
289 : // internal virtual methods -----------------------------------------------
290 :
291 : /** Determines whether the BrowseBox control is really showing inside of
292 : its parent accessible window. Derived classes may implement different
293 : behaviour.
294 : @attention This method requires locked mutex's and a living object.
295 : @return <TRUE/>, if the object is really showing. */
296 : virtual sal_Bool implIsShowing();
297 :
298 : /** Derived classes return the bounding box relative to the parent window.
299 : @attention This method requires locked mutex's and a living object.
300 : @return The bounding box (VCL rect.) relative to the parent window. */
301 : virtual Rectangle implGetBoundingBox() = 0;
302 : /** Derived classes return the bounding box in screen coordinates.
303 : @attention This method requires locked mutex's and a living object.
304 : @return The bounding box (VCL rect.) in screen coordinates. */
305 : virtual Rectangle implGetBoundingBoxOnScreen() = 0;
306 :
307 : /** Creates a new AccessibleStateSetHelper and fills it with states of the
308 : current object. This method calls FillStateSet at the BrowseBox which
309 : fills it with more states depending on the object type. Derived classes
310 : may overwrite this method and add more states.
311 : @attention This method requires locked mutex's.
312 : @return A filled AccessibleStateSetHelper. */
313 : virtual ::utl::AccessibleStateSetHelper* implCreateStateSetHelper();
314 :
315 : // internal helper methods ------------------------------------------------
316 :
317 : /** @throws <type>DisposedException</type> If the object is not alive. */
318 : void ensureIsAlive() const
319 : throw ( ::com::sun::star::lang::DisposedException );
320 :
321 : /** @return The ::osl::Mutex member provided by the class OBaseMutex. */
322 : inline ::osl::Mutex& getOslMutex();
323 : /** @return Pointer to the global ::osl::Mutex. */
324 : static inline ::osl::Mutex* getOslGlobalMutex();
325 :
326 : /** Changes the name of the object (flat assignment, no notify).
327 : @attention This method requires a locked mutex. */
328 : inline void implSetName( const OUString& rName );
329 : /** Changes the description of the object (flat assignment, no notify).
330 : @attention This method requires a locked mutex. */
331 : inline void implSetDescription( const OUString& rDescription );
332 :
333 : /** Locks all mutex's and calculates the bounding box relative to the
334 : parent window.
335 : @return The bounding box (VCL rect.) relative to the parent object. */
336 : Rectangle getBoundingBox()
337 : throw ( ::com::sun::star::lang::DisposedException );
338 : /** Locks all mutex's and calculates the bounding box in screen
339 : coordinates.
340 : @return The bounding box (VCL rect.) in screen coordinates. */
341 : Rectangle getBoundingBoxOnScreen()
342 : throw ( ::com::sun::star::lang::DisposedException );
343 :
344 0 : ::comphelper::AccessibleEventNotifier::TClientId getClientId() const { return m_aClientId; }
345 0 : void setClientId(::comphelper::AccessibleEventNotifier::TClientId _aNewClientId) { m_aClientId = _aNewClientId; }
346 :
347 : public:
348 : // public versions of internal helper methods, with access control
349 0 : struct AccessControl { friend class SolarMethodGuard; private: AccessControl() { } };
350 :
351 0 : inline ::osl::Mutex& getMutex( const AccessControl& ) { return getOslMutex(); }
352 0 : inline void ensureIsAlive( const AccessControl& ) { ensureIsAlive(); }
353 :
354 : protected:
355 : // members ----------------------------------------------------------------
356 :
357 : /** The parent accessible object. */
358 : ::com::sun::star::uno::Reference<
359 : ::com::sun::star::accessibility::XAccessible > mxParent;
360 : /** The VCL BrowseBox control. */
361 : ::svt::IAccessibleTableProvider* mpBrowseBox;
362 :
363 : /** This is the window which get all the nice focus events
364 : */
365 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xFocusWindow;
366 :
367 : private:
368 : /** Localized name. */
369 : OUString maName;
370 : /** Localized description text. */
371 : OUString maDescription;
372 :
373 : /** The type of this object (for names, descriptions, state sets, ...). */
374 : ::svt::AccessibleBrowseBoxObjType meObjType;
375 :
376 : ::comphelper::AccessibleEventNotifier::TClientId m_aClientId;
377 : };
378 :
379 : // ============================================================================
380 : // a version of AccessibleBrowseBoxBase which implements not only the XAccessibleContext,
381 : // but also the XAccessible
382 :
383 : typedef ::cppu::ImplHelper1 < ::com::sun::star::accessibility::XAccessible
384 : > BrowseBoxAccessibleElement_Base;
385 :
386 : class BrowseBoxAccessibleElement
387 : :public AccessibleBrowseBoxBase
388 : ,public BrowseBoxAccessibleElement_Base
389 : {
390 : protected:
391 : /** Constructor sets specified name and description. If the constant of a
392 : text is BBTEXT_NONE, the derived class has to set the text via
393 : implSetName() and implSetDescription() (in Ctor) or later via
394 : setAccessibleName() and setAccessibleDescription() (these methods
395 : notify the listeners about the change).
396 :
397 : @param rxParent XAccessible interface of the parent object.
398 : @param rBrowseBox The BrowseBox control.
399 : @param eNameText The constant for the name text.
400 : @param eDescrText The constant for the description text.
401 : */
402 : BrowseBoxAccessibleElement(
403 : const ::com::sun::star::uno::Reference<
404 : ::com::sun::star::accessibility::XAccessible >& rxParent,
405 : ::svt::IAccessibleTableProvider& rBrowseBox,
406 : const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& _xFocusWindow,
407 : ::svt::AccessibleBrowseBoxObjType eObjType );
408 :
409 : /** Constructor sets specified name and description.
410 :
411 : @param rxParent XAccessible interface of the parent object.
412 : @param rBrowseBox The BrowseBox control.
413 : @param rName The name of this object.
414 : @param rDescription The description text of this object.
415 : */
416 : BrowseBoxAccessibleElement(
417 : const ::com::sun::star::uno::Reference<
418 : ::com::sun::star::accessibility::XAccessible >& rxParent,
419 : ::svt::IAccessibleTableProvider& rBrowseBox,
420 : const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& _xFocusWindow,
421 : ::svt::AccessibleBrowseBoxObjType eObjType,
422 : const OUString& rName,
423 : const OUString& rDescription );
424 :
425 : public:
426 : // XInterface
427 : DECLARE_XINTERFACE( )
428 : // XTypeProvider
429 : DECLARE_XTYPEPROVIDER( )
430 :
431 : protected:
432 : virtual ~BrowseBoxAccessibleElement();
433 :
434 : protected:
435 : // XAccessible ------------------------------------------------------------
436 :
437 : /** @return The XAccessibleContext interface of this object. */
438 : virtual ::com::sun::star::uno::Reference<
439 : ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL
440 : getAccessibleContext()
441 : throw ( ::com::sun::star::uno::RuntimeException );
442 :
443 : private:
444 : BrowseBoxAccessibleElement(); // never implemented
445 : BrowseBoxAccessibleElement( const BrowseBoxAccessibleElement& ); // never implemented
446 : BrowseBoxAccessibleElement& operator=( const BrowseBoxAccessibleElement& ); // never implemented
447 : };
448 :
449 : // ============================================================================
450 : // a helper class for protecting methods which need to lock the solar mutex in addition to the own mutex
451 :
452 : typedef ::osl::MutexGuard OslMutexGuard;
453 :
454 0 : class SolarMethodGuard : public SolarMutexGuard, public OslMutexGuard
455 : {
456 : public:
457 0 : inline SolarMethodGuard( AccessibleBrowseBoxBase& _rOwner, bool _bEnsureAlive = true )
458 : :SolarMutexGuard( )
459 0 : ,OslMutexGuard( _rOwner.getMutex( AccessibleBrowseBoxBase::AccessControl() ) )
460 : {
461 0 : if ( _bEnsureAlive )
462 0 : _rOwner.ensureIsAlive( AccessibleBrowseBoxBase::AccessControl() );
463 0 : }
464 : };
465 :
466 : // inlines --------------------------------------------------------------------
467 :
468 0 : inline ::svt::AccessibleBrowseBoxObjType AccessibleBrowseBoxBase::getType() const
469 : {
470 0 : return meObjType;
471 : }
472 :
473 0 : inline ::osl::Mutex& AccessibleBrowseBoxBase::getOslMutex()
474 : {
475 0 : return m_aMutex;
476 : }
477 :
478 : inline ::osl::Mutex* AccessibleBrowseBoxBase::getOslGlobalMutex()
479 : {
480 : return ::osl::Mutex::getGlobalMutex();
481 : }
482 :
483 0 : inline void AccessibleBrowseBoxBase::implSetName(
484 : const OUString& rName )
485 : {
486 0 : maName = rName;
487 0 : }
488 :
489 : inline void AccessibleBrowseBoxBase::implSetDescription(
490 : const OUString& rDescription )
491 : {
492 : maDescription = rDescription;
493 : }
494 :
495 : // ============================================================================
496 :
497 : } // namespace accessibility
498 :
499 : // ============================================================================
500 :
501 : #endif
502 :
503 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|