xref: /trunk/main/svx/source/inc/svxrectctaccessiblecontext.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 _SVXRECTACCESSIBLECONTEXT_HXX
26 #define _SVXRECTACCESSIBLECONTEXT_HXX
27 
28 #include <com/sun/star/accessibility/XAccessible.hpp>
29 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
30 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
31 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
32 #include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
33 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
34 #include <com/sun/star/accessibility/XAccessibleValue.hpp>
35 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
36 #include <com/sun/star/uno/Reference.hxx>
37 #include <cppuhelper/weak.hxx>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <com/sun/star/lang/XTypeProvider.hpp>
40 #include <com/sun/star/lang/XServiceName.hpp>
41 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
42 #include <com/sun/star/lang/DisposedException.hpp>
43 #include <vos/mutex.hxx>
44 #include <cppuhelper/interfacecontainer.h>
45 #include <cppuhelper/compbase6.hxx>
46 #ifndef _CPPUHELPER_COMPBASE7_HXX_
47 #include <cppuhelper/compbase7.hxx>
48 #endif
49 #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLE_ACTION_HPP_
50 #include <com/sun/star/accessibility/XAccessibleAction.hpp>
51 #endif
52 #include <comphelper/broadcasthelper.hxx>
53 #include <cppuhelper/implbase6.hxx>
54 #include <comphelper/servicehelper.hxx>
55 #include <svx/rectenum.hxx>
56 
57 namespace com { namespace sun { namespace star { namespace awt {
58     struct Point;
59     struct Rectangle;
60     struct Size;
61     class XFocusListener;
62 } } } }
63 
64 class Rectangle;
65 class SvxRectCtl;
66 class SvxRectCtlChildAccessibleContext;
67 class Window;
68 
69 
70 typedef ::cppu::WeakAggComponentImplHelper6<
71             ::com::sun::star::accessibility::XAccessible,
72             ::com::sun::star::accessibility::XAccessibleComponent,
73             ::com::sun::star::accessibility::XAccessibleContext,
74             ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
75             ::com::sun::star::accessibility::XAccessibleSelection,
76             ::com::sun::star::lang::XServiceInfo >
77             SvxRectCtlAccessibleContext_Base;
78 
79 class SvxRectCtlAccessibleContext : public ::comphelper::OBaseMutex, public SvxRectCtlAccessibleContext_Base
80 {
81 public:
82     //=====  internal  ========================================================
83     SvxRectCtlAccessibleContext(
84         const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible>& rxParent,
85         SvxRectCtl&             rRepresentation,
86         const ::rtl::OUString*  pName = NULL,
87         const ::rtl::OUString*  pDescription = NULL );
88 protected:
89     virtual ~SvxRectCtlAccessibleContext();
90 public:
91     //=====  XAccessible  =====================================================
92 
93     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext> SAL_CALL
94         getAccessibleContext( void );
95 
96     //=====  XAccessibleComponent  ============================================
97 
98     virtual sal_Bool SAL_CALL
99         containsPoint( const ::com::sun::star::awt::Point& rPoint );
100 
101     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
102         getAccessibleAtPoint( const ::com::sun::star::awt::Point& rPoint );
103 
104     virtual ::com::sun::star::awt::Rectangle SAL_CALL
105         getBounds();
106 
107     virtual ::com::sun::star::awt::Point SAL_CALL
108         getLocation();
109 
110     virtual ::com::sun::star::awt::Point SAL_CALL
111         getLocationOnScreen();
112 
113     virtual ::com::sun::star::awt::Size SAL_CALL
114         getSize();
115 
116     virtual sal_Bool SAL_CALL
117         isShowing();
118 
119     virtual sal_Bool SAL_CALL
120         isVisible();
121 
122     virtual sal_Bool SAL_CALL
123         isFocusTraversable();
124 
125     virtual void SAL_CALL
126         addFocusListener(
127             const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener );
128 
129     virtual void SAL_CALL
130         removeFocusListener(
131             const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener );
132 
133     virtual void SAL_CALL
134         grabFocus();
135 
136     virtual ::com::sun::star::uno::Any SAL_CALL
137         getAccessibleKeyBinding();
138     virtual sal_Int32 SAL_CALL
139         getForeground(  );
140     virtual sal_Int32 SAL_CALL
141         getBackground(  );
142 
143     //=====  XAccessibleContext  ==============================================
144 
145     virtual sal_Int32 SAL_CALL
146         getAccessibleChildCount( void );
147 
148     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
149         getAccessibleChild( sal_Int32 nIndex );
150 
151     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
152         getAccessibleParent( void );
153 
154     virtual sal_Int32 SAL_CALL
155         getAccessibleIndexInParent( void );
156 
157     virtual sal_Int16 SAL_CALL
158         getAccessibleRole( void );
159 
160     virtual ::rtl::OUString SAL_CALL
161         getAccessibleDescription( void );
162 
163     virtual ::rtl::OUString SAL_CALL
164         getAccessibleName( void );
165 
166     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL
167         getAccessibleRelationSet( void );
168 
169     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL
170         getAccessibleStateSet( void );
171 
172     virtual ::com::sun::star::lang::Locale SAL_CALL
173         getLocale( void );
174 
175     //=====  XComponent  =====================================================
176 
177     using ::cppu::WeakAggComponentImplHelperBase::addEventListener;
178     using ::cppu::WeakAggComponentImplHelperBase::removeEventListener;
179 
180     //=====  XAccessibleEventBroadcaster  =====================================
181 
182     virtual void SAL_CALL
183         addEventListener(
184             const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener );
185 
186     virtual void SAL_CALL
187         removeEventListener(
188             const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener );
189 
190     //=====  XServiceInfo  ====================================================
191 
192     virtual ::rtl::OUString SAL_CALL
193         getImplementationName( void );
194 
195     virtual sal_Bool SAL_CALL
196         supportsService( const ::rtl::OUString& sServiceName );
197 
198     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
199         getSupportedServiceNames( void );
200 
201     //=====  XTypeProvider  ===================================================
202 
203     virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL
204         getImplementationId( void );
205 
206     //=====  XAccessibleSelection =============================================
207 
208     virtual void SAL_CALL
209         selectAccessibleChild( sal_Int32 nChildIndex );
210 
211     virtual sal_Bool SAL_CALL
212         isAccessibleChildSelected( sal_Int32 nChildIndex );
213 
214     virtual void SAL_CALL
215         clearAccessibleSelection();
216 
217     virtual void SAL_CALL
218         selectAllAccessibleChildren();
219 
220     virtual sal_Int32 SAL_CALL
221         getSelectedAccessibleChildCount();
222 
223     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
224         getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex );
225 
226     virtual void SAL_CALL
227         deselectAccessibleChild( sal_Int32 nSelectedChildIndex );
228 
229 
230 protected:
231     //=====  internals ========================================================
232 
233     void checkChildIndex( long nIndexOfChild );
234 
235     void checkChildIndexOnSelection( long nIndexOfChild );
236 
237     /** Selects a new child by index.
238 
239         <p>If the child was not selected before, the state of the child will
240         be updated. If the index is invalid, the index will internally set to NOCHILDSELECTED</p>
241 
242         @param nIndexOfChild
243             Index of the new child which should be selected.
244     */
245     //void selectChild( long nIndexOfChild );
246     void selectChild( long nIndexOfChild, sal_Bool bFireFocus = sal_True);
247 
248 public:
249     /** Selects a new child by point.
250 
251         <p>If the child was not selected before, the state of the child will
252         be updated. If the point is not invalid, the index will internally set to NOCHILDSELECTED</p>
253 
254         @param eButton
255             Button which belongs to the child which should be selected.
256     */
257     //void selectChild( RECT_POINT ePoint );
258     void selectChild( RECT_POINT ePoint, sal_Bool bFireFocus = sal_True );
259     void FireChildFocus( RECT_POINT eButton );
260     //Solution: Add the event handling method
261     void FireAccessibleEvent (short nEventId, const ::com::sun::star::uno::Any& rOld, const ::com::sun::star::uno::Any& rNew);
262     /// Sets the name
263     void setName( const ::rtl::OUString& rName );
264 
265     /// Sets the description
266     void setDescription( const ::rtl::OUString& rDescr );
267 private:
268     static ::com::sun::star::uno::Sequence< sal_Int8 > getUniqueId( void );
269 protected:
270 
271     /// @Return the object's current bounding box relative to the desktop.
272     virtual Rectangle GetBoundingBoxOnScreen( void );
273 
274     /// @Return the object's current bounding box relative to the parent object.
275     virtual Rectangle GetBoundingBox( void );
276 
277     /// Calls all Listener to tell they the change.
278     void CommitChange( const com::sun::star::accessibility::AccessibleEventObject& rEvent );
279 
280     virtual void SAL_CALL disposing();
281 
282     /// @returns true if it's disposed or in disposing
283     inline sal_Bool IsAlive( void ) const;
284 
285     /// @returns true if it's not disposed and no in disposing
286     inline sal_Bool IsNotAlive( void ) const;
287 
288     /// throws the exception DisposedException if it's not alive
289     void ThrowExceptionIfNotAlive( void );
290 
291 private:
292     /** Description of this object.  This is not a constant because it can
293         be set from the outside.
294     */
295     ::rtl::OUString                     msDescription;
296 
297     /** Name of this object.
298     */
299     ::rtl::OUString                     msName;
300 
301     /// Reference to the parent object.
302     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
303                                         mxParent;
304 
305     /// pointer to internal representation
306     SvxRectCtl*                         mpRepr;
307 
308     /// array for all possible childs
309     SvxRectCtlChildAccessibleContext**  mpChilds;
310 
311     /// client id in the AccessibleEventNotifier queue
312     sal_uInt32 mnClientId;
313 
314     /// actual selected child
315     long                                mnSelectedChild;
316 
317     /// mode of control (true -> 8 points, false -> 9 points)
318     sal_Bool                            mbAngleMode;
319 };
320 
IsAlive(void) const321 inline sal_Bool SvxRectCtlAccessibleContext::IsAlive( void ) const
322 {
323     return !rBHelper.bDisposed && !rBHelper.bInDispose;
324 }
325 
IsNotAlive(void) const326 inline sal_Bool SvxRectCtlAccessibleContext::IsNotAlive( void ) const
327 {
328     return rBHelper.bDisposed || rBHelper.bInDispose;
329 }
330 
331 typedef ::cppu::WeakAggComponentImplHelper7<
332             ::com::sun::star::accessibility::XAccessible,
333             ::com::sun::star::accessibility::XAccessibleComponent,
334             ::com::sun::star::accessibility::XAccessibleContext,
335             ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
336             ::com::sun::star::accessibility::XAccessibleValue,
337             ::com::sun::star::accessibility::XAccessibleAction,
338             ::com::sun::star::lang::XServiceInfo >
339             SvxRectCtlChildAccessibleContext_Base;
340 
341 
342 class SvxRectCtlChildAccessibleContext : public SvxRectCtlChildAccessibleContext_Base
343 {
344 public:
345     SvxRectCtlChildAccessibleContext(
346         const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible>& rxParent,
347         const Window& rParentWindow,
348         const ::rtl::OUString& rName, const ::rtl::OUString& rDescription,
349         const Rectangle& rBoundingBox,
350         long nIndexInParent );
351 protected:
352     virtual ~SvxRectCtlChildAccessibleContext();
353 public:
354     //=====  XAccessible  =====================================================
355 
356     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext> SAL_CALL
357         getAccessibleContext( void );
358 
359     //=====  XAccessibleComponent  ============================================
360 
361     virtual sal_Bool SAL_CALL
362         containsPoint( const ::com::sun::star::awt::Point& rPoint );
363 
364     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
365         getAccessibleAtPoint( const ::com::sun::star::awt::Point& rPoint );
366 
367     virtual ::com::sun::star::awt::Rectangle SAL_CALL
368         getBounds();
369 
370     virtual ::com::sun::star::awt::Point SAL_CALL
371         getLocation();
372 
373     virtual ::com::sun::star::awt::Point SAL_CALL
374         getLocationOnScreen();
375 
376     virtual ::com::sun::star::awt::Size SAL_CALL
377         getSize();
378 
379     virtual sal_Bool SAL_CALL
380         isShowing();
381 
382     virtual sal_Bool SAL_CALL
383         isVisible();
384 
385     virtual sal_Bool SAL_CALL
386         isFocusTraversable();
387 
388     virtual void SAL_CALL
389         addFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener );
390 
391     virtual void SAL_CALL
392         removeFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener );
393 
394     virtual void SAL_CALL
395         grabFocus();
396 
397     virtual ::com::sun::star::uno::Any SAL_CALL
398         getAccessibleKeyBinding();
399     virtual sal_Int32 SAL_CALL
400         getForeground(  );
401     virtual sal_Int32 SAL_CALL
402         getBackground(  );
403 
404     //=====  XAccessibleContext  ==============================================
405 
406     virtual sal_Int32 SAL_CALL
407         getAccessibleChildCount( void );
408 
409     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
410         getAccessibleChild( sal_Int32 nIndex );
411 
412     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
413         getAccessibleParent( void );
414 
415     virtual sal_Int32 SAL_CALL
416         getAccessibleIndexInParent( void );
417 
418     virtual sal_Int16 SAL_CALL
419         getAccessibleRole( void );
420 
421     virtual ::rtl::OUString SAL_CALL
422         getAccessibleDescription( void );
423 
424     virtual ::rtl::OUString SAL_CALL
425         getAccessibleName( void );
426 
427     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL
428         getAccessibleRelationSet( void );
429 
430     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL
431         getAccessibleStateSet( void );
432 
433     virtual ::com::sun::star::lang::Locale SAL_CALL
434         getLocale( void );
435 
436     //=====  XComponent  =====================================================
437 
438     using ::cppu::WeakAggComponentImplHelperBase::addEventListener;
439     using ::cppu::WeakAggComponentImplHelperBase::removeEventListener;
440 
441     //=====  XAccessibleEventBroadcaster  =====================================
442 
443     virtual void SAL_CALL
444         addEventListener(
445             const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener );
446 
447     virtual void SAL_CALL
448         removeEventListener(
449             const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener );
450 
451     //=====  XAccessibleValue  ================================================
452 
453     virtual ::com::sun::star::uno::Any SAL_CALL
454         getCurrentValue();
455 
456     virtual sal_Bool SAL_CALL
457         setCurrentValue( const ::com::sun::star::uno::Any& aNumber );
458 
459     virtual ::com::sun::star::uno::Any SAL_CALL
460         getMaximumValue();
461 
462     virtual ::com::sun::star::uno::Any SAL_CALL
463         getMinimumValue();
464 
465     // XAccessibleAction
466     virtual sal_Int32 SAL_CALL getAccessibleActionCount( );
467     virtual sal_Bool SAL_CALL doAccessibleAction ( sal_Int32 nIndex );
468     virtual ::rtl::OUString SAL_CALL getAccessibleActionDescription ( sal_Int32 nIndex );
469     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleKeyBinding > SAL_CALL getAccessibleActionKeyBinding( sal_Int32 nIndex );
470     //=====  XServiceInfo  ====================================================
471 
472     virtual ::rtl::OUString SAL_CALL
473         getImplementationName( void );
474 
475     virtual sal_Bool SAL_CALL
476         supportsService( const ::rtl::OUString& sServiceName );
477 
478     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
479         getSupportedServiceNames( void );
480 
481 
482     //=====  XTypeProvider  ===================================================
483 
484     virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL
485         getImplementationId( void );
486 
487     //===== internal ==========================================================
488 
489     /// Sets the checked status
490     //void setStateChecked( sal_Bool bChecked );
491     void setStateChecked( sal_Bool bChecked, sal_Bool bFireFocus = sal_True);
492     void FireFocusEvent();
493 protected:
494     virtual Rectangle GetBoundingBoxOnScreen( void );
495 
496     virtual Rectangle GetBoundingBox( void );
497 
498     void CommitChange( const com::sun::star::accessibility::AccessibleEventObject& rEvent );
499 
500     virtual void SAL_CALL disposing();
501 
502     /// @returns true if it's disposed or in disposing
503     inline sal_Bool IsAlive( void ) const;
504 
505     /// @returns true if it's not disposed and no in disposing
506     inline sal_Bool IsNotAlive( void ) const;
507 
508     /// throws the exception DisposedException if it's not alive
509     void ThrowExceptionIfNotAlive( void );
510 
511     /// Mutex guarding this object.
512     ::osl::Mutex                        maMutex;
513 
514 private:
515 
516     /** Description of this object.  This is not a constant because it can
517         be set from the outside.  Furthermore, it changes according to the
518         draw page's display mode.
519     */
520     ::rtl::OUString                     msDescription;
521 
522     /** Name of this object.  It changes according the draw page's
523         display mode.
524     */
525     ::rtl::OUString                     msName;
526 
527     /// Reference to the parent object.
528     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
529                                         mxParent;
530 
531     /// Bounding box
532     Rectangle*                          mpBoundingBox;
533 
534     /// window of parent
535     const Window&                       mrParentWindow;
536 
537     /// client id in the AccessibleEventNotifier queue
538     sal_uInt32                          mnClientId;
539 
540     /// index of child in parent
541     long                                mnIndexInParent;
542 
543     /// Indicates, if object is checked
544     sal_Bool                            mbIsChecked;
545 };
546 
IsAlive(void) const547 inline sal_Bool SvxRectCtlChildAccessibleContext::IsAlive( void ) const
548 {
549     return !rBHelper.bDisposed && !rBHelper.bInDispose;
550 }
551 
IsNotAlive(void) const552 inline sal_Bool SvxRectCtlChildAccessibleContext::IsNotAlive( void ) const
553 {
554     return rBHelper.bDisposed || rBHelper.bInDispose;
555 }
556 
557 
558 #endif
559