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