LibreOffice Module editeng (master) 1
AccessibleParaManager.hxx
Go to the documentation of this file.
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#ifndef INCLUDED_EDITENG_ACCESSIBLEPARAMANAGER_HXX
21#define INCLUDED_EDITENG_ACCESSIBLEPARAMANAGER_HXX
22
23#include <config_options.h>
24#include <vector>
25#include <utility>
26#include <tools/gen.hxx>
27#include <com/sun/star/awt/Rectangle.hpp>
28#include <com/sun/star/uno/Reference.hxx>
30#include <rtl/ref.hxx>
32
33namespace com::sun::star::accessibility { class XAccessible; }
34
35class SvxEditSourceAdapter;
36
37namespace accessibility
38{
39 class AccessibleEditableTextPara;
40
48 template < class UnoType, class CppType > class WeakCppRef
49 {
50 public:
51
52 typedef UnoType UnoInterfaceType;
53 typedef CppType InterfaceType;
54
55 WeakCppRef() : maWeakRef(), maUnsafeRef( nullptr ) {}
56
58 maWeakRef(rImpl.get()),
59 maUnsafeRef(rImpl.get())
60 {
61 }
62
63 // get object with c++ object and hard reference (which
64 // prevents the c++ object from destruction during use)
66 css::uno::Reference<UnoInterfaceType> ref(maWeakRef);
67 return ref.is() ? maUnsafeRef : rtl::Reference<InterfaceType>();
68 }
69
70 // default copy constructor and assignment will do
71 // WeakCppRef( const WeakCppRef& );
72 // WeakCppRef& operator= ( const WeakCppRef& );
73
74 private:
75
76 // the interface, hold weakly
77 css::uno::WeakReference< UnoInterfaceType > maWeakRef;
78
79 // hard ref to c++ class, _only_ valid if maWeakRef.is() is true
81 };
82
83
89 class UNLESS_MERGELIBS(EDITENG_DLLPUBLIC) AccessibleParaManager
90 {
91 public:
93 typedef ::std::pair< WeakPara, css::awt::Rectangle > WeakChild;
94 typedef ::std::pair< css::uno::Reference<
95 css::accessibility::XAccessible > , css::awt::Rectangle > Child;
96 typedef ::std::vector< WeakChild > VectorOfChildren;
97
98 AccessibleParaManager();
99 ~AccessibleParaManager();
100
107 void SetAdditionalChildStates( sal_Int64 nChildStates );
108
115 void SetNum( sal_Int32 nNumParas );
116
118 sal_Int32 GetNum() const;
119
120 // iterators
121 VectorOfChildren::iterator begin();
122 VectorOfChildren::iterator end();
123
125 void SetFocus( sal_Int32 nChild );
126
127 void FireEvent( sal_Int32 nPara,
128 const sal_Int16 nEventId ) const;
129
130 static bool IsReferencable(rtl::Reference<AccessibleEditableTextPara> const & aChild);
131 bool IsReferencable( sal_Int32 nChild ) const;
132 static void ShutdownPara( const WeakChild& rChild );
133
134 Child CreateChild( sal_Int32 nChild,
135 const css::uno::Reference< css::accessibility::XAccessible >& xFrontEnd,
136 SvxEditSourceAdapter& rEditSource,
137 sal_Int32 nParagraphIndex );
138
139 WeakChild GetChild( sal_Int32 nParagraphIndex ) const;
140 bool HasCreatedChild( sal_Int32 nParagraphIndex ) const;
141
142 // forwarder to all paragraphs
144 void SetActive( bool bActive = true );
146 void SetState( const sal_Int64 nStateId );
148 void UnSetState( const sal_Int64 nStateId );
150 void SetEEOffset ( const Point& rOffset );
152 void Dispose ();
153
154 // forwarder to given paragraphs
155
166 void Release( sal_Int32 nStartPara, sal_Int32 nEndPara );
167
178 void FireEvent( sal_Int32 nStartPara,
179 sal_Int32 nEndPara,
180 const sal_Int16 nEventId,
181 const css::uno::Any& rNewValue = css::uno::Any(),
182 const css::uno::Any& rOldValue = css::uno::Any() ) const;
183
194 template < typename Functor > class WeakChildAdapter
195 {
196 public:
197 WeakChildAdapter( Functor& rFunctor ) : mrFunctor(rFunctor) {}
198 void operator()( const WeakChild& rPara )
199 {
200 // retrieve hard reference from weak one
201 auto aHardRef( rPara.first.get() );
202
203 if( aHardRef.is() )
204 mrFunctor( *aHardRef );
205 }
206
207 private:
208 Functor& mrFunctor;
209 };
210
220 template < typename Argument > class MemFunAdapter
221 {
222 public:
223 typedef void (::accessibility::AccessibleEditableTextPara::*FunctionPointer)( Argument );
224
225 MemFunAdapter( FunctionPointer aFunPtr, Argument aArg ) : maFunPtr(aFunPtr), maArg(aArg) {}
226 void operator()( const WeakChild& rPara )
227 {
228 // retrieve hard reference from weak one
229 auto aHardRef( rPara.first.get() );
230
231 if( aHardRef.is() )
232 (*aHardRef.*maFunPtr)( maArg );
233 }
234
235 private:
236 FunctionPointer maFunPtr;
237 Argument maArg;
238 };
239
240 private:
242 void SetState( sal_Int32 nChild, const sal_Int64 nStateId );
244 void UnSetState( sal_Int32 nChild, const sal_Int64 nStateId );
246 void InitChild( AccessibleEditableTextPara& rChild,
247 SvxEditSourceAdapter& rEditSource,
248 sal_Int32 nChild,
249 sal_Int32 nParagraphIndex ) const;
250
251 // vector the size of the paragraph number of the underlying EditEngine
252 VectorOfChildren maChildren;
253
255 sal_Int64 mnChildStates;
256
257 // cache EE offset for child creation
258 Point maEEOffset;
259
260 // which child currently has the focus (-1 for none)
261 sal_Int32 mnFocusedChild;
262
263 // whether children are active and editable
264 bool mbActive;
265 };
266
267} // end of namespace accessibility
268
269#endif
270
271/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< Reference< XAnimationNode > > maChildren
Helper class for weak object references plus implementation.
WeakCppRef(rtl::Reference< InterfaceType > const &rImpl)
rtl::Reference< InterfaceType > get() const
css::uno::WeakReference< UnoInterfaceType > maWeakRef
void Dispose(const T &xInterface)
enumrange< T >::Iterator begin(enumrange< T >)
end
bool mbActive