1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_SVX_ACCESSIBLETEXTHELPER_HXX
21 #define INCLUDED_SVX_ACCESSIBLETEXTHELPER_HXX
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <sal/types.h>
28 #include <svx/svxdllapi.h>
30 namespace com
{ namespace sun
{ namespace star
{
31 namespace accessibility
{ class XAccessible
; }
32 namespace accessibility
{ class XAccessibleEventListener
; }
33 namespace awt
{ struct Point
; }
39 namespace accessibility
42 class AccessibleTextHelper_Impl
;
44 /** Helper class for objects containing EditEngine/Outliner text
46 This class provides the methods from the XAccessibleContext,
47 XAccessibleEventBroadcaster and XAccessibleComponent
48 interfaces, that are common to all accessible objects
49 containing an edit engine.
51 The text contained in the EditEngine/Outliner is presented as
52 children of this class, namely for every text paragraph a
53 AccessibleEditableTextPara child object is generated. As this
54 class manages these children for itself, it has to send out
55 AccessibleEventId::CHILD events on your
56 behalf. Thus, you must forward every call to your
57 addEventListener()/removeEventListener() methods to the
58 AccessibleTextHelper (methods
59 AddEventListener/RemoveEventListener), otherwise none or not
60 every one of your event listener will notice child changes.
62 You have to implement the SvxEditSource, SvxTextForwarder,
63 SvxViewForwarder and SvxEditViewForwarder interfaces in order
64 to enable your object to cooperate with this
65 class. SvxTextForwarder encapsulates the fact that text
66 objects do not necessarily have an EditEngine at their
67 disposal, SvxViewForwarder and SvxEditViewForwarder do the
68 same for the document and the edit view. The three mentioned
69 forwarder objects are not stored by the AccessibleTextHelper,
70 but fetched every time from the SvxEditSource. So you are best
71 off making your SvxEditSource::Get*Forwarder methods cache the
74 To support changes in edit mode or conversion of fixed text
75 into EditEngine text, you can change the SvxEditSource this
76 class is referring to. This might render all children invalid
77 and change the child count, since the AccessibleTextHelper
78 reinitializes itself from scratch.
80 This class registers itself at the SvxEditSource as a state
81 listener and manages the state of its children (i.e. the
82 paragraphs). See the method documentation of
83 AccessibleTextHelper::SetEditSource for the expected
84 events. Generally, be prepared that when sending any of these
85 events via SvxEditSource::GetBroadcaster() broadcaster, the
86 AccessibleTextHelper will call the SvxEditSource and their
87 forwarder to update it's state. Avoid being inconsistent in
88 the facts you tell in the events, e.g. when sending a
89 SfxHintId::TextParaInserted event, the
90 SvxEditSource::GetTextForwarder().GetParagraphCount() should
91 already include the newly inserted paragraph.
93 @attention All public methods must not be called with any
94 mutex hold, except when calling from the main thread (with
95 holds the solar mutex), unless stated otherwise. This is
96 because they themselves might need the solar mutex in addition
97 to the object mutex, and the ordering of the locking must be:
98 first solar mutex, then object mutex. Furthermore, state
99 change events might be fired internally.
101 @derive Use this class in an aggregation and forward, or
102 derive from it and overwrite.
106 @see SvxTextForwarder
107 @see SvxViewForwarder
108 @see SvxEditViewForwarder
110 class SVX_DLLPUBLIC AccessibleTextHelper final
114 typedef ::std::vector
< sal_Int16
> VectorOfStates
;
116 /** Create accessible text object for given edit source
119 The edit source to use. Object ownership is transferred
120 from the caller to the callee. The object listens on the
121 SvxEditSource for object disposal, so no provisions have
122 to be taken if the caller destroys the data (e.g. the
123 model) contained in the given SvxEditSource.
126 explicit AccessibleTextHelper( ::std::unique_ptr
< SvxEditSource
> && pEditSource
);
128 ~AccessibleTextHelper();
130 AccessibleTextHelper( const AccessibleTextHelper
& ) = delete;
131 AccessibleTextHelper
& operator= ( const AccessibleTextHelper
& ) = delete;
133 /** Query the current edit source
135 @attention This method returns by reference, so you are
136 responsible for serialization (typically, you acquired the
137 solar mutex when calling this method). Thus, the method
138 should only be called from the main office thread.
141 const SvxEditSource
& GetEditSource() const;
143 /** Set the current edit source
145 @attention Might fire state change events, therefore,
146 don't hold any mutex except solar mutex, which you are
147 required to lock before. This method should only be called
148 from the main office thread.
150 The EditSource set here is required to broadcast out the
151 following hints: SfxHintId::EditSourceParasMoved,
152 SfxHintId::EditSourceSelectionChanged, SfxHintId::TextModified,
153 SfxHintId::TextParaInserted, SfxHintId::TextParaRemoved,
154 SfxHintId::TextHeightChanged,
155 SfxHintId::TextViewScrolled. Otherwise, not all state changes
156 will get noticed by the accessibility object. Further
157 more, when the corresponding core object or the model is
158 dying, either the edit source must be set to NULL or it
159 has to broadcast a SfxHintId::Dying hint.
161 If the SvxEditSource's managed text can change between
162 edit/non-edit mode (i.e. there are times when
163 SvxEditSource::GetEditViewForwarder(sal_False) returns
164 NULL), then the two additional hints are required:
165 SdrHintKind::BeginEdit and SdrHintKind::EndEdit. When the
166 AccessibleTextHelper receives a SdrHintKind::BeginEdit, it expects
167 the SvxEditSource already in edit mode. On a SdrHintKind::EndEdit,
168 edit mode must already been left. The rationale for these
169 events are the fact that focus and selection have to be
170 updated in edit mode, and completely relinquished and
171 reset to the parent (for the focus) in non-edit mode.
173 This class does not have a dispose method, since it is not
174 a UNO component. Nevertheless, it holds C++ references to
175 several core objects, so you should issue a
176 SetEditSource(::std::unique_ptr<SvxEditSource>()) in
177 your dispose() method.
180 The new edit source to set. Object ownership is transferred
181 from the caller to the callee.
183 void SetEditSource( ::std::unique_ptr
< SvxEditSource
> && pEditSource
);
185 /** Set the event source
187 You should set the event source before registering any
188 event listener and before requesting any child. Children
189 of this object receive the event source as their parent
190 accessible object. That is, the event source is best set
191 in your object's init method.
193 @attention When setting a reference here, you should call
194 Dispose() when you as the owner are disposing, since until
195 then this object will hold that reference
198 The interface that should be set as the source for
199 accessibility events sent by this object.
201 void SetEventSource( const css::uno::Reference
< css::accessibility::XAccessible
>& rInterface
);
203 /** Set offset of EditEngine/Outliner from parent
205 If the origin of the underlying EditEngine/Outliner does
206 not correspond to the upper left corner of the object
207 using this class, you have to specify the offset.
209 @attention Might fire state change events, therefore,
210 don't hold any mutex except solar mutex, which you are
211 required to lock before. This method should only be called
212 from the main office thread.
215 The offset in screen coordinates (i.e. pixel)
217 void SetOffset( const Point
& rPoint
);
219 /** Set offset the object adds to all children's indices
221 This can be used if the owner of this object has children
222 handled by itself. Setting an offset different from 0
223 leads to this object mimicking that all its children are
224 within the range [nOffset, GetChildCount()+nOffset). That
225 means, GetChild() also expects the index to be in this
228 @attention Might fire state change events, therefore,
229 don't hold any mutex except solar mutex, which you are
230 required to lock before. This method should only be called
231 from the main office thread.
234 The offset to add to every children's index.
236 void SetStartIndex( sal_Int32 nOffset
);
238 /** Query offset the object adds to all children's indices
240 @return the offset to add to every children's index.
242 sal_Int32
GetStartIndex() const;
244 /** Sets a vector of additional accessible states.
246 The states are passed to every created child object
247 (text paragraph). The state values are defined in
248 css::accessibility::AccessibleStateType.
250 This function has to be called before querying for
251 any children (e.g. with GetChild()).
253 void SetAdditionalChildStates( const VectorOfStates
& rChildStates
);
255 /** Update the visible children
257 @attention Might fire state change events, therefore,
258 don't hold any mutex except solar mutex, which you are
259 required to lock before. This method should only be called
260 from the main office thread.
262 This method reevaluates the visibility of all
263 children. Call this method if your visibility state has
264 changed somehow, e.g. if the visible area has changed and
265 the AccessibleTextHelper isn't notified internally
266 (e.g. via SfxHintId::TextViewScrolled). Normally, there should
267 not be a need to call this method.
269 void UpdateChildren();
271 /** Drop all references and enter disposed state
273 This method drops all references to external objects (also
274 the event source reference set via SetEventSource()) and
275 sets the object into the disposed state (i.e. the methods
276 return default values or throw a uno::DisposedException
281 /** Set the focus state of the accessibility object
283 Since this class handles children which also might get the
284 focus, the user of this class is encouraged to delegate
285 focus handling. Whenever the focus state of the
286 surrounding object changes, this method has to be called.
288 The protocol of focus handling for a user of this class is
289 then to call SetFocus() with the appropriate focus state,
290 and HaveFocus() to determine the focus state you tell the
293 @attention Might fire state change events, therefore,
294 don't hold any mutex except solar mutex, which you are
295 required to lock before. This method should only be called
296 from the main office thread.
299 Whether we got or we lost the focus. Set to true if
300 focus is gotten, false otherwise.
304 void SetFocus( bool bHaveFocus
= true );
306 /** Query the focus state of the surrounding object
308 If focus handling is delegated to this class, determine
309 focus state with this method. Be prepared that even if you
310 set the focus with SetFocus(true), this method might
311 return false. This is the case if one of the children
312 actually got the focus.
314 @return the state of the focus ownership
318 // XAccessibleContext child handling methods
320 /** Implements getAccessibleChildCount
322 @attention Don't call with locked mutexes. You may hold
323 the solar mutex, but this method acquires it anyway.
325 sal_Int32
GetChildCount();
326 /** Implements getAccessibleChild
328 @attention Don't call with locked mutexes. You may hold
329 the solar mutex, but this method acquires it anyway.
331 css::uno::Reference
< css::accessibility::XAccessible
> GetChild( sal_Int32 i
);
333 // XAccessibleEventBroadcaster child related methods
335 /** Implements addEventListener
337 @attention Don't call with locked mutexes
339 void AddEventListener( const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& xListener
);
340 /** Implements removeEventListener
342 @attention Don't call with locked mutexes
344 void RemoveEventListener( const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& xListener
);
346 // XAccessibleComponent child related methods
348 /** Implements getAccessibleAt
350 @attention Don't call with locked mutexes. You may hold
351 the solar mutex, but this method acquires it anyway.
353 css::uno::Reference
< css::accessibility::XAccessible
> GetAt( const css::awt::Point
& aPoint
);
358 const std::unique_ptr
< AccessibleTextHelper_Impl
> mpImpl
;
362 } // end of namespace accessibility
364 #endif // INCLUDED_SVX_ACCESSIBLETEXTHELPER_HXX
366 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */