android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / access / acctextframe.cxx
blob6b5340ce6f348122dd2196411537551615476704
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
31 #include <frmfmt.hxx>
32 #include <flyfrm.hxx>
33 #include <accmap.hxx>
34 #include <unotools/accessiblerelationsethelper.hxx>
35 #include <hints.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() )
56 msDesc = msTitle;
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;
68 switch(rHint.GetId())
70 case SfxHintId::Dying:
71 EndListeningAll();
72 return;
73 default:
74 return;
75 // #i73249#
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())
86 break;
87 [[fallthrough]];
89 case SfxHintId::SwDescriptionChanged:
91 if(!pFlyFrame)
92 return;
93 const OUString sOldDesc(msDesc);
94 msDesc = pFlyFrameFormat->GetObjDescription();
95 if(msDesc.isEmpty() && msTitle != GetName())
96 msDesc = msTitle;
97 if(msDesc == sOldDesc)
98 return;
99 AccessibleEventObject aEvent;
100 aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
101 aEvent.OldValue <<= sOldDesc;
102 aEvent.NewValue <<= msDesc;
103 FireAccessibleEvent(aEvent);
104 return;
109 // XInterface
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)
119 return aReturn;
122 void SAL_CALL
123 SwAccessibleTextFrame::acquire()
124 noexcept
126 SwAccessibleContext::acquire ();
129 void SAL_CALL
130 SwAccessibleTextFrame::release()
131 noexcept
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 )
145 SolarMutexGuard g;
147 uno::Reference<XAccessible> xAcc = getAccessibleChild( nChildIndex );
148 uno::Reference<XAccessibleContext> xContext;
149 if( xAcc.is() )
150 xContext = xAcc->getAccessibleContext();
152 if( xContext.is() )
154 if( xContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
156 uno::Reference< css::accessibility::XAccessibleText >
157 xText(xAcc, uno::UNO_QUERY);
158 if( xText.is() )
160 if( xText->getSelectionStart() >= 0 ) return true;
165 return false;
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++;
185 return nCount;
188 uno::Reference<XAccessible> SAL_CALL SwAccessibleTextFrame::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex )
190 SolarMutexGuard g;
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 );
200 i2++;
202 return uno::Reference<XAccessible>();
205 void SAL_CALL SwAccessibleTextFrame::deselectAccessibleChild( sal_Int64 )
207 SAL_WARN("sw.a11y", "SwAccessibleTextFrame::selectAllAccessibleChildren - missing implementation");
210 // #i73249#
211 OUString SAL_CALL SwAccessibleTextFrame::getAccessibleName()
213 SolarMutexGuard aGuard;
215 ThrowIfDisposed();
217 if ( !msTitle.isEmpty() )
219 return msTitle;
222 return SwAccessibleFrameBase::getAccessibleName();
225 OUString SAL_CALL SwAccessibleTextFrame::getAccessibleDescription()
227 SolarMutexGuard aGuard;
229 ThrowIfDisposed();
231 return msDesc;
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();
262 assert(pFrame);
263 if( pFrame->IsFlyFrame() )
265 pFlyFrame = static_cast<SwFlyFrame*>( const_cast<SwFrame*>( pFrame ) );
268 return pFlyFrame;
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;
281 ThrowIfDisposed();
283 // get the frame, and insert prev/next relations into helper
285 rtl::Reference<AccessibleRelationSetHelper> pHelper = new AccessibleRelationSetHelper();
287 SwFlyFrame* pFlyFrame = getFlyFrame();
288 assert(pFlyFrame);
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 ) );
300 return pHelper;
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */