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 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
21 #include <cppuhelper/queryinterface.hxx>
22 #include <cppuhelper/supportsservice.hxx>
23 #include <vcl/svapp.hxx>
24 #include <sal/log.hxx>
25 #include <com/sun/star/accessibility/AccessibleRole.hpp>
26 #include <com/sun/star/accessibility/AccessibleRelation.hpp>
27 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
28 #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
29 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
30 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
34 #include <unotools/accessiblerelationsethelper.hxx>
36 #include "acctextframe.hxx"
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::accessibility
;
41 using utl::AccessibleRelationSetHelper
;
42 using ::com::sun::star::accessibility::XAccessibleContext
;
44 SwAccessibleTextFrame::SwAccessibleTextFrame(
45 std::shared_ptr
<SwAccessibleMap
> const& pInitMap
,
46 const SwFlyFrame
& rFlyFrame
) :
47 SwAccessibleFrameBase( pInitMap
, AccessibleRole::TEXT_FRAME
, &rFlyFrame
)
49 const SwFlyFrameFormat
* pFlyFrameFormat
= rFlyFrame
.GetFormat();
50 msTitle
= pFlyFrameFormat
->GetObjTitle();
52 msDesc
= pFlyFrameFormat
->GetObjDescription();
53 if ( msDesc
.isEmpty() &&
54 msTitle
!= GetName() )
60 SwAccessibleTextFrame::~SwAccessibleTextFrame()
64 void SwAccessibleTextFrame::Notify(const SfxHint
& rHint
)
66 const SwFlyFrame
* pFlyFrame
= static_cast<const SwFlyFrame
*>(GetFrame());
67 const SwFlyFrameFormat
* pFlyFrameFormat
= pFlyFrame
? pFlyFrame
->GetFormat() : nullptr;
70 case SfxHintId::Dying
:
76 case SfxHintId::SwTitleChanged
:
78 auto rTitleChanged
= static_cast<const sw::TitleChanged
&>(rHint
);
79 msTitle
= rTitleChanged
.m_sNew
;
80 AccessibleEventObject aEvent
;
81 aEvent
.EventId
= AccessibleEventId::NAME_CHANGED
;
82 aEvent
.OldValue
<<= rTitleChanged
.m_sOld
;
83 aEvent
.NewValue
<<= msTitle
;
84 FireAccessibleEvent( aEvent
);
85 if(!pFlyFrameFormat
|| !pFlyFrameFormat
->GetObjDescription().isEmpty())
89 case SfxHintId::SwDescriptionChanged
:
93 const OUString
sOldDesc(msDesc
);
94 msDesc
= pFlyFrameFormat
->GetObjDescription();
95 if(msDesc
.isEmpty() && msTitle
!= GetName())
97 if(msDesc
== sOldDesc
)
99 AccessibleEventObject aEvent
;
100 aEvent
.EventId
= AccessibleEventId::DESCRIPTION_CHANGED
;
101 aEvent
.OldValue
<<= sOldDesc
;
102 aEvent
.NewValue
<<= msDesc
;
103 FireAccessibleEvent(aEvent
);
111 css::uno::Any SAL_CALL
112 SwAccessibleTextFrame::queryInterface (const css::uno::Type
& rType
)
114 css::uno::Any aReturn
= SwAccessibleContext::queryInterface (rType
);
115 if ( ! aReturn
.hasValue())
116 aReturn
= ::cppu::queryInterface (rType
,
117 static_cast< css::accessibility::XAccessibleSelection
* >(this)
123 SwAccessibleTextFrame::acquire()
126 SwAccessibleContext::acquire ();
130 SwAccessibleTextFrame::release()
133 SwAccessibleContext::release ();
136 // XAccessibleSelection
138 void SAL_CALL
SwAccessibleTextFrame::selectAccessibleChild( sal_Int64
)
140 SAL_WARN("sw.a11y", "SwAccessibleTextFrame::selectAccessibleChild - missing implementation");
143 sal_Bool SAL_CALL
SwAccessibleTextFrame::isAccessibleChildSelected( sal_Int64 nChildIndex
)
147 uno::Reference
<XAccessible
> xAcc
= getAccessibleChild( nChildIndex
);
148 uno::Reference
<XAccessibleContext
> xContext
;
150 xContext
= xAcc
->getAccessibleContext();
154 const sal_Int16 nRole
= xContext
->getAccessibleRole();
155 if (nRole
== AccessibleRole::PARAGRAPH
|| nRole
== AccessibleRole::BLOCK_QUOTE
)
157 uno::Reference
< css::accessibility::XAccessibleText
>
158 xText(xAcc
, uno::UNO_QUERY
);
161 if( xText
->getSelectionStart() >= 0 ) return true;
169 void SAL_CALL
SwAccessibleTextFrame::clearAccessibleSelection( )
171 SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::clearAccessibleSelection()> - missing implementation");
174 void SAL_CALL
SwAccessibleTextFrame::selectAllAccessibleChildren( )
176 SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::selectAllAccessibleChildren()> - missing implementation");
179 sal_Int64 SAL_CALL
SwAccessibleTextFrame::getSelectedAccessibleChildCount()
181 sal_Int64 nCount
= 0;
182 sal_Int64 TotalCount
= getAccessibleChildCount();
183 for( sal_Int64 i
= 0; i
< TotalCount
; i
++ )
184 if( isAccessibleChildSelected(i
) ) nCount
++;
189 uno::Reference
<XAccessible
> SAL_CALL
SwAccessibleTextFrame::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex
)
193 if ( nSelectedChildIndex
> getSelectedAccessibleChildCount() )
194 throw lang::IndexOutOfBoundsException();
196 for(sal_Int64 i1
= 0, i2
= 0; i1
< getAccessibleChildCount(); i1
++ )
197 if( isAccessibleChildSelected(i1
) )
199 if( i2
== nSelectedChildIndex
)
200 return getAccessibleChild( i1
);
203 return uno::Reference
<XAccessible
>();
206 void SAL_CALL
SwAccessibleTextFrame::deselectAccessibleChild( sal_Int64
)
208 SAL_WARN("sw.a11y", "SwAccessibleTextFrame::selectAllAccessibleChildren - missing implementation");
212 OUString SAL_CALL
SwAccessibleTextFrame::getAccessibleName()
214 SolarMutexGuard aGuard
;
218 if ( !msTitle
.isEmpty() )
223 return SwAccessibleFrameBase::getAccessibleName();
226 OUString SAL_CALL
SwAccessibleTextFrame::getAccessibleDescription()
228 SolarMutexGuard aGuard
;
236 OUString SAL_CALL
SwAccessibleTextFrame::getImplementationName()
238 return u
"com.sun.star.comp.Writer.SwAccessibleTextFrameView"_ustr
;
241 sal_Bool SAL_CALL
SwAccessibleTextFrame::supportsService(const OUString
& sTestServiceName
)
243 return cppu::supportsService(this, sTestServiceName
);
246 uno::Sequence
< OUString
> SAL_CALL
SwAccessibleTextFrame::getSupportedServiceNames()
248 return { u
"com.sun.star.text.AccessibleTextFrameView"_ustr
, sAccessibleServiceName
};
251 uno::Sequence
< sal_Int8
> SAL_CALL
SwAccessibleTextFrame::getImplementationId()
253 return css::uno::Sequence
<sal_Int8
>();
256 // XAccessibleRelationSet
258 SwFlyFrame
* SwAccessibleTextFrame::getFlyFrame() const
260 SwFlyFrame
* pFlyFrame
= nullptr;
262 const SwFrame
* pFrame
= GetFrame();
264 if( pFrame
->IsFlyFrame() )
266 pFlyFrame
= static_cast<SwFlyFrame
*>( const_cast<SwFrame
*>( pFrame
) );
272 AccessibleRelation
SwAccessibleTextFrame::makeRelation(AccessibleRelationType eType
, const SwFlyFrame
* pFrame
)
274 uno::Sequence
<uno::Reference
<XAccessible
>> aSequence
{ GetMap()->GetContext(pFrame
) };
275 return AccessibleRelation(eType
, aSequence
);
278 uno::Reference
<XAccessibleRelationSet
> SAL_CALL
SwAccessibleTextFrame::getAccessibleRelationSet( )
280 SolarMutexGuard aGuard
;
284 // get the frame, and insert prev/next relations into helper
286 rtl::Reference
<AccessibleRelationSetHelper
> pHelper
= new AccessibleRelationSetHelper();
288 SwFlyFrame
* pFlyFrame
= getFlyFrame();
291 const SwFlyFrame
* pPrevFrame
= pFlyFrame
->GetPrevLink();
292 if( pPrevFrame
!= nullptr )
293 pHelper
->AddRelation( makeRelation(
294 AccessibleRelationType_CONTENT_FLOWS_FROM
, pPrevFrame
) );
296 const SwFlyFrame
* pNextFrame
= pFlyFrame
->GetNextLink();
297 if( pNextFrame
!= nullptr )
298 pHelper
->AddRelation( makeRelation(
299 AccessibleRelationType_CONTENT_FLOWS_TO
, pNextFrame
) );
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */