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_SVX_SOURCE_INC_SVXRECTCTACCESSIBLECONTEXT_HXX
22 #define INCLUDED_SVX_SOURCE_INC_SVXRECTCTACCESSIBLECONTEXT_HXX
23 
24 #include <com/sun/star/accessibility/XAccessible.hpp>
25 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
26 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
27 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
28 #include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
29 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
30 #include <com/sun/star/accessibility/XAccessibleAction.hpp>
31 #include <com/sun/star/accessibility/XAccessibleValue.hpp>
32 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
33 #include <com/sun/star/uno/Reference.hxx>
34 #include <cppuhelper/weak.hxx>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/lang/XTypeProvider.hpp>
37 #include <com/sun/star/lang/XServiceName.hpp>
38 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
39 #include <com/sun/star/lang/DisposedException.hpp>
40 #include <osl/mutex.hxx>
41 #include <cppuhelper/interfacecontainer.h>
42 #include <cppuhelper/compbase6.hxx>
43 #include <cppuhelper/compbase7.hxx>
44 #include <cppuhelper/compbase3.hxx>
45 #include <cppuhelper/basemutex.hxx>
46 #include <comphelper/accessibleselectionhelper.hxx>
47 #include <svx/rectenum.hxx>
48 #include <vcl/vclptr.hxx>
49 #include <tools/gen.hxx>
50 #include <vector>
51 
52 namespace com { namespace sun { namespace star { namespace awt {
53     struct Point;
54     struct Rectangle;
55     struct Size;
56     class XFocusListener;
57 } } } }
58 
59 namespace tools { class Rectangle; }
60 class SvxRectCtl;
61 class SvxRectCtlChildAccessibleContext;
62 namespace vcl { class Window; }
63 
64 typedef ::cppu::ImplHelper1<css::accessibility::XAccessible> OAccessibleHelper_Base;
65 
66 class SvxRectCtlAccessibleContext final : public ::comphelper::OAccessibleSelectionHelper,
67                                        public OAccessibleHelper_Base
68 {
69 public:
70     // internal
71     SvxRectCtlAccessibleContext(SvxRectCtl* pRepresentation);
72 
73     DECLARE_XINTERFACE( )
74     DECLARE_XTYPEPROVIDER( )
75 
76     // XAccessibleComponent
77     virtual void SAL_CALL grabFocus() override;
78     virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point& rPoint) override;
79 
80     // XAccessible
81     // XAccessibleContext
82     virtual sal_Int32 SAL_CALL getAccessibleChildCount() override;
83     virtual css::uno::Reference< css::accessibility::XAccessible> SAL_CALL getAccessibleChild(sal_Int32 nIndex) override;
84     virtual css::uno::Reference< css::accessibility::XAccessible> SAL_CALL getAccessibleParent() override;
85     virtual sal_Int16 SAL_CALL getAccessibleRole() override;
86     virtual OUString SAL_CALL getAccessibleDescription() override;
87     virtual OUString SAL_CALL getAccessibleName() override;
88     virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override;
89     virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() override;
90 
getAccessibleContext()91     virtual css::uno::Reference< css::accessibility::XAccessibleContext> SAL_CALL getAccessibleContext() override { return this; }
92     virtual sal_Int32 SAL_CALL getForeground() override;
93     virtual sal_Int32 SAL_CALL getBackground() override;
94 
95     /** Selects a new child by point.
96 
97         <p>If the child was not selected before, the state of the child will
98         be updated. If the point is not invalid, the index will internally set to NOCHILDSELECTED</p>
99 
100         @param eButton
101             Button which belongs to the child which should be selected.
102     */
103     void selectChild( RectPoint ePoint );
104     void FireChildFocus( RectPoint eButton );
105 
106 private:
107     virtual ~SvxRectCtlAccessibleContext() override;
108 
109     // OCommonAccessibleSelection
110     // return if the specified child is visible => watch for special ChildIndexes (ACCESSIBLE_SELECTION_CHILD_xxx)
111     virtual bool implIsSelected(sal_Int32 nAccessibleChildIndex) override;
112 
113     // select the specified child => watch for special ChildIndexes (ACCESSIBLE_SELECTION_CHILD_xxx)
114     virtual void implSelect(sal_Int32 nAccessibleChildIndex, bool bSelect) override;
115 
116     // OCommonAccessibleComponent
117     virtual css::awt::Rectangle implGetBounds() override;
118 
119     virtual void SAL_CALL disposing() override;
120 
121     void checkChildIndex(long nIndex);
122 
123     /** Selects a new child by index.
124 
125         <p>If the child was not selected before, the state of the child will
126         be updated. If the index is invalid, the index will internally set to NOCHILDSELECTED</p>
127 
128         @param nIndexOfChild
129             Index of the new child which should be selected.
130     */
131     void selectChild( long nIndexOfChild );
132 
133     /** Description of this object.  This is not a constant because it can
134         be set from the outside.
135     */
136     OUString                     msDescription;
137 
138     /** Name of this object.
139     */
140     OUString                     msName;
141 
142     /// pointer to internal representation
143     SvxRectCtl*                  mpRepr;
144 
145     /// array for all possible children
146     std::vector<rtl::Reference<SvxRectCtlChildAccessibleContext>>  mvChildren;
147 
148     /// actual selected child
149     long                                mnSelectedChild;
150 };
151 
152 typedef ::cppu::ImplHelper3 <   css::accessibility::XAccessible,
153                                 css::accessibility::XAccessibleValue,
154                                 css::accessibility::XAccessibleAction
155                             >   OAccessibleHelper_Base_3;
156 
157 class SvxRectCtlChildAccessibleContext final : public ::comphelper::OAccessibleComponentHelper,
158                                             public OAccessibleHelper_Base_3
159 {
160 public:
161     SvxRectCtlChildAccessibleContext(
162         const css::uno::Reference< css::accessibility::XAccessible>& rxParent,
163         const OUString& rName, const OUString& rDescription,
164         const tools::Rectangle& rBoundingBox,
165         long nIndexInParent );
166 
167     DECLARE_XINTERFACE( )
168     DECLARE_XTYPEPROVIDER( )
169 
170     // XAccessibleComponent
171     virtual void SAL_CALL grabFocus() override;
172     virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& rPoint ) override;
173 
174     // XAccessibleContext
175     virtual sal_Int32 SAL_CALL getAccessibleChildCount() override;
176     virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 nIndex ) override;
177     virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override;
178     virtual sal_Int16 SAL_CALL getAccessibleRole() override;
179     virtual OUString SAL_CALL getAccessibleDescription() override;
180     virtual OUString SAL_CALL getAccessibleName() override;
181     virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override;
182     virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() override;
183 
getAccessibleContext()184     virtual css::uno::Reference< css::accessibility::XAccessibleContext> SAL_CALL getAccessibleContext() override { return this; }
185 
186     virtual sal_Int32 SAL_CALL getForeground() override;
187     virtual sal_Int32 SAL_CALL getBackground() override;
188 
189     // XAccessibleValue
190     virtual css::uno::Any SAL_CALL
191         getCurrentValue() override;
192 
193     virtual sal_Bool SAL_CALL
194         setCurrentValue( const css::uno::Any& aNumber ) override;
195 
196     virtual css::uno::Any SAL_CALL
197         getMaximumValue() override;
198 
199     virtual css::uno::Any SAL_CALL
200         getMinimumValue() override;
201 
202     // XAccessibleAction
203     virtual sal_Int32 SAL_CALL getAccessibleActionCount( ) override;
204     virtual sal_Bool SAL_CALL doAccessibleAction ( sal_Int32 nIndex ) override;
205     virtual OUString SAL_CALL getAccessibleActionDescription ( sal_Int32 nIndex ) override;
206     virtual css::uno::Reference< css::accessibility::XAccessibleKeyBinding > SAL_CALL getAccessibleActionKeyBinding( sal_Int32 nIndex ) override;
207 
208     // internal
209     /// Sets the checked status
210     void setStateChecked(bool bChecked);
211     void FireFocusEvent();
212 
213 private:
214     virtual ~SvxRectCtlChildAccessibleContext() override;
215 
216     virtual void SAL_CALL disposing() override;
217 
218     // OCommonAccessibleComponent
219     /// implements the calculation of the bounding rectangle
220     virtual css::awt::Rectangle implGetBounds(  ) override;
221 
222     /** Description of this object.  This is not a constant because it can
223         be set from the outside.  Furthermore, it changes according to the
224         draw page's display mode.
225     */
226     OUString const                      msDescription;
227 
228     /** Name of this object.  It changes according the draw page's
229         display mode.
230     */
231     OUString const                      msName;
232 
233     /// Reference to the parent object.
234     css::uno::Reference< css::accessibility::XAccessible >
235                                         mxParent;
236 
237     /// Bounding box
238     tools::Rectangle const              maBoundingBox;
239 
240     /// index of child in parent
241     long const                          mnIndexInParent;
242 
243     /// Indicates, if object is checked
244     bool                                mbIsChecked;
245 };
246 
247 
248 #endif
249 
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
251