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