Avoid potential negative array index access to cached text.
[LibreOffice.git] / accessibility / inc / extended / AccessibleGridControl.hxx
bloba1f7815ce16773c7ee48adb934775bdc87b1ba6e
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 .
20 #pragma once
22 #include <extended/AccessibleGridControlBase.hxx>
23 #include <extended/AccessibleGridControlTable.hxx>
24 #include <cppuhelper/weakref.hxx>
25 #include <rtl/ref.hxx>
26 #include <vcl/accessibletable.hxx>
28 namespace accessibility {
30 class AccessibleGridControlHeader;
33 /** This class represents the complete accessible Grid Control object. */
34 class AccessibleGridControl final : public AccessibleGridControlBase
36 friend class AccessibleGridControlAccess;
38 AccessibleGridControl(
39 const css::uno::Reference< css::accessibility::XAccessible >& _rxParent,
40 const css::uno::Reference< css::accessibility::XAccessible >& _rxCreator,
41 ::vcl::table::IAccessibleTable& _rTable
44 virtual ~AccessibleGridControl() override = default;
46 /** Cleans up members. */
47 using AccessibleGridControlBase::disposing;
48 virtual void SAL_CALL disposing() override;
50 // XAccessibleContext -----------------------------------------------------
52 /** @return The count of visible children. */
53 virtual sal_Int64 SAL_CALL getAccessibleChildCount() override;
55 /** @return The XAccessible interface of the specified child. */
56 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
57 getAccessibleChild( sal_Int64 nChildIndex ) override;
59 /** @return The role of this object (a table). */
60 virtual sal_Int16 SAL_CALL getAccessibleRole() override;
62 // XAccessibleComponent ---------------------------------------------------
64 /** @return
65 The accessible child rendered under the given point.
67 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
68 getAccessibleAtPoint( const css::awt::Point& rPoint ) override;
70 /** Grabs the focus to the Grid Control. */
71 virtual void SAL_CALL grabFocus() override;
73 // XServiceInfo -----------------------------------------------------------
75 /** @return
76 The name of this class.
78 virtual OUString SAL_CALL getImplementationName() override;
80 public:
81 // helper functions
83 /** commitCellEvent commit the event at all listeners of the table
84 @param nEventId
85 the event id
86 @param rNewValue
87 the new value
88 @param rOldValue
89 the old value
91 void commitCellEvent(sal_Int16 nEventId, const css::uno::Any& rNewValue,
92 const css::uno::Any& rOldValue);
94 /** commitTableEvent commit the event at all listeners of the table
95 @param nEventId
96 the event id
97 @param rNewValue
98 the new value
99 @param rOldValue
100 the old value
102 void commitTableEvent(sal_Int16 nEventId, const css::uno::Any& rNewValue,
103 const css::uno::Any& rOldValue);
105 private:
106 // internal virtual methods -----------------------------------------------
108 /** @attention This method requires locked mutex's and a living object.
109 @return The bounding box (VCL rect.) relative to the parent window. */
110 virtual tools::Rectangle implGetBoundingBox() override;
111 /** @attention This method requires locked mutex's and a living object.
112 @return The bounding box (VCL rect.) in screen coordinates. */
113 virtual AbsoluteScreenPixelRectangle implGetBoundingBoxOnScreen() override;
115 // internal helper methods ------------------------------------------------
117 /** This method creates (once) and returns the accessible data table child.
118 @attention This method requires locked mutex's and a living object.
119 @return The XAccessible interface of the data table. */
120 css::uno::Reference< css::accessibility::XAccessible > implGetTable();
122 /** This method creates (once) and returns the specified header bar.
123 @attention This method requires locked mutex's and a living object.
124 @return The XAccessible interface of the header bar. */
125 css::uno::Reference< css::accessibility::XAccessible >
126 implGetHeaderBar( ::vcl::table::AccessibleTableControlObjType eObjType );
128 /** This method returns one of the children that are always present:
129 Data table, row and column header bar or corner control.
130 @attention This method requires locked mutex's and a living object.
131 @return The XAccessible interface of the specified child. */
132 css::uno::Reference< css::accessibility::XAccessible >
133 implGetFixedChild( sal_Int64 nChildIndex );
135 /** This method creates and returns an accessible table.
136 @return An AccessibleGridControlTable. */
137 rtl::Reference<AccessibleGridControlTable> createAccessibleTable();
139 /// the css::accessibility::XAccessible which created the AccessibleGridControl
140 css::uno::WeakReference< css::accessibility::XAccessible > m_aCreator;
142 /** The data table child. */
143 rtl::Reference<AccessibleGridControlTable> m_xTable;
145 /** The header bar for rows. */
146 rtl::Reference<AccessibleGridControlHeader> m_xRowHeaderBar;
148 /** The header bar for columns (first row of the table). */
149 rtl::Reference<AccessibleGridControlHeader> m_xColumnHeaderBar;
151 /** @return The count of visible children. */
152 inline sal_Int64 implGetAccessibleChildCount();
156 /** the XAccessible which creates/returns an AccessibleGridControl
158 <p>The instance holds its XAccessibleContext with a hard reference, while
159 the context holds this instance weak.</p>
162 class AccessibleGridControlAccess final : public ::vcl::table::IAccessibleTableControl
164 private:
165 css::uno::Reference< css::accessibility::XAccessible > m_xParent;
166 ::vcl::table::IAccessibleTable * m_pTable;
167 rtl::Reference<AccessibleGridControl> m_xContext;
169 public:
170 AccessibleGridControlAccess(
171 css::uno::Reference< css::accessibility::XAccessible > _xParent,
172 ::vcl::table::IAccessibleTable& _rTable
175 /// returns the AccessibleContext belonging to this Accessible
176 AccessibleGridControl* getContext() { return m_xContext.get(); }
178 private:
179 virtual ~AccessibleGridControlAccess() override;
181 // XAccessible
182 virtual css::uno::Reference< css::accessibility::XAccessibleContext >
183 SAL_CALL getAccessibleContext() override;
185 // IAccessibleTable
186 void DisposeAccessImpl() override;
187 virtual bool isAlive() const override
189 return m_xContext.is() && m_xContext->isAlive();
191 virtual void commitCellEvent( sal_Int16 nEventId,
192 const css::uno::Any& rNewValue, const css::uno::Any& rOldValue ) override
194 AccessibleGridControl* pContext( getContext() );
195 if ( pContext )
196 pContext->commitCellEvent( nEventId, rNewValue, rOldValue );
198 virtual void commitTableEvent( sal_Int16 nEventId,
199 const css::uno::Any& rNewValue, const css::uno::Any& rOldValue ) override
201 AccessibleGridControl* pContext( getContext() );
202 if ( pContext )
203 pContext->commitTableEvent( nEventId, rNewValue, rOldValue );
205 virtual void commitEvent( sal_Int16 nEventId,
206 const css::uno::Any& rNewValue ) override
208 AccessibleGridControl* pContext( getContext() );
209 if ( pContext )
210 pContext->commitEvent( nEventId, rNewValue, css::uno::Any() );
213 private:
214 AccessibleGridControlAccess( const AccessibleGridControlAccess& ) = delete;
215 AccessibleGridControlAccess& operator=( const AccessibleGridControlAccess& ) = delete;
219 } // namespace accessibility
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */