Avoid potential negative array index access to cached text.
[LibreOffice.git] / accessibility / inc / standard / vclxaccessiblelist.hxx
blob7bfb83c7e386df5cdcff87018447fed2da0e3cdc
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 <memory>
23 #include <vector>
24 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
25 #include <cppuhelper/implbase.hxx>
26 #include <toolkit/awt/vclxaccessiblecomponent.hxx>
28 class VCLXAccessibleListItem;
30 namespace accessibility
32 class IComboListBoxHelper;
36 /** Base class for the list contained in list- and combo boxes. This class
37 does not support selection because lists of combo boxes give no direct
38 access to their underlying list implementation. Look into derived
39 classes for selection.
41 class VCLXAccessibleList final
42 : public cppu::ImplInheritanceHelper<
43 VCLXAccessibleComponent,
44 css::accessibility::XAccessible,
45 css::accessibility::XAccessibleSelection>
47 public:
48 enum BoxType {COMBOBOX, LISTBOX};
50 VCLXAccessibleList (VCLXWindow* pVCLXindow, BoxType aBoxType,
51 const css::uno::Reference<
52 css::accessibility::XAccessible >& _xParent);
54 /** The index that is passed to this method is returned on following
55 calls to getAccessibleIndexInParent.
57 void SetIndexInParent (sal_Int32 nIndex);
59 /** Process some of the events and delegate the rest to the base classes.
61 virtual void ProcessWindowEvent (const VclWindowEvent& rVclWindowEvent) override;
62 virtual void FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet ) override;
64 /** Called on reception of selection events this method checks all known
65 list items for a possible change in their selection state and
66 updates that accordingly. No accessibility events are sent because
67 the XAccessibleSelection interface is not supported and the items
68 are transient.
69 @param sTextOfSelectedItem
70 This string contains the text of the currently selected
71 item. It is used to retrieve the index of that item.
73 void UpdateSelection (std::u16string_view sTextOfSelectedItem);
75 // XAccessible
76 virtual css::uno::Reference< css::accessibility::XAccessibleContext> SAL_CALL
77 getAccessibleContext() override;
79 // XAccessibleContext
80 virtual sal_Int64 SAL_CALL getAccessibleChildCount() override final;
81 css::uno::Reference< css::accessibility::XAccessible> SAL_CALL
82 getAccessibleChild (sal_Int64 i) override;
83 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
84 getAccessibleParent( ) override;
86 /** The index returned as index in parent is always the one set with the
87 SetIndexInParent() method.
89 virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override;
90 virtual sal_Int16 SAL_CALL getAccessibleRole() override;
92 // XServiceInfo
93 virtual OUString SAL_CALL getImplementationName() override;
94 // Return list specific services.
95 virtual css::uno::Sequence< OUString > SAL_CALL
96 getSupportedServiceNames() override;
98 // XAccessibleSelection
99 virtual void SAL_CALL selectAccessibleChild( sal_Int64 nChildIndex ) override;
100 virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int64 nChildIndex ) override;
101 virtual void SAL_CALL clearAccessibleSelection( ) override;
102 virtual void SAL_CALL selectAllAccessibleChildren( ) override;
103 virtual sal_Int64 SAL_CALL getSelectedAccessibleChildCount( ) override;
104 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex ) override;
105 virtual void SAL_CALL deselectAccessibleChild( sal_Int64 nSelectedChildIndex ) override;
107 virtual css::awt::Point SAL_CALL getLocationOnScreen( ) override;
108 bool IsInDropDown() const;
109 void HandleDropOpen();
110 void ProcessWindowEvent (const VclWindowEvent& rVclWindowEvent, bool b_IsDropDownList);
111 void UpdateSelection_Acc (std::u16string_view sTextOfSelectedItem, bool b_IsDropDownList);
112 void UpdateSelection_Impl_Acc (bool b_IsDropDownList);
114 static void NotifyListItem(css::uno::Any const & val);
115 ::accessibility::IComboListBoxHelper* getListBoxHelper() { return m_pListBoxHelper.get(); }
116 private:
117 BoxType m_aBoxType;
118 std::unique_ptr<::accessibility::IComboListBoxHelper> m_pListBoxHelper;
119 std::vector<rtl::Reference<VCLXAccessibleListItem>> m_aAccessibleChildren;
120 sal_Int32 m_nVisibleLineCount;
121 /// Index in parent. This is settable from the outside.
122 sal_Int32 m_nIndexInParent;
123 sal_Int32 m_nLastTopEntry;
124 sal_Int32 m_nLastSelectedPos;
125 bool m_bDisableProcessEvent;
126 bool m_bVisible;
127 sal_Int32 m_nCurSelectedPos;
130 virtual ~VCLXAccessibleList() override = default;
132 sal_Int64 implGetAccessibleChildCount();
134 /** This function is called from the implementation helper during a
135 XComponent::dispose call. Free the list of items and the items themselves.
137 virtual void SAL_CALL disposing() override;
139 void disposeChildren();
141 /** This method adds the states
142 AccessibleStateType::FOCUSABLE and possibly
143 AccessibleStateType::MULTI_SELECTABLE to the state set
144 of the base classes.
146 virtual void FillAccessibleStateSet (sal_Int64& rStateSet) override;
148 /** Create the specified child and insert it into the list of children.
149 Sets the child's states.
151 rtl::Reference<VCLXAccessibleListItem> CreateChild (sal_Int32 i);
153 /** Call this method when the item list has been changed, i.e. items
154 have been deleted or inserted.
156 void HandleChangedItemList();
158 // VCLXAccessibleComponent
159 virtual css::awt::Rectangle implGetBounds( ) override;
161 /** We need to save the accessible parent to return it in getAccessibleParent(),
162 because this method of the base class returns the wrong parent.
164 css::uno::Reference< css::accessibility::XAccessible > m_xParent;
166 void UpdateEntryRange_Impl();
167 void UpdateSelection_Impl(sal_Int32 nPos = 0);
168 bool checkEntrySelected(sal_Int32 _nPos,
169 css::uno::Any& _rNewValue,
170 css::uno::Reference< css::accessibility::XAccessible >& _rxNewAcc);
171 void notifyVisibleStates(bool _bSetNew );
172 void UpdateVisibleLineCount();
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */