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_EXTENDED_ACCESSIBLEBROWSEBOX_HXX
22 #define INCLUDED_ACCESSIBILITY_INC_EXTENDED_ACCESSIBLEBROWSEBOX_HXX
23 
24 #include <extended/AccessibleBrowseBoxBase.hxx>
25 #include <cppuhelper/implbase.hxx>
26 #include <cppuhelper/weakref.hxx>
27 #include <vcl/accessibletableprovider.hxx>
28 
29 namespace accessibility {
30 
31     class AccessibleBrowseBoxHeaderBar;
32     class AccessibleBrowseBoxTable;
33 
34 
35 /** This class represents the complete accessible BrowseBox object. */
36 class AccessibleBrowseBox : public AccessibleBrowseBoxBase
37 {
38     friend class AccessibleBrowseBoxAccess;
39 
40 protected:
41     AccessibleBrowseBox(
42         const css::uno::Reference< css::accessibility::XAccessible >& _rxParent,
43         const css::uno::Reference< css::accessibility::XAccessible >& _rxCreator,
44         ::vcl::IAccessibleTableProvider& _rBrowseBox
45     );
46 
47     virtual ~AccessibleBrowseBox() override;
48 
49     /** sets the XAccessible which created the context
50 
51         To be called only once, and only if in the ctor NULL was passed.
52     */
53     void    setCreator(
54         const css::uno::Reference< css::accessibility::XAccessible >& _rxCreator
55     );
56 
57     /** Cleans up members. */
58     using AccessibleBrowseBoxBase::disposing;
59     virtual void SAL_CALL disposing() override;
60 
61 protected:
62     // XAccessibleContext
63 
64     /** @return  The count of visible children. */
65     virtual sal_Int32 SAL_CALL getAccessibleChildCount() override;
66 
67     /** @return  The XAccessible interface of the specified child. */
68     virtual css::uno::Reference<
69         css::accessibility::XAccessible > SAL_CALL
70     getAccessibleChild( sal_Int32 nChildIndex ) override;
71 
72     // XAccessibleComponent
73 
74     /** @return
75             The accessible child rendered under the given point.
76     */
77     virtual css::uno::Reference<
78         css::accessibility::XAccessible > SAL_CALL
79     getAccessibleAtPoint( const css::awt::Point& rPoint ) override;
80 
81     /** Grabs the focus to the BrowseBox. */
82     virtual void SAL_CALL grabFocus() override;
83 
84     // XServiceInfo
85 
86     /** @return
87             The name of this class.
88     */
89     virtual OUString SAL_CALL getImplementationName() override;
90 
91 public:
92     // helper functions
93     /** commitHeaderBarEvent commit the event at all listeners of the column/row header bar
94         @param nEventId
95             the event id
96         @param rNewValue
97             the new value
98         @param rOldValue
99             the old value
100         @param _bColumnHeaderBar
101             true if a column based header bar, false if a row based header bar
102     */
103     void commitHeaderBarEvent(sal_Int16 nEventId,
104             const css::uno::Any& rNewValue,
105             const css::uno::Any& rOldValue, bool _bColumnHeaderBar);
106 
107     // helper functions
108     /** commitTableEvent commit the event at all listeners of the table
109         @param nEventId
110             the event id
111         @param rNewValue
112             the new value
113         @param rOldValue
114             the old value
115     */
116     void commitTableEvent(sal_Int16 nEventId,
117             const css::uno::Any& rNewValue,
118             const css::uno::Any& rOldValue);
119 
120     /** returns the accessible object for the row or the column header bar
121     */
122     css::uno::Reference<
123         css::accessibility::XAccessible >
getHeaderBar(::vcl::AccessibleBrowseBoxObjType _eObjType)124         getHeaderBar( ::vcl::AccessibleBrowseBoxObjType _eObjType )
125         {
126             return implGetHeaderBar(_eObjType);
127         }
128 
129     /** returns the accessible object for the table representation
130     */
131     css::uno::Reference<
132         css::accessibility::XAccessible >
getTable()133         getTable( )
134         {
135             return implGetTable();
136         }
137 
138 protected:
139     // internal virtual methods
140 
141     /** @attention  This method requires locked mutex's and a living object.
142         @return  The bounding box (VCL rect.) relative to the parent window. */
143     virtual tools::Rectangle implGetBoundingBox() override;
144     /** @attention  This method requires locked mutex's and a living object.
145         @return  The bounding box (VCL rect.) in screen coordinates. */
146     virtual tools::Rectangle implGetBoundingBoxOnScreen() override;
147 
148     // internal helper methods
149 
150     /** This method creates (once) and returns the accessible data table child.
151         @attention  This method requires locked mutex's and a living object.
152         @return  The XAccessible interface of the data table. */
153     css::uno::Reference<
154         css::accessibility::XAccessible > implGetTable();
155 
156     /** This method creates (once) and returns the specified header bar.
157         @attention  This method requires locked mutex's and a living object.
158         @return  The XAccessible interface of the header bar. */
159     css::uno::Reference<
160         css::accessibility::XAccessible >
161         implGetHeaderBar( ::vcl::AccessibleBrowseBoxObjType eObjType );
162 
163     /** This method returns one of the children that are always present:
164         Data table, row and column header bar or corner control.
165         @attention  This method requires locked mutex's and a living object.
166         @return  The XAccessible interface of the specified child. */
167     css::uno::Reference<
168         css::accessibility::XAccessible >
169     implGetFixedChild( sal_Int32 nChildIndex );
170 
171     /** This method creates and returns an accessible table.
172         @return  An AccessibleBrowseBoxTable. */
173     virtual AccessibleBrowseBoxTable*   createAccessibleTable();
174 
175 private:
176     /// the css::accessibility::XAccessible which created the AccessibleBrowseBox
177     css::uno::WeakReference< css::accessibility::XAccessible >  m_aCreator;
178 
179     /** The data table child. */
180     rtl::Reference<AccessibleBrowseBoxTable>                    mxTable;
181 
182     /** The header bar for rows ("handle column"). */
183     rtl::Reference<AccessibleBrowseBoxHeaderBar>                mxRowHeaderBar;
184 
185     /** The header bar for columns (first row of the table). */
186     rtl::Reference<AccessibleBrowseBoxHeaderBar>                mxColumnHeaderBar;
187 };
188 
189 
190 /** the XAccessible which creates/returns an AccessibleBrowseBox
191 
192     The instance holds its XAccessibleContext with a hard reference, while
193     the context holds this instance weak.
194 */
195 class AccessibleBrowseBoxAccess:
196     public cppu::WeakImplHelper<css::accessibility::XAccessible>,
197     public ::vcl::IAccessibleBrowseBox
198 {
199 private:
200     ::osl::Mutex                        m_aMutex;
201     css::uno::Reference< css::accessibility::XAccessible >
202                                         m_xParent;
203     ::vcl::IAccessibleTableProvider&    m_rBrowseBox;
204 
205     rtl::Reference<AccessibleBrowseBox> m_xContext;
206 
207 public:
208     AccessibleBrowseBoxAccess(
209         const css::uno::Reference< css::accessibility::XAccessible >& _rxParent,
210         ::vcl::IAccessibleTableProvider& _rBrowseBox
211     );
212 
213     /// returns the AccessibleContext belonging to this Accessible
getContext()214     AccessibleBrowseBox*            getContext() { return m_xContext.get(); }
215 
216 protected:
217     virtual ~AccessibleBrowseBoxAccess() override;
218 
219     // XAccessible
220     virtual css::uno::Reference< css::accessibility::XAccessibleContext >
221         SAL_CALL getAccessibleContext() override;
222 
223     // IAccessibleBrowseBox
224     virtual css::uno::Reference< css::accessibility::XAccessible >
getMyself()225         getMyself() override
226     {
227         return this;
228     }
229     void dispose() override;
isAlive() const230     virtual bool isAlive() const override
231     {
232         return m_xContext.is() && m_xContext->isAlive();
233     }
234     virtual css::uno::Reference< css::accessibility::XAccessible >
getHeaderBar(::vcl::AccessibleBrowseBoxObjType _eObjType)235         getHeaderBar( ::vcl::AccessibleBrowseBoxObjType _eObjType ) override
236     {
237         css::uno::Reference< css::accessibility::XAccessible > xAccessible;
238         AccessibleBrowseBox* pContext( getContext() );
239         if ( pContext )
240             xAccessible = pContext->getHeaderBar( _eObjType );
241         return xAccessible;
242     }
243     virtual css::uno::Reference< css::accessibility::XAccessible >
getTable()244         getTable() override
245     {
246         css::uno::Reference< css::accessibility::XAccessible > xAccessible;
247         AccessibleBrowseBox* pContext( getContext() );
248         if ( pContext )
249             xAccessible = pContext->getTable();
250         return xAccessible;
251     }
commitHeaderBarEvent(sal_Int16 nEventId,const css::uno::Any & rNewValue,const css::uno::Any & rOldValue,bool _bColumnHeaderBar)252     virtual void commitHeaderBarEvent( sal_Int16 nEventId, const css::uno::Any& rNewValue,
253         const css::uno::Any& rOldValue, bool _bColumnHeaderBar ) override
254     {
255         AccessibleBrowseBox* pContext( getContext() );
256         if ( pContext )
257             pContext->commitHeaderBarEvent( nEventId, rNewValue, rOldValue, _bColumnHeaderBar );
258     }
commitTableEvent(sal_Int16 nEventId,const css::uno::Any & rNewValue,const css::uno::Any & rOldValue)259     virtual void commitTableEvent( sal_Int16 nEventId,
260         const css::uno::Any& rNewValue, const css::uno::Any& rOldValue ) override
261     {
262         AccessibleBrowseBox* pContext( getContext() );
263         if ( pContext )
264             pContext->commitTableEvent( nEventId, rNewValue, rOldValue );
265     }
commitEvent(sal_Int16 nEventId,const css::uno::Any & rNewValue,const css::uno::Any & rOldValue)266     virtual void commitEvent( sal_Int16 nEventId,
267         const css::uno::Any& rNewValue, const css::uno::Any& rOldValue ) override
268     {
269         AccessibleBrowseBox* pContext( getContext() );
270         if ( pContext )
271             pContext->commitEvent( nEventId, rNewValue, rOldValue );
272     }
273 
274 private:
275     AccessibleBrowseBoxAccess( const AccessibleBrowseBoxAccess& ) = delete;
276     AccessibleBrowseBoxAccess& operator=( const AccessibleBrowseBoxAccess& ) = delete;
277 };
278 
279 
280 } // namespace accessibility
281 
282 
283 #endif
284 
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
286