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_EDITENG_ACCESSIBLEPARAMANAGER_HXX
21 #define INCLUDED_EDITENG_ACCESSIBLEPARAMANAGER_HXX
23 #include <config_options.h>
26 #include <tools/gen.hxx>
27 #include <com/sun/star/awt/Rectangle.hpp>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <cppuhelper/weakref.hxx>
30 #include <rtl/ref.hxx>
31 #include <editeng/editengdllapi.h>
33 namespace com::sun::star::accessibility
{ class XAccessible
; }
35 class SvxEditSourceAdapter
;
37 namespace accessibility
39 class AccessibleEditableTextPara
;
41 /** Helper class for weak object references plus implementation
43 This class combines a weak reference (to facilitate automatic
44 object disposal if user drops last reference) and hard
45 reference to the c++ class (for fast access and bypassing of
48 template < class UnoType
, class CppType
> class WeakCppRef
52 typedef UnoType UnoInterfaceType
;
53 typedef CppType InterfaceType
;
55 WeakCppRef() : maWeakRef(), maUnsafeRef( nullptr ) {}
57 WeakCppRef(rtl::Reference
<InterfaceType
> const & rImpl
):
58 maWeakRef(rImpl
.get()),
59 maUnsafeRef(rImpl
.get())
63 // get object with c++ object and hard reference (which
64 // prevents the c++ object from destruction during use)
65 rtl::Reference
<InterfaceType
> get() const {
66 css::uno::Reference
<UnoInterfaceType
> ref(maWeakRef
);
67 return ref
.is() ? maUnsafeRef
: rtl::Reference
<InterfaceType
>();
70 // default copy constructor and assignment will do
71 // WeakCppRef( const WeakCppRef& );
72 // WeakCppRef& operator= ( const WeakCppRef& );
76 // the interface, hold weakly
77 css::uno::WeakReference
< UnoInterfaceType
> maWeakRef
;
79 // hard ref to c++ class, _only_ valid if maWeakRef.is() is true
80 InterfaceType
* maUnsafeRef
;
84 /** This class manages the paragraphs of an AccessibleTextHelper
86 To facilitate automatic deletion of paragraphs no longer used,
87 this class uses the WeakCppRef helper to hold the objects weakly.
89 class UNLESS_MERGELIBS(EDITENG_DLLPUBLIC
) AccessibleParaManager
92 typedef WeakCppRef
< css::accessibility::XAccessible
, AccessibleEditableTextPara
> WeakPara
;
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
;
98 AccessibleParaManager();
99 ~AccessibleParaManager();
101 /** Sets a bitset of additional accessible states.
103 The states are passed to every created child object
104 (text paragraph). The state values are defined in
105 css::accessibility::AccessibleStateType.
107 void SetAdditionalChildStates( sal_Int64 nChildStates
);
109 /** Set the number of paragraphs
112 The total number of paragraphs the EditEngine currently
113 has (_not_ the number of currently visible children)
115 void SetNum( sal_Int32 nNumParas
);
117 /** Get the number of paragraphs currently possible */
118 sal_Int32
GetNum() const;
121 VectorOfChildren::iterator
begin();
122 VectorOfChildren::iterator
end();
124 /// Set focus to given child
125 void SetFocus( sal_Int32 nChild
);
127 void FireEvent( sal_Int32 nPara
,
128 const sal_Int16 nEventId
) const;
130 static bool IsReferencable(rtl::Reference
<AccessibleEditableTextPara
> const & aChild
);
131 bool IsReferencable( sal_Int32 nChild
) const;
132 static void ShutdownPara( const WeakChild
& rChild
);
134 Child
CreateChild( sal_Int32 nChild
,
135 const css::uno::Reference
< css::accessibility::XAccessible
>& xFrontEnd
,
136 SvxEditSourceAdapter
& rEditSource
,
137 sal_Int32 nParagraphIndex
);
139 WeakChild
GetChild( sal_Int32 nParagraphIndex
) const;
140 bool HasCreatedChild( sal_Int32 nParagraphIndex
) const;
142 // forwarder to all paragraphs
143 /// Make all children active and editable (or off)
144 void SetActive( bool bActive
= true );
145 /// Set state of all children
146 void SetState( const sal_Int64 nStateId
);
147 /// Unset state of all children
148 void UnSetState( const sal_Int64 nStateId
);
149 /// Set offset to edit engine for all children
150 void SetEEOffset ( const Point
& rOffset
);
151 /// Dispose all living children
154 // forwarder to given paragraphs
156 /** Release the given range of paragraphs
158 All ranges have the meaning [start,end), similar to STL
161 Index of paragraph to start with releasing
164 Index of first paragraph to stop with releasing
166 void Release( sal_Int32 nStartPara
, sal_Int32 nEndPara
);
168 /** Fire event for the given range of paragraphs
170 All ranges have the meaning [start,end), similar to STL
173 Index of paragraph to start with event firing
176 Index of first paragraph to stop with event firing
178 void FireEvent( sal_Int32 nStartPara
,
180 const sal_Int16 nEventId
,
181 const css::uno::Any
& rNewValue
= css::uno::Any(),
182 const css::uno::Any
& rOldValue
= css::uno::Any() ) const;
184 /** Functor adapter for ForEach template
186 Adapts giving functor such that only the paragraph objects
187 are accessed and the fact that our children are held
190 The functor must provide the following method:
191 void operator() ( AccessibleEditablePara& )
194 template < typename Functor
> class WeakChildAdapter
197 WeakChildAdapter( Functor
& rFunctor
) : mrFunctor(rFunctor
) {}
198 void operator()( const WeakChild
& rPara
)
200 // retrieve hard reference from weak one
201 auto aHardRef( rPara
.first
.get() );
204 mrFunctor( *aHardRef
);
211 /** Adapter for unary member functions
213 Since STL's binder don't work with const& arguments (and
214 BOOST's neither, at least on MSVC), have to provide our
215 own adapter for unary member functions.
217 Create with pointer to member function of
218 AccessibleEditableTextPara and the corresponding argument.
220 template < typename Argument
> class MemFunAdapter
223 typedef void (::accessibility::AccessibleEditableTextPara::*FunctionPointer
)( Argument
);
225 MemFunAdapter( FunctionPointer aFunPtr
, Argument aArg
) : maFunPtr(aFunPtr
), maArg(aArg
) {}
226 void operator()( const WeakChild
& rPara
)
228 // retrieve hard reference from weak one
229 auto aHardRef( rPara
.first
.get() );
232 (*aHardRef
.*maFunPtr
)( maArg
);
236 FunctionPointer maFunPtr
;
241 /// Set state on given child
242 void SetState( sal_Int32 nChild
, const sal_Int64 nStateId
);
243 /// Unset state on given child
244 void UnSetState( sal_Int32 nChild
, const sal_Int64 nStateId
);
245 /// Init child with default state (as stored in previous SetFocus and SetActive calls)
246 void InitChild( AccessibleEditableTextPara
& rChild
,
247 SvxEditSourceAdapter
& rEditSource
,
249 sal_Int32 nParagraphIndex
) const;
251 // vector the size of the paragraph number of the underlying EditEngine
252 VectorOfChildren maChildren
;
254 /// Additional states that will be set at every created child object.
255 sal_Int64 mnChildStates
;
257 // cache EE offset for child creation
260 // which child currently has the focus (-1 for none)
261 sal_Int32 mnFocusedChild
;
263 // whether children are active and editable
267 } // end of namespace accessibility
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */