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