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 if(rHint.GetId() == SfxHintId::Dying)
68 else if (rHint.GetId() == SfxHintId::SwLegacyModify)
69 {
70 auto pLegacyModifyHint = static_cast<const sw::LegacyModifyHint*>(&rHint);
71 const sal_uInt16 nWhich = pLegacyModifyHint->GetWhich();
72 const SwFlyFrame* pFlyFrame = static_cast<const SwFlyFrame*>(GetFrame());
73 switch(nWhich)
74 {
75 // #i73249#
77 {
78 OUString sOldTitle, sNewTitle;
79 const SwStringMsgPoolItem *pOldItem = dynamic_cast<const SwStringMsgPoolItem*>(pLegacyModifyHint->m_pOld);
80 if(pOldItem)
81 sOldTitle = pOldItem->GetString();
82 const SwStringMsgPoolItem *pNewItem = dynamic_cast<const SwStringMsgPoolItem*>(pLegacyModifyHint->m_pNew);
83 if(pNewItem)
84 sNewTitle = pNewItem->GetString();
85 if(sOldTitle == sNewTitle)
86 break;
87 msTitle = sNewTitle;
88 AccessibleEventObject aEvent;
89 aEvent.EventId = AccessibleEventId::NAME_CHANGED;
90 aEvent.OldValue <<= sOldTitle;
91 aEvent.NewValue <<= msTitle;
93
94 const SwFlyFrameFormat* pFlyFrameFormat = pFlyFrame->GetFormat();
95 if(!pFlyFrameFormat || !pFlyFrameFormat->GetObjDescription().isEmpty())
96 break;
97 [[fallthrough]];
98 }
100 {
101 if(pFlyFrame)
102 {
103 const OUString sOldDesc(msDesc);
104
105 const SwFlyFrameFormat* pFlyFrameFormat = pFlyFrame->GetFormat();
106 const OUString& rDesc = pFlyFrameFormat->GetObjDescription();
107 msDesc = rDesc;
108 if(msDesc.isEmpty() && msTitle != GetName())
109 msDesc = msTitle;
110
111 if(msDesc != sOldDesc)
112 {
113 AccessibleEventObject aEvent;
114 aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
115 aEvent.OldValue <<= sOldDesc;
116 aEvent.NewValue <<= msDesc;
118 }
119 }
120 }
121 }
122 }
123}
124
125// XInterface
126
127css::uno::Any SAL_CALL
128 SwAccessibleTextFrame::queryInterface (const css::uno::Type & rType)
129{
130 css::uno::Any aReturn = SwAccessibleContext::queryInterface (rType);
131 if ( ! aReturn.hasValue())
132 aReturn = ::cppu::queryInterface (rType,
133 static_cast< css::accessibility::XAccessibleSelection* >(this)
134 );
135 return aReturn;
136}
137
138void SAL_CALL
140 noexcept
141{
142 SwAccessibleContext::acquire ();
143}
144
145void SAL_CALL
147 noexcept
148{
149 SwAccessibleContext::release ();
150}
151
152// XAccessibleSelection
153
155{
156 SAL_WARN("sw.a11y", "SwAccessibleTextFrame::selectAccessibleChild - missing implementation");
157}
158
160{
162
163 uno::Reference<XAccessible> xAcc = getAccessibleChild( nChildIndex );
164 uno::Reference<XAccessibleContext> xContext;
165 if( xAcc.is() )
166 xContext = xAcc->getAccessibleContext();
167
168 if( xContext.is() )
169 {
170 if( xContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
171 {
172 uno::Reference< css::accessibility::XAccessibleText >
173 xText(xAcc, uno::UNO_QUERY);
174 if( xText.is() )
175 {
176 if( xText->getSelectionStart() >= 0 ) return true;
177 }
178 }
179 }
180
181 return false;
182}
183
185{
186 SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::clearAccessibleSelection()> - missing implementation");
187}
188
190{
191 SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::selectAllAccessibleChildren()> - missing implementation");
192}
193
195{
196 sal_Int64 nCount = 0;
197 sal_Int64 TotalCount = getAccessibleChildCount();
198 for( sal_Int64 i = 0; i < TotalCount; i++ )
200
201 return nCount;
202}
203
204uno::Reference<XAccessible> SAL_CALL SwAccessibleTextFrame::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex )
205{
207
208 if ( nSelectedChildIndex > getSelectedAccessibleChildCount() )
209 throw lang::IndexOutOfBoundsException();
210
211 for(sal_Int64 i1 = 0, i2 = 0; i1 < getAccessibleChildCount(); i1++ )
213 {
214 if( i2 == nSelectedChildIndex )
215 return getAccessibleChild( i1 );
216 i2++;
217 }
218 return uno::Reference<XAccessible>();
219}
220
222{
223 SAL_WARN("sw.a11y", "SwAccessibleTextFrame::selectAllAccessibleChildren - missing implementation");
224}
225
226// #i73249#
228{
229 SolarMutexGuard aGuard;
230
232
233 if ( !msTitle.isEmpty() )
234 {
235 return msTitle;
236 }
237
239}
240
242{
243 SolarMutexGuard aGuard;
244
246
247 return msDesc;
248
249}
250
252{
253 return "com.sun.star.comp.Writer.SwAccessibleTextFrameView";
254}
255
256sal_Bool SAL_CALL SwAccessibleTextFrame::supportsService(const OUString& sTestServiceName)
257{
258 return cppu::supportsService(this, sTestServiceName);
259}
260
261uno::Sequence< OUString > SAL_CALL SwAccessibleTextFrame::getSupportedServiceNames()
262{
263 return { "com.sun.star.text.AccessibleTextFrameView", sAccessibleServiceName };
264}
265
266uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleTextFrame::getImplementationId()
267{
268 return css::uno::Sequence<sal_Int8>();
269}
270
271// XAccessibleRelationSet
272
274{
275 SwFlyFrame* pFlyFrame = nullptr;
276
277 const SwFrame* pFrame = GetFrame();
278 assert(pFrame);
279 if( pFrame->IsFlyFrame() )
280 {
281 pFlyFrame = static_cast<SwFlyFrame*>( const_cast<SwFrame*>( pFrame ) );
282 }
283
284 return pFlyFrame;
285}
286
287AccessibleRelation SwAccessibleTextFrame::makeRelation( sal_Int16 nType, const SwFlyFrame* pFrame )
288{
289 uno::Sequence<uno::Reference<XInterface> > aSequence { GetMap()->GetContext( pFrame ) };
290 return AccessibleRelation( nType, aSequence );
291}
292
293uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleTextFrame::getAccessibleRelationSet( )
294{
295 SolarMutexGuard aGuard;
296
298
299 // get the frame, and insert prev/next relations into helper
300
302
303 SwFlyFrame* pFlyFrame = getFlyFrame();
304 assert(pFlyFrame);
305
306 const SwFlyFrame* pPrevFrame = pFlyFrame->GetPrevLink();
307 if( pPrevFrame != nullptr )
308 pHelper->AddRelation( makeRelation(
309 AccessibleRelationType::CONTENT_FLOWS_FROM, pPrevFrame ) );
310
311 const SwFlyFrame* pNextFrame = pFlyFrame->GetNextLink();
312 if( pNextFrame != nullptr )
313 pHelper->AddRelation( makeRelation(
314 AccessibleRelationType::CONTENT_FLOWS_TO, pNextFrame ) );
315
316 return pHelper;
317}
318
319/* 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:567
const OUString & GetName() const
Definition: acccontext.hxx:334
virtual OUString SAL_CALL getAccessibleName() override
Definition: acccontext.cxx:723
void FireAccessibleEvent(css::accessibility::AccessibleEventObject &rEvent)
Definition: acccontext.cxx:440
SwAccessibleMap * GetMap()
Definition: acccontext.hxx:112
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 nIndex) override
Definition: acccontext.cxx:577
const SwFrame * GetFrame() const
Definition: accframe.hxx:103
css::uno::Reference< css::accessibility::XAccessible > GetContext(const SwFrame *pFrame, bool bCreate=true)
Definition: accmap.cxx:1792
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:3259
OUString GetObjTitle() const
Definition: atrfrm.cxx:3216
general base class for all free-flowing frames
Definition: flyfrm.hxx:79
SwFlyFrame * GetPrevLink() const
Definition: flyfrm.hxx:194
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:2905
SwFlyFrame * GetNextLink() const
Definition: flyfrm.hxx:195
Base class of the Writer layout elements.
Definition: frame.hxx:315
bool IsFlyFrame() const
Definition: frame.hxx:1210
const OUString & GetString() const
Definition: hints.hxx:364
int nCount
constexpr TypedWhichId< SwStringMsgPoolItem > RES_DESCRIPTION_CHANGED(189)
constexpr TypedWhichId< SwStringMsgPoolItem > RES_TITLE_CHANGED(188)
#define SAL_WARN(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
QPRO_FUNC_TYPE nType
sal_uInt16 GetWhich() const
Definition: calbck.hxx:75
unsigned char sal_Bool