/src/libreoffice/include/vcl/accessibility/AccessibleBrowseBoxBase.hxx
Line | Count | Source |
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 | | #pragma once |
22 | | |
23 | | #include <sal/config.h> |
24 | | |
25 | | #include <rtl/ustring.hxx> |
26 | | #include <vcl/svapp.hxx> |
27 | | #include <com/sun/star/lang/XServiceInfo.hpp> |
28 | | #include <com/sun/star/awt/XFocusListener.hpp> |
29 | | #include <comphelper/OAccessible.hxx> |
30 | | |
31 | | |
32 | | enum class AccessibleBrowseBoxObjType; |
33 | | namespace com::sun::star::accessibility { class XAccessible; } |
34 | | namespace com::sun::star::awt { class XWindow; } |
35 | | namespace com::sun::star::uno { class Any; } |
36 | | namespace tools { class Rectangle; } |
37 | | |
38 | | namespace vcl { |
39 | | class IAccessibleTableProvider; |
40 | | } |
41 | | |
42 | | /** The BrowseBox accessible objects inherit from this base class. It |
43 | | implements basic functionality for various Accessibility interfaces. */ |
44 | | class VCL_DLLPUBLIC AccessibleBrowseBoxBase |
45 | | : public cppu::ImplInheritanceHelper<comphelper::OAccessible, css::awt::XFocusListener, |
46 | | css::lang::XServiceInfo> |
47 | | { |
48 | | public: |
49 | | /** Constructor sets specified name and description. If the constant of a |
50 | | text is BBTEXT_NONE, the derived class has to set the text via |
51 | | implSetName() (in Ctor) or later via |
52 | | setAccessibleName() and setAccessibleDescription() (these methods |
53 | | notify the listeners about the change). |
54 | | |
55 | | @param rxParent XAccessible interface of the parent object. |
56 | | @param rBrowseBox The BrowseBox control. |
57 | | @param _xFocusWindow The window that gets all the focus events. |
58 | | @param eObjType Object type */ |
59 | | AccessibleBrowseBoxBase( |
60 | | const css::uno::Reference<css::accessibility::XAccessible>& xParent, |
61 | | ::vcl::IAccessibleTableProvider& rBrowseBox, |
62 | | const css::uno::Reference<css::awt::XWindow>& xFocusWindow, |
63 | | AccessibleBrowseBoxObjType eObjType ); |
64 | | |
65 | | /** Constructor sets specified name and description. |
66 | | @param rxParent XAccessible interface of the parent object. |
67 | | @param rBrowseBox The BrowseBox control. |
68 | | @param _xFocusWindow The window that gets all the focus events. |
69 | | @param eObjType Object type |
70 | | @param rName The name of this object. |
71 | | @param rDescription The description text of this object. */ |
72 | | AccessibleBrowseBoxBase( |
73 | | css::uno::Reference< css::accessibility::XAccessible > xParent, |
74 | | ::vcl::IAccessibleTableProvider& rBrowseBox, |
75 | | css::uno::Reference< css::awt::XWindow > _xFocusWindow, |
76 | | AccessibleBrowseBoxObjType eObjType, |
77 | | OUString rName, |
78 | | OUString rDescription ); |
79 | | |
80 | | protected: |
81 | | AccessibleBrowseBoxBase(const AccessibleBrowseBoxBase&) = delete; |
82 | | AccessibleBrowseBoxBase& operator=(const AccessibleBrowseBoxBase&) = delete; |
83 | | |
84 | | /** Commits DeFunc event to listeners and cleans up members. */ |
85 | | virtual void SAL_CALL disposing() override; |
86 | | |
87 | | virtual css::awt::Rectangle implGetBounds() override; |
88 | | |
89 | | public: |
90 | | // XAccessibleContext |
91 | | /** @return A reference to the parent accessible object. */ |
92 | | virtual css::uno::Reference<css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override; |
93 | | |
94 | | /** @return |
95 | | The description of this object. |
96 | | */ |
97 | | virtual OUString SAL_CALL getAccessibleDescription() override; |
98 | | |
99 | | /** @return |
100 | | The name of this object. |
101 | | */ |
102 | | virtual OUString SAL_CALL getAccessibleName() override; |
103 | | |
104 | | /** @return |
105 | | The relation set (the BrowseBox does not have one). |
106 | | */ |
107 | | virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override; |
108 | | |
109 | | /** @return The set of current states. */ |
110 | | virtual sal_Int64 SAL_CALL getAccessibleStateSet() override; |
111 | | |
112 | | /** @return The parent's locale. */ |
113 | | virtual css::lang::Locale SAL_CALL getLocale() override; |
114 | | |
115 | | /** @return |
116 | | The role of this object. Panel, ROWHEADER, COLUMNHEADER, TABLE, TABLE_CELL are supported. |
117 | | */ |
118 | | virtual sal_Int16 SAL_CALL getAccessibleRole() override; |
119 | | |
120 | | /* Derived classes have to implement: |
121 | | - getAccessibleChildCount, |
122 | | - getAccessibleChild, |
123 | | - getAccessibleRole. |
124 | | Derived classes may overwrite getAccessibleIndexInParent to increase |
125 | | performance. */ |
126 | | |
127 | | // XAccessibleComponent |
128 | | |
129 | | virtual sal_Int32 SAL_CALL getForeground( ) override; |
130 | | virtual sal_Int32 SAL_CALL getBackground( ) override; |
131 | | |
132 | | // XFocusListener |
133 | | virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; |
134 | | virtual void SAL_CALL focusGained( const css::awt::FocusEvent& e ) override; |
135 | | virtual void SAL_CALL focusLost( const css::awt::FocusEvent& e ) override; |
136 | | |
137 | | /* Derived classes have to implement: |
138 | | - getAccessibleAt, |
139 | | - grabFocus. */ |
140 | | |
141 | | /** @return |
142 | | The accessible child rendered under the given point. |
143 | | */ |
144 | | virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& rPoint ) override; |
145 | | |
146 | | // XServiceInfo |
147 | | |
148 | | /** @return Whether the specified service is supported by this class. */ |
149 | | virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override; |
150 | | |
151 | | /** @return A list of all supported services. */ |
152 | | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
153 | | |
154 | | /* Derived classes have to implement: |
155 | | - getImplementationName. */ |
156 | | |
157 | | // helper methods |
158 | | |
159 | | /** @return The BrowseBox object type. */ |
160 | | inline AccessibleBrowseBoxObjType getType() const; |
161 | | |
162 | | /** Changes the name of the object and notifies listeners. */ |
163 | | void setAccessibleName( const OUString& rName ); |
164 | | /** Changes the description of the object and notifies listeners. */ |
165 | | void setAccessibleDescription( const OUString& rDescription ); |
166 | | |
167 | | /** Commits an event to all listeners. */ |
168 | | void commitEvent( |
169 | | sal_Int16 nEventId, |
170 | | const css::uno::Any& rNewValue, |
171 | | const css::uno::Any& rOldValue ); |
172 | | /** @return TRUE, if the object is not disposed or disposing. */ |
173 | | bool isAlive() const; |
174 | | |
175 | | protected: |
176 | | // internal virtual methods |
177 | | |
178 | | /** Determines whether the BrowseBox control is really showing inside of |
179 | | its parent accessible window. Derived classes may implement different |
180 | | behaviour. |
181 | | @attention This method requires locked mutex's and a living object. |
182 | | @return TRUE, if the object is really showing. */ |
183 | | bool implIsShowing(); |
184 | | |
185 | | /** Derived classes return the bounding box relative to the parent window. |
186 | | @attention This method requires locked mutex's and a living object. |
187 | | @return The bounding box (VCL rect.) relative to the parent window. */ |
188 | | virtual tools::Rectangle implGetBoundingBox() = 0; |
189 | | |
190 | | /** Creates a bitset of states of the |
191 | | current object. This method calls FillStateSet at the BrowseBox which |
192 | | fills it with more states depending on the object type. Derived classes |
193 | | may overwrite this method and add more states. |
194 | | @attention This method requires locked mutex's. |
195 | | */ |
196 | | virtual sal_Int64 implCreateStateSet(); |
197 | | |
198 | | // internal helper methods |
199 | | |
200 | | /** Changes the name of the object (flat assignment, no notify). |
201 | | @attention This method requires a locked mutex. */ |
202 | | inline void implSetName( const OUString& rName ); |
203 | | |
204 | | public: |
205 | | /** @return The osl::Mutex member provided by the class BaseMutex. */ |
206 | 0 | ::osl::Mutex& getMutex( ) { return m_aMutex; } |
207 | | |
208 | | /** @throws <type>DisposedException</type> If the object is not alive. */ |
209 | | void ensureIsAlive() const; |
210 | | |
211 | | |
212 | | protected: |
213 | | // members |
214 | | |
215 | | /** The parent accessible object. */ |
216 | | css::uno::Reference< css::accessibility::XAccessible > mxParent; |
217 | | /** The VCL BrowseBox control. */ |
218 | | ::vcl::IAccessibleTableProvider* mpBrowseBox; |
219 | | |
220 | | /** This is the window which get all the nice focus events |
221 | | */ |
222 | | css::uno::Reference< css::awt::XWindow > m_xFocusWindow; |
223 | | |
224 | | private: |
225 | | /** Localized name. */ |
226 | | OUString maName; |
227 | | /** Localized description text. */ |
228 | | OUString maDescription; |
229 | | |
230 | | /** The type of this object (for names, descriptions, state sets, ...). */ |
231 | | AccessibleBrowseBoxObjType meObjType; |
232 | | }; |
233 | | |
234 | | // a helper class for protecting methods which need to lock the solar mutex in addition to the own mutex |
235 | | |
236 | | class SolarMethodGuard : public SolarMutexGuard, public osl::MutexGuard |
237 | | { |
238 | | public: |
239 | | SolarMethodGuard( osl::Mutex& rMutex ) |
240 | 0 | :SolarMutexGuard( ) |
241 | 0 | ,osl::MutexGuard( rMutex ) |
242 | 0 | { |
243 | 0 | } |
244 | | }; |
245 | | |
246 | | // inlines |
247 | | |
248 | | inline AccessibleBrowseBoxObjType AccessibleBrowseBoxBase::getType() const |
249 | 0 | { |
250 | 0 | return meObjType; |
251 | 0 | } |
252 | | |
253 | | inline void AccessibleBrowseBoxBase::implSetName( |
254 | | const OUString& rName ) |
255 | 0 | { |
256 | 0 | maName = rName; |
257 | 0 | } |
258 | | |
259 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |