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 if( xContext
->getAccessibleRole() == AccessibleRole::PARAGRAPH
)
156 uno::Reference
< css::accessibility::XAccessibleText
>
157 xText(xAcc
, uno::UNO_QUERY
);
160 if( xText
->getSelectionStart() >= 0 ) return true;
168 void SAL_CALL
SwAccessibleTextFrame::clearAccessibleSelection( )
170 SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::clearAccessibleSelection()> - missing implementation");
173 void SAL_CALL
SwAccessibleTextFrame::selectAllAccessibleChildren( )
175 SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::selectAllAccessibleChildren()> - missing implementation");
178 sal_Int64 SAL_CALL
SwAccessibleTextFrame::getSelectedAccessibleChildCount()
180 sal_Int64 nCount
= 0;
181 sal_Int64 TotalCount
= getAccessibleChildCount();
182 for( sal_Int64 i
= 0; i
< TotalCount
; i
++ )
183 if( isAccessibleChildSelected(i
) ) nCount
++;
188 uno::Reference
<XAccessible
> SAL_CALL
SwAccessibleTextFrame::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex
)
192 if ( nSelectedChildIndex
> getSelectedAccessibleChildCount() )
193 throw lang::IndexOutOfBoundsException();
195 for(sal_Int64 i1
= 0, i2
= 0; i1
< getAccessibleChildCount(); i1
++ )
196 if( isAccessibleChildSelected(i1
) )
198 if( i2
== nSelectedChildIndex
)
199 return getAccessibleChild( i1
);
202 return uno::Reference
<XAccessible
>();
205 void SAL_CALL
SwAccessibleTextFrame::deselectAccessibleChild( sal_Int64
)
207 SAL_WARN("sw.a11y", "SwAccessibleTextFrame::selectAllAccessibleChildren - missing implementation");
211 OUString SAL_CALL
SwAccessibleTextFrame::getAccessibleName()
213 SolarMutexGuard aGuard
;
217 if ( !msTitle
.isEmpty() )
222 return SwAccessibleFrameBase::getAccessibleName();
225 OUString SAL_CALL
SwAccessibleTextFrame::getAccessibleDescription()
227 SolarMutexGuard aGuard
;
235 OUString SAL_CALL
SwAccessibleTextFrame::getImplementationName()
237 return "com.sun.star.comp.Writer.SwAccessibleTextFrameView";
240 sal_Bool SAL_CALL
SwAccessibleTextFrame::supportsService(const OUString
& sTestServiceName
)
242 return cppu::supportsService(this, sTestServiceName
);
245 uno::Sequence
< OUString
> SAL_CALL
SwAccessibleTextFrame::getSupportedServiceNames()
247 return { "com.sun.star.text.AccessibleTextFrameView", sAccessibleServiceName
};
250 uno::Sequence
< sal_Int8
> SAL_CALL
SwAccessibleTextFrame::getImplementationId()
252 return css::uno::Sequence
<sal_Int8
>();
255 // XAccessibleRelationSet
257 SwFlyFrame
* SwAccessibleTextFrame::getFlyFrame() const
259 SwFlyFrame
* pFlyFrame
= nullptr;
261 const SwFrame
* pFrame
= GetFrame();
263 if( pFrame
->IsFlyFrame() )
265 pFlyFrame
= static_cast<SwFlyFrame
*>( const_cast<SwFrame
*>( pFrame
) );
271 AccessibleRelation
SwAccessibleTextFrame::makeRelation( sal_Int16 nType
, const SwFlyFrame
* pFrame
)
273 uno::Sequence
<uno::Reference
<XInterface
> > aSequence
{ GetMap()->GetContext( pFrame
) };
274 return AccessibleRelation( nType
, aSequence
);
277 uno::Reference
<XAccessibleRelationSet
> SAL_CALL
SwAccessibleTextFrame::getAccessibleRelationSet( )
279 SolarMutexGuard aGuard
;
283 // get the frame, and insert prev/next relations into helper
285 rtl::Reference
<AccessibleRelationSetHelper
> pHelper
= new AccessibleRelationSetHelper();
287 SwFlyFrame
* pFlyFrame
= getFlyFrame();
290 const SwFlyFrame
* pPrevFrame
= pFlyFrame
->GetPrevLink();
291 if( pPrevFrame
!= nullptr )
292 pHelper
->AddRelation( makeRelation(
293 AccessibleRelationType::CONTENT_FLOWS_FROM
, pPrevFrame
) );
295 const SwFlyFrame
* pNextFrame
= pFlyFrame
->GetNextLink();
296 if( pNextFrame
!= nullptr )
297 pHelper
->AddRelation( makeRelation(
298 AccessibleRelationType::CONTENT_FLOWS_TO
, pNextFrame
) );
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */