Avoid potential negative array index access to cached text.
[LibreOffice.git] / accessibility / inc / extended / AccessibleBrowseBox.hxx
blobb7e912df6e926ee3e05f68ca96a5588eef6f8369
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #pragma once
23 #include <extended/AccessibleBrowseBoxBase.hxx>
24 #include <cppuhelper/weakref.hxx>
25 #include <vcl/accessibletableprovider.hxx>
26 #include <mutex>
28 namespace accessibility {
30 class AccessibleBrowseBoxHeaderBar;
31 class AccessibleBrowseBoxTable;
34 /** This class represents the complete accessible BrowseBox object. */
35 class AccessibleBrowseBox : public AccessibleBrowseBoxBase
37 friend class AccessibleBrowseBoxAccess;
39 protected:
40 AccessibleBrowseBox(
41 const css::uno::Reference< css::accessibility::XAccessible >& _rxParent,
42 const css::uno::Reference< css::accessibility::XAccessible >& _rxCreator,
43 ::vcl::IAccessibleTableProvider& _rBrowseBox
46 virtual ~AccessibleBrowseBox() override;
48 /** sets the XAccessible which created the context
50 To be called only once, and only if in the ctor NULL was passed.
52 void setCreator(
53 const css::uno::Reference< css::accessibility::XAccessible >& _rxCreator
56 /** Cleans up members. */
57 using AccessibleBrowseBoxBase::disposing;
58 virtual void SAL_CALL disposing() override;
60 protected:
61 // XAccessibleContext
63 /** @return The count of visible children. */
64 virtual sal_Int64 SAL_CALL getAccessibleChildCount() override;
66 /** @return The XAccessible interface of the specified child. */
67 virtual css::uno::Reference<
68 css::accessibility::XAccessible > SAL_CALL
69 getAccessibleChild( sal_Int64 nChildIndex ) override;
71 // XAccessibleComponent
73 /** @return
74 The accessible child rendered under the given point.
76 virtual css::uno::Reference<
77 css::accessibility::XAccessible > SAL_CALL
78 getAccessibleAtPoint( const css::awt::Point& rPoint ) override;
80 /** Grabs the focus to the BrowseBox. */
81 virtual void SAL_CALL grabFocus() override;
83 // XServiceInfo
85 /** @return
86 The name of this class.
88 virtual OUString SAL_CALL getImplementationName() override;
90 public:
91 // helper functions
92 /** commitHeaderBarEvent commit the event at all listeners of the column/row header bar
93 @param nEventId
94 the event id
95 @param rNewValue
96 the new value
97 @param rOldValue
98 the old value
99 @param _bColumnHeaderBar
100 true if a column based header bar, false if a row based header bar
102 void commitHeaderBarEvent(sal_Int16 nEventId,
103 const css::uno::Any& rNewValue,
104 const css::uno::Any& rOldValue, bool _bColumnHeaderBar);
106 // helper functions
107 /** commitTableEvent commit the event at all listeners of the table
108 @param nEventId
109 the event id
110 @param rNewValue
111 the new value
112 @param rOldValue
113 the old value
115 void commitTableEvent(sal_Int16 nEventId,
116 const css::uno::Any& rNewValue,
117 const css::uno::Any& rOldValue);
119 /** returns the accessible object for the row or the column header bar
121 css::uno::Reference<
122 css::accessibility::XAccessible >
123 getHeaderBar( AccessibleBrowseBoxObjType _eObjType )
125 return implGetHeaderBar(_eObjType);
128 /** returns the accessible object for the table representation
130 css::uno::Reference<
131 css::accessibility::XAccessible >
132 getTable( )
134 return implGetTable();
137 protected:
138 // internal virtual methods
140 /** @attention This method requires locked mutex's and a living object.
141 @return The bounding box (VCL rect.) relative to the parent window. */
142 virtual tools::Rectangle implGetBoundingBox() override;
143 /** @attention This method requires locked mutex's and a living object.
144 @return The bounding box (VCL rect.) in screen coordinates. */
145 virtual AbsoluteScreenPixelRectangle implGetBoundingBoxOnScreen() override;
147 // internal helper methods
149 /** This method creates (once) and returns the accessible data table child.
150 @attention This method requires locked mutex's and a living object.
151 @return The XAccessible interface of the data table. */
152 css::uno::Reference<
153 css::accessibility::XAccessible > implGetTable();
155 /** This method creates (once) and returns the specified header bar.
156 @attention This method requires locked mutex's and a living object.
157 @return The XAccessible interface of the header bar. */
158 css::uno::Reference<
159 css::accessibility::XAccessible >
160 implGetHeaderBar( AccessibleBrowseBoxObjType eObjType );
162 /** This method returns one of the children that are always present:
163 Data table, row and column header bar or corner control.
164 @attention This method requires locked mutex's and a living object.
165 @return The XAccessible interface of the specified child. */
166 css::uno::Reference<
167 css::accessibility::XAccessible >
168 implGetFixedChild( sal_Int64 nChildIndex );
170 /** This method creates and returns an accessible table.
171 @return An AccessibleBrowseBoxTable. */
172 virtual rtl::Reference<AccessibleBrowseBoxTable> createAccessibleTable();
174 private:
175 /// the css::accessibility::XAccessible which created the AccessibleBrowseBox
176 css::uno::WeakReference< css::accessibility::XAccessible > m_aCreator;
178 /** The data table child. */
179 rtl::Reference<AccessibleBrowseBoxTable> mxTable;
181 /** The header bar for rows ("handle column"). */
182 rtl::Reference<AccessibleBrowseBoxHeaderBar> mxRowHeaderBar;
184 /** The header bar for columns (first row of the table). */
185 rtl::Reference<AccessibleBrowseBoxHeaderBar> mxColumnHeaderBar;
189 /** the XAccessible which creates/returns an AccessibleBrowseBox
191 The instance holds its XAccessibleContext with a hard reference, while
192 the context holds this instance weak.
194 class AccessibleBrowseBoxAccess final : public ::vcl::IAccessibleBrowseBox
196 private:
197 std::mutex m_aMutex;
198 css::uno::Reference< css::accessibility::XAccessible >
199 m_xParent;
200 ::vcl::IAccessibleTableProvider& m_rBrowseBox;
202 rtl::Reference<AccessibleBrowseBox> m_xContext;
204 public:
205 AccessibleBrowseBoxAccess(
206 css::uno::Reference< css::accessibility::XAccessible > _xParent,
207 ::vcl::IAccessibleTableProvider& _rBrowseBox
210 /// returns the AccessibleContext belonging to this Accessible
211 AccessibleBrowseBox* getContext() { return m_xContext.get(); }
213 private:
214 virtual ~AccessibleBrowseBoxAccess() override;
216 // XAccessible
217 virtual css::uno::Reference< css::accessibility::XAccessibleContext >
218 SAL_CALL getAccessibleContext() override;
220 // IAccessibleBrowseBox
221 void dispose() override;
222 virtual bool isAlive() const override
224 return m_xContext.is() && m_xContext->isAlive();
226 virtual css::uno::Reference< css::accessibility::XAccessible >
227 getHeaderBar( AccessibleBrowseBoxObjType _eObjType ) override
229 css::uno::Reference< css::accessibility::XAccessible > xAccessible;
230 AccessibleBrowseBox* pContext( getContext() );
231 if ( pContext )
232 xAccessible = pContext->getHeaderBar( _eObjType );
233 return xAccessible;
235 virtual css::uno::Reference< css::accessibility::XAccessible >
236 getTable() override
238 css::uno::Reference< css::accessibility::XAccessible > xAccessible;
239 AccessibleBrowseBox* pContext( getContext() );
240 if ( pContext )
241 xAccessible = pContext->getTable();
242 return xAccessible;
244 virtual void commitHeaderBarEvent( sal_Int16 nEventId, const css::uno::Any& rNewValue,
245 const css::uno::Any& rOldValue, bool _bColumnHeaderBar ) override
247 AccessibleBrowseBox* pContext( getContext() );
248 if ( pContext )
249 pContext->commitHeaderBarEvent( nEventId, rNewValue, rOldValue, _bColumnHeaderBar );
251 virtual void commitTableEvent( sal_Int16 nEventId,
252 const css::uno::Any& rNewValue, const css::uno::Any& rOldValue ) override
254 AccessibleBrowseBox* pContext( getContext() );
255 if ( pContext )
256 pContext->commitTableEvent( nEventId, rNewValue, rOldValue );
258 virtual void commitEvent( sal_Int16 nEventId,
259 const css::uno::Any& rNewValue, const css::uno::Any& rOldValue ) override
261 AccessibleBrowseBox* pContext( getContext() );
262 if ( pContext )
263 pContext->commitEvent( nEventId, rNewValue, rOldValue );
266 private:
267 AccessibleBrowseBoxAccess( const AccessibleBrowseBoxAccess& ) = delete;
268 AccessibleBrowseBoxAccess& operator=( const AccessibleBrowseBoxAccess& ) = delete;
272 } // namespace accessibility
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */