24#include <com/sun/star/uno/Any.hxx>
25#include <com/sun/star/uno/Reference.hxx>
29#include <com/sun/star/accessibility/XAccessible.hpp>
30#include <com/sun/star/accessibility/AccessibleStateType.hpp>
46 AccessibleParaManager::AccessibleParaManager() :
55 AccessibleParaManager::~AccessibleParaManager()
60 void AccessibleParaManager::SetAdditionalChildStates( sal_Int64 nChildStates )
62 mnChildStates = nChildStates;
65 void AccessibleParaManager::SetNum( sal_Int32 nNumParas )
72 if( mnFocusedChild >= nNumParas )
76 sal_Int32 AccessibleParaManager::GetNum()
const
79 if (nSize > SAL_MAX_INT32)
81 SAL_WARN(
"editeng",
"AccessibleParaManager::GetNum - overflow " << nSize);
84 return static_cast<sal_Int32
>(nSize);
87 AccessibleParaManager::VectorOfChildren::iterator AccessibleParaManager::begin()
92 AccessibleParaManager::VectorOfChildren::iterator AccessibleParaManager::end()
97 void AccessibleParaManager::FireEvent( sal_Int32 nPara,
98 const sal_Int16 nEventId )
const
101 "AccessibleParaManager::FireEvent: invalid index" );
105 auto aChild( GetChild( nPara ).
first.get() );
107 aChild->FireEvent( nEventId );
111 bool AccessibleParaManager::IsReferencable(
117 bool AccessibleParaManager::IsReferencable( sal_Int32 nChild )
const
120 "AccessibleParaManager::IsReferencable: invalid index" );
125 return IsReferencable( GetChild( nChild ).
first.get() );
133 AccessibleParaManager::WeakChild AccessibleParaManager::GetChild( sal_Int32 nParagraphIndex )
const
136 "AccessibleParaManager::GetChild: invalid index" );
148 bool AccessibleParaManager::HasCreatedChild( sal_Int32 nParagraphIndex )
const
152 auto const & rChild =
maChildren[ nParagraphIndex ];
153 return rChild.second.Width != 0 || rChild.second.Height != 0;
159 AccessibleParaManager::Child AccessibleParaManager::CreateChild( sal_Int32 nChild,
160 const uno::Reference< XAccessible >& xFrontEnd,
161 SvxEditSourceAdapter& rEditSource,
162 sal_Int32 nParagraphIndex )
165 "AccessibleParaManager::CreateChild: invalid index" );
170 auto aChild( GetChild( nParagraphIndex ).
first.get() );
172 if( !IsReferencable( nParagraphIndex ) )
176 aChild =
new AccessibleEditableTextPara(xFrontEnd,
this);
178 InitChild( *aChild, rEditSource, nChild, nParagraphIndex );
180 maChildren[ nParagraphIndex ] = WeakChild( aChild, aChild->getBounds() );
183 return Child( aChild.get(), GetChild( nParagraphIndex ).second );
191 void AccessibleParaManager::SetEEOffset(
const Point& rOffset )
193 maEEOffset = rOffset;
195 MemFunAdapter< const Point& > aAdapter( &::accessibility::AccessibleEditableTextPara::SetEEOffset, rOffset );
196 std::for_each(
begin(),
end(), aAdapter );
199 void AccessibleParaManager::SetActive(
bool bActive )
205 SetState( AccessibleStateType::ACTIVE );
206 SetState( AccessibleStateType::EDITABLE );
210 UnSetState( AccessibleStateType::ACTIVE );
211 UnSetState( AccessibleStateType::EDITABLE );
215 void AccessibleParaManager::SetFocus( sal_Int32 nChild )
217 if( mnFocusedChild != -1 )
218 UnSetState( mnFocusedChild, AccessibleStateType::FOCUSED );
220 mnFocusedChild = nChild;
222 if( mnFocusedChild != -1 )
223 SetState( mnFocusedChild, AccessibleStateType::FOCUSED );
226 void AccessibleParaManager::InitChild( AccessibleEditableTextPara& rChild,
227 SvxEditSourceAdapter& rEditSource,
229 sal_Int32 nParagraphIndex )
const
231 rChild.SetEditSource( &rEditSource );
232 rChild.SetIndexInParent( nChild );
233 rChild.SetParagraphIndex( nParagraphIndex );
235 rChild.SetEEOffset( maEEOffset );
239 rChild.SetState( AccessibleStateType::ACTIVE );
240 rChild.SetState( AccessibleStateType::EDITABLE );
243 if( mnFocusedChild == nParagraphIndex )
244 rChild.SetState( AccessibleStateType::FOCUSED );
247 for (
int i=0;
i<63;
i++)
249 sal_Int64
nState = sal_Int64(1) <<
i;
250 if ( nState & mnChildStates )
251 rChild.SetState( nState );
255 void AccessibleParaManager::SetState( sal_Int32 nChild,
const sal_Int64 nStateId )
257 MemFunAdapter< const sal_Int64 > aFunc( &AccessibleEditableTextPara::SetState,
259 aFunc( GetChild(nChild) );
262 void AccessibleParaManager::SetState(
const sal_Int64 nStateId )
265 MemFunAdapter< const sal_Int64 >( &AccessibleEditableTextPara::SetState,
269 void AccessibleParaManager::UnSetState( sal_Int32 nChild,
const sal_Int64 nStateId )
271 MemFunAdapter< const sal_Int64 > aFunc( &AccessibleEditableTextPara::UnSetState,
273 aFunc( GetChild(nChild) );
276 void AccessibleParaManager::UnSetState(
const sal_Int64 nStateId )
279 MemFunAdapter< const sal_Int64 >( &AccessibleEditableTextPara::UnSetState,
286 class AccessibleParaManager_DisposeChildren
289 AccessibleParaManager_DisposeChildren() {}
290 void operator()( ::accessibility::AccessibleEditableTextPara& rPara )
298 void AccessibleParaManager::Dispose()
300 AccessibleParaManager_DisposeChildren aFunctor;
303 WeakChildAdapter< AccessibleParaManager_DisposeChildren > (aFunctor) );
309 class StateChangeEvent
312 StateChangeEvent(
const sal_Int16 nEventId,
318 void operator()( ::accessibility::AccessibleEditableTextPara
const & rPara )
331 void AccessibleParaManager::FireEvent( sal_Int32 nStartPara,
333 const sal_Int16 nEventId,
337 DBG_ASSERT( 0 <= nStartPara && 0 <= nEndPara &&
340 nEndPara >= nStartPara,
"AccessibleParaManager::FireEvent: invalid index" );
343 if( 0 <= nStartPara && 0 <= nEndPara &&
346 nEndPara >= nStartPara )
348 VectorOfChildren::const_iterator front =
maChildren.begin();
349 VectorOfChildren::const_iterator back = front;
351 std::advance( front, nStartPara );
352 std::advance( back, nEndPara );
354 StateChangeEvent aFunctor( nEventId, rNewValue, rOldValue );
356 std::for_each( front, back, AccessibleParaManager::WeakChildAdapter< StateChangeEvent >( aFunctor ) );
365 AccessibleParaManager::WeakChild operator()(
const AccessibleParaManager::WeakChild& rPara )
367 AccessibleParaManager::ShutdownPara( rPara );
370 return AccessibleParaManager::WeakChild();
376 void AccessibleParaManager::Release( sal_Int32 nStartPara, sal_Int32 nEndPara )
378 DBG_ASSERT( 0 <= nStartPara && 0 <= nEndPara &&
381 "AccessibleParaManager::Release: invalid index" );
383 if( 0 <= nStartPara && 0 <= nEndPara &&
387 VectorOfChildren::iterator front =
maChildren.begin();
388 VectorOfChildren::iterator back = front;
390 std::advance( front, nStartPara );
391 std::advance( back, nEndPara );
393 std::transform( front, back, front, ReleaseChild() );
397 void AccessibleParaManager::ShutdownPara(
const WeakChild& rChild )
399 auto aChild( rChild.first.get() );
401 if( IsReferencable( aChild ) )
402 aChild->SetEditSource(
nullptr );
const sal_Int16 mnEventId
const uno::Any & mrNewValue
const uno::Any & mrOldValue
std::vector< Reference< XAnimationNode > > maChildren
#define DBG_ASSERT(sCon, aError)
#define SAL_WARN(area, stream)
constexpr OUStringLiteral first
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
enumrange< T >::Iterator begin(enumrange< T >)