LibreOffice Module sw (master) 1
acctextframe.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <com/sun/star/accessibility/XAccessibleContext.hpp>
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>
35#include <hints.hxx>
36#include "acctextframe.hxx"
37
38using namespace ::com::sun::star;
39using namespace ::com::sun::star::accessibility;
40
42using ::com::sun::star::accessibility::XAccessibleContext;
43
45 std::shared_ptr<SwAccessibleMap> const& pInitMap,
46 const SwFlyFrame& rFlyFrame ) :
47 SwAccessibleFrameBase( pInitMap, AccessibleRole::TEXT_FRAME, &rFlyFrame )
48{
49 const SwFlyFrameFormat* pFlyFrameFormat = rFlyFrame.GetFormat();
50 msTitle = pFlyFrameFormat->GetObjTitle();
51
52 msDesc = pFlyFrameFormat->GetObjDescription();
53 if ( msDesc.isEmpty() &&
54 msTitle != GetName() )
55 {
57 }
58}
59
61{
62}
63
65{
66 const SwFlyFrame* pFlyFrame = static_cast<const SwFlyFrame*>(GetFrame());
67 const SwFlyFrameFormat* pFlyFrameFormat = pFlyFrame ? pFlyFrame->GetFormat() : nullptr;
68 switch(rHint.GetId())
69 {
70 case SfxHintId::Dying:
72 return;
73 default:
74 return;
75 // #i73249#
76 case SfxHintId::SwTitleChanged:
77 {
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;
85 if(!pFlyFrameFormat || !pFlyFrameFormat->GetObjDescription().isEmpty())
86 break;
87 [[fallthrough]];
88 }
89 case SfxHintId::SwDescriptionChanged:
90 {
91 if(!pFlyFrame)
92 return;
93 const OUString sOldDesc(msDesc);
94 msDesc = pFlyFrameFormat->GetObjDescription();
95 if(msDesc.isEmpty() && msTitle != GetName())
97 if(msDesc == sOldDesc)
98 return;
99 AccessibleEventObject aEvent;
100 aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
101 aEvent.OldValue <<= sOldDesc;
102 aEvent.NewValue <<= msDesc;
104 return;
105 }
106 }
107}
108
109// XInterface
110
111css::uno::Any SAL_CALL
112 SwAccessibleTextFrame::queryInterface (const css::uno::Type & rType)
113{
114 css::uno::Any aReturn = SwAccessibleContext::queryInterface (rType);
115 if ( ! aReturn.hasValue())
116 aReturn = ::cppu::queryInterface (rType,
117 static_cast< css::accessibility::XAccessibleSelection* >(this)
118 );
119 return aReturn;
120}
121
122void SAL_CALL
124 noexcept
125{
126 SwAccessibleContext::acquire ();
127}
128
129void SAL_CALL
131 noexcept
132{
133 SwAccessibleContext::release ();
134}
135
136// XAccessibleSelection
137
139{
140 SAL_WARN("sw.a11y", "SwAccessibleTextFrame::selectAccessibleChild - missing implementation");
141}
142
144{
146
147 uno::Reference<XAccessible> xAcc = getAccessibleChild( nChildIndex );
148 uno::Reference<XAccessibleContext> xContext;
149 if( xAcc.is() )
150 xContext = xAcc->getAccessibleContext();
151
152 if( xContext.is() )
153 {
154 if( xContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
155 {
156 uno::Reference< css::accessibility::XAccessibleText >
157 xText(xAcc, uno::UNO_QUERY);
158 if( xText.is() )
159 {
160 if( xText->getSelectionStart() >= 0 ) return true;
161 }
162 }
163 }
164
165 return false;
166}
167
169{
170 SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::clearAccessibleSelection()> - missing implementation");
171}
172
174{
175 SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::selectAllAccessibleChildren()> - missing implementation");
176}
177
179{
180 sal_Int64 nCount = 0;
181 sal_Int64 TotalCount = getAccessibleChildCount();
182 for( sal_Int64 i = 0; i < TotalCount; i++ )
184
185 return nCount;
186}
187
188uno::Reference<XAccessible> SAL_CALL SwAccessibleTextFrame::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex )
189{
191
192 if ( nSelectedChildIndex > getSelectedAccessibleChildCount() )
193 throw lang::IndexOutOfBoundsException();
194
195 for(sal_Int64 i1 = 0, i2 = 0; i1 < getAccessibleChildCount(); i1++ )
197 {
198 if( i2 == nSelectedChildIndex )
199 return getAccessibleChild( i1 );
200 i2++;
201 }
202 return uno::Reference<XAccessible>();
203}
204
206{
207 SAL_WARN("sw.a11y", "SwAccessibleTextFrame::selectAllAccessibleChildren - missing implementation");
208}
209
210// #i73249#
212{
213 SolarMutexGuard aGuard;
214
216
217 if ( !msTitle.isEmpty() )
218 {
219 return msTitle;
220 }
221
223}
224
226{
227 SolarMutexGuard aGuard;
228
230
231 return msDesc;
232
233}
234
236{
237 return "com.sun.star.comp.Writer.SwAccessibleTextFrameView";
238}
239
240sal_Bool SAL_CALL SwAccessibleTextFrame::supportsService(const OUString& sTestServiceName)
241{
242 return cppu::supportsService(this, sTestServiceName);
243}
244
245uno::Sequence< OUString > SAL_CALL SwAccessibleTextFrame::getSupportedServiceNames()
246{
247 return { "com.sun.star.text.AccessibleTextFrameView", sAccessibleServiceName };
248}
249
250uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleTextFrame::getImplementationId()
251{
252 return css::uno::Sequence<sal_Int8>();
253}
254
255// XAccessibleRelationSet
256
258{
259 SwFlyFrame* pFlyFrame = nullptr;
260
261 const SwFrame* pFrame = GetFrame();
262 assert(pFrame);
263 if( pFrame->IsFlyFrame() )
264 {
265 pFlyFrame = static_cast<SwFlyFrame*>( const_cast<SwFrame*>( pFrame ) );
266 }
267
268 return pFlyFrame;
269}
270
271AccessibleRelation SwAccessibleTextFrame::makeRelation( sal_Int16 nType, const SwFlyFrame* pFrame )
272{
273 uno::Sequence<uno::Reference<XInterface> > aSequence { GetMap()->GetContext( pFrame ) };
274 return AccessibleRelation( nType, aSequence );
275}
276
277uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleTextFrame::getAccessibleRelationSet( )
278{
279 SolarMutexGuard aGuard;
280
282
283 // get the frame, and insert prev/next relations into helper
284
286
287 SwFlyFrame* pFlyFrame = getFlyFrame();
288 assert(pFlyFrame);
289
290 const SwFlyFrame* pPrevFrame = pFlyFrame->GetPrevLink();
291 if( pPrevFrame != nullptr )
292 pHelper->AddRelation( makeRelation(
293 AccessibleRelationType::CONTENT_FLOWS_FROM, pPrevFrame ) );
294
295 const SwFlyFrame* pNextFrame = pFlyFrame->GetNextLink();
296 if( pNextFrame != nullptr )
297 pHelper->AddRelation( makeRelation(
298 AccessibleRelationType::CONTENT_FLOWS_TO, pNextFrame ) );
299
300 return pHelper;
301}
302
303/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sAccessibleServiceName
Definition: acccontext.hxx:42
AnyEventRef aEvent
SfxHintId GetId() const
void EndListeningAll()
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
Definition: acccontext.cxx:573
const OUString & GetName() const
Definition: acccontext.hxx:334
virtual OUString SAL_CALL getAccessibleName() override
Definition: acccontext.cxx:729
void FireAccessibleEvent(css::accessibility::AccessibleEventObject &rEvent)
Definition: acccontext.cxx:441
SwAccessibleMap * GetMap()
Definition: acccontext.hxx:112
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 nIndex) override
Definition: acccontext.cxx:583
const SwFrame * GetFrame() const
Definition: accframe.hxx:102
css::uno::Reference< css::accessibility::XAccessible > GetContext(const SwFrame *pFrame, bool bCreate=true)
Definition: accmap.cxx:1789
virtual ~SwAccessibleTextFrame() override
virtual OUString SAL_CALL getAccessibleName() override
virtual void SAL_CALL clearAccessibleSelection() override
virtual OUString SAL_CALL getImplementationName() override
Returns an identifier for the implementation of this object.
SwAccessibleTextFrame(std::shared_ptr< SwAccessibleMap > const &pInitMap, const SwFlyFrame &rFlyFrame)
virtual void SAL_CALL selectAllAccessibleChildren() override
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
Return whether the specified service is supported by this class.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
virtual sal_Bool SAL_CALL isAccessibleChildSelected(sal_Int64 nChildIndex) override
virtual sal_Int64 SAL_CALL getSelectedAccessibleChildCount() override
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL selectAccessibleChild(sal_Int64 nChildIndex) override
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild(sal_Int64 nSelectedChildIndex) override
virtual OUString SAL_CALL getAccessibleDescription() override
Return this object's description.
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
virtual void SAL_CALL deselectAccessibleChild(sal_Int64 nSelectedChildIndex) override
virtual void Notify(const SfxHint &) override
css::accessibility::AccessibleRelation makeRelation(sal_Int16 nType, const SwFlyFrame *pFrame)
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual void SAL_CALL acquire() noexcept override
SwFlyFrame * getFlyFrame() const
OUString GetObjDescription() const
Definition: atrfrm.cxx:3226
OUString GetObjTitle() const
Definition: atrfrm.cxx:3184
general base class for all free-flowing frames
Definition: flyfrm.hxx:79
SwFlyFrame * GetPrevLink() const
Definition: flyfrm.hxx:193
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:3119
SwFlyFrame * GetNextLink() const
Definition: flyfrm.hxx:194
Base class of the Writer layout elements.
Definition: frame.hxx:315
bool IsFlyFrame() const
Definition: frame.hxx:1216
int nCount
#define SAL_WARN(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
QPRO_FUNC_TYPE nType
unsigned char sal_Bool