LibreOffice Module sw (master) 1
accnotextframe.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 <vcl/svapp.hxx>
21#include <com/sun/star/accessibility/AccessibleEventId.hpp>
22#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24#include <frmfmt.hxx>
25#include <ndnotxt.hxx>
26#include <flyfrm.hxx>
27#include <notxtfrm.hxx>
28#include <hints.hxx>
29#include "accnotextframe.hxx"
30#include <fmturl.hxx>
33#include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
34
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::accessibility;
38
40{
41 const SwNoTextNode *pNd = nullptr;
42 const SwFlyFrame *pFlyFrame = static_cast< const SwFlyFrame *>( GetFrame() );
43 if( pFlyFrame->Lower() && pFlyFrame->Lower()->IsNoTextFrame() )
44 {
45 const SwNoTextFrame *pContentFrame =
46 static_cast<const SwNoTextFrame *>(pFlyFrame->Lower());
47 const SwContentNode* pSwContentNode = pContentFrame->GetNode();
48 if(pSwContentNode != nullptr)
49 {
50 pNd = pSwContentNode->GetNoTextNode();
51 }
52 }
53
54 return pNd;
55}
56
58 std::shared_ptr<SwAccessibleMap> const& pInitMap,
59 sal_Int16 nInitRole,
60 const SwFlyFrame* pFlyFrame ) :
61 SwAccessibleFrameBase( pInitMap, nInitRole, pFlyFrame )
62{
63 const SwNoTextNode* pNd = GetNoTextNode();
64 // #i73249#
65 // consider new attributes Title and Description
66 if( pNd )
67 {
68 StartListening(const_cast<SwNoTextNode*>(pNd)->GetNotifier());
69 msTitle = pNd->GetTitle();
70
71 msDesc = pNd->GetDescription();
72 if ( msDesc.isEmpty() &&
73 msTitle != GetName() )
74 {
76 }
77 }
78}
79
81{
82}
83
85{
86 if(rHint.GetId() == SfxHintId::Dying)
88 else if (rHint.GetId() == SfxHintId::SwLegacyModify)
89 {
90 auto pLegacyModifyHint = static_cast<const sw::LegacyModifyHint*>(&rHint);
91 const sal_uInt16 nWhich = pLegacyModifyHint->GetWhich();
92 if (nWhich != RES_TITLE_CHANGED && nWhich != RES_DESCRIPTION_CHANGED)
93 return;
94 const SwNoTextNode* pNd = GetNoTextNode();
95 switch(nWhich)
96 {
97 // #i73249#
99 {
100 OUString sOldTitle, sNewTitle;
101 const SwStringMsgPoolItem* pOldItem = dynamic_cast<const SwStringMsgPoolItem*>(pLegacyModifyHint->m_pOld);
102 if(pOldItem)
103 sOldTitle = pOldItem->GetString();
104 const SwStringMsgPoolItem* pNewItem = dynamic_cast<const SwStringMsgPoolItem*>(pLegacyModifyHint->m_pNew);
105 if(pNewItem)
106 sNewTitle = pNewItem->GetString();
107 if(sOldTitle == sNewTitle)
108 break;
109 msTitle = sNewTitle;
110 AccessibleEventObject aEvent;
111 aEvent.EventId = AccessibleEventId::NAME_CHANGED;
112 aEvent.OldValue <<= sOldTitle;
113 aEvent.NewValue <<= msTitle;
115
116 if(!pNd->GetDescription().isEmpty())
117 break;
118 [[fallthrough]];
119 }
121 {
122 if(pNd && GetFrame())
123 {
124 const OUString sOldDesc(msDesc);
125
126 const OUString& rDesc = pNd->GetDescription();
127 msDesc = rDesc;
128 if(msDesc.isEmpty() && msTitle != GetName())
129 msDesc = msTitle;
130
131 if(msDesc != sOldDesc)
132 {
133 AccessibleEventObject aEvent;
134 aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
135 aEvent.OldValue <<= sOldDesc;
136 aEvent.NewValue <<= msDesc;
138 }
139 }
140 }
141 }
142 }
143}
144
145void SwAccessibleNoTextFrame::Dispose(bool bRecursive, bool bCanSkipInvisible)
146{
147 SolarMutexGuard aGuard;
149 SwAccessibleFrameBase::Dispose(bRecursive, bCanSkipInvisible);
150}
151
152// #i73249#
154{
155 SolarMutexGuard aGuard;
156
158
159 if ( !msTitle.isEmpty() )
160 {
161 return msTitle;
162 }
163
165}
166
168{
169 SolarMutexGuard aGuard;
170
172
173 return msDesc;
174}
175
176// XInterface
177
179{
180 if( aType ==
182 {
183 uno::Reference<XAccessibleImage> xImage = this;
184 return uno::Any(xImage);
185 }
186 else if ( aType == cppu::UnoType<XAccessibleHypertext>::get())
187 {
188 uno::Reference<XAccessibleHypertext> aAccHypertext = this;
189 return uno::Any( aAccHypertext );
190 }
191 else
192 return SwAccessibleContext::queryInterface( aType );
193}
194
195// XTypeProvider
196
197uno::Sequence< uno::Type > SAL_CALL SwAccessibleNoTextFrame::getTypes()
198{
201 SwAccessibleFrameBase::getTypes() ).getTypes();
202}
203
205
210{
212}
213
215{
216 return getSize().Height;
217}
218
220{
221 return getSize().Width;
222}
223
224// XAccessibleText
225sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getCaretPosition( ){return 0;}
226sal_Bool SAL_CALL SwAccessibleNoTextFrame::setCaretPosition( sal_Int32 ){return false;}
228css::uno::Sequence< css::beans::PropertyValue > SAL_CALL SwAccessibleNoTextFrame::getCharacterAttributes( sal_Int32 , const css::uno::Sequence< OUString >& )
229{
230 return uno::Sequence<beans::PropertyValue>();
231}
232css::awt::Rectangle SAL_CALL SwAccessibleNoTextFrame::getCharacterBounds( sal_Int32 )
233{
234 return css::awt::Rectangle(0, 0, 0, 0 );
235}
236sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getCharacterCount( ){return 0;}
237sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getIndexAtPoint( const css::awt::Point& ){return 0;}
238OUString SAL_CALL SwAccessibleNoTextFrame::getSelectedText( ){return OUString();}
239sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getSelectionStart( ){return 0;}
240sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getSelectionEnd( ){return 0;}
241sal_Bool SAL_CALL SwAccessibleNoTextFrame::setSelection( sal_Int32 , sal_Int32 ){return true;}
242OUString SAL_CALL SwAccessibleNoTextFrame::getText( ){return OUString();}
243OUString SAL_CALL SwAccessibleNoTextFrame::getTextRange( sal_Int32 , sal_Int32 ){return OUString();}
244css::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextAtIndex( sal_Int32 , sal_Int16 )
245{
246 css::accessibility::TextSegment aResult;
247 return aResult;
248}
249css::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextBeforeIndex( sal_Int32, sal_Int16 )
250{
251 css::accessibility::TextSegment aResult;
252 return aResult;
253}
254css::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextBehindIndex( sal_Int32 , sal_Int16 )
255{
256 css::accessibility::TextSegment aResult;
257 return aResult;
258}
259
260sal_Bool SAL_CALL SwAccessibleNoTextFrame::copyText( sal_Int32, sal_Int32 ){return true;}
261sal_Bool SAL_CALL SwAccessibleNoTextFrame::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType ){return false;}
262
263// XAccessibleHyperText
264
266{
267 SolarMutexGuard aGuard;
268
270
271 sal_Int32 nCount = 0;
272 SwFormatURL aURL( static_cast<const SwLayoutFrame*>(GetFrame())->GetFormat()->GetURL() );
273
274 if(aURL.GetMap() || !aURL.GetURL().isEmpty())
275 nCount = 1;
276
277 return nCount;
278}
279
280uno::Reference< XAccessibleHyperlink > SAL_CALL
282{
283 SolarMutexGuard aGuard;
284
286
287 SwFormatURL aURL( static_cast<const SwLayoutFrame*>(GetFrame())->GetFormat()->GetURL() );
288
289 if( nLinkIndex > 0 )
290 throw lang::IndexOutOfBoundsException();
291
292 if( aURL.GetMap() || !aURL.GetURL().isEmpty() )
293 {
294 if ( !m_xHyperlink.is() )
295 {
297 }
298
299 return m_xHyperlink;
300 }
301
302 return nullptr;
303}
304
305sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getHyperLinkIndex( sal_Int32 )
306{
307 return 0;
308}
309
310uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleNoTextFrame::getAccessibleRelationSet( )
311{
312 return new AccessibleRelationSetHelper();
313}
314
315/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
SfxHintId GetId() const
void EndListeningAll()
bool StartListening(SvtBroadcaster &rBroadcaster)
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
virtual css::awt::Size SAL_CALL getSize() override
Definition: acccontext.cxx:953
virtual void Dispose(bool bRecursive, bool bCanSkipInvisible=true) override
const SwFrame * GetFrame() const
Definition: accframe.hxx:103
css::uno::Reference< css::accessibility::XAccessibleHyperlink > m_xHyperlink
virtual void Dispose(bool bRecursive, bool bCanSkipInvisible=true) override
virtual sal_Int32 SAL_CALL getAccessibleImageHeight() override
virtual sal_Int32 SAL_CALL getHyperLinkCount() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
virtual sal_Bool SAL_CALL copyText(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual sal_Bool SAL_CALL setSelection(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual void Notify(const SfxHint &) override
virtual css::accessibility::TextSegment SAL_CALL getTextBehindIndex(sal_Int32 nIndex, sal_Int16 aTextType) override
virtual OUString SAL_CALL getAccessibleDescription() override
Return this object's description.
virtual css::accessibility::TextSegment SAL_CALL getTextBeforeIndex(sal_Int32 nIndex, sal_Int16 aTextType) override
virtual sal_Int32 SAL_CALL getIndexAtPoint(const css::awt::Point &aPoint) override
virtual OUString SAL_CALL getText() override
virtual sal_Int32 SAL_CALL getAccessibleImageWidth() override
virtual OUString SAL_CALL getAccessibleName() override
virtual ~SwAccessibleNoTextFrame() override
virtual OUString SAL_CALL getTextRange(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual sal_Int32 SAL_CALL getCharacterCount() override
virtual OUString SAL_CALL getAccessibleImageDescription() override
XAccessibleImage.
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCharacterAttributes(sal_Int32 nIndex, const css::uno::Sequence< OUString > &aRequestedAttributes) override
virtual OUString SAL_CALL getSelectedText() override
virtual sal_Int32 SAL_CALL getHyperLinkIndex(sal_Int32 nCharIndex) override
virtual sal_Int32 SAL_CALL getCaretPosition() override
const SwNoTextNode * GetNoTextNode() const
virtual css::awt::Rectangle SAL_CALL getCharacterBounds(sal_Int32 nIndex) override
virtual sal_Int32 SAL_CALL getSelectionStart() override
virtual sal_Bool SAL_CALL setCaretPosition(sal_Int32 nIndex) override
SwAccessibleNoTextFrame(std::shared_ptr< SwAccessibleMap > const &pInitMap, sal_Int16 nInitRole, const SwFlyFrame *pFlyFrame)
virtual sal_Unicode SAL_CALL getCharacter(sal_Int32 nIndex) override
virtual sal_Bool SAL_CALL scrollSubstringTo(sal_Int32 nStartIndex, sal_Int32 nEndIndex, css::accessibility::AccessibleScrollType aScrollType) override
virtual css::accessibility::TextSegment SAL_CALL getTextAtIndex(sal_Int32 nIndex, sal_Int16 aTextType) override
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
friend class SwAccessibleNoTextHyperlink
virtual css::uno::Reference< css::accessibility::XAccessibleHyperlink > SAL_CALL getHyperLink(sal_Int32 nLinkIndex) override
virtual sal_Int32 SAL_CALL getSelectionEnd() override
general base class for all free-flowing frames
Definition: flyfrm.hxx:79
bool IsNoTextFrame() const
Definition: frame.hxx:1238
A layout frame is a frame that contains other frames (m_pLower), e.g. SwPageFrame or SwTabFrame.
Definition: layfrm.hxx:36
const SwFrame * Lower() const
Definition: layfrm.hxx:101
const SwContentNode * GetNode() const
Definition: notxtfrm.hxx:77
Layout frame for SwNoTextNode, i.e. graphics and OLE nodes (including charts).
Definition: ndnotxt.hxx:30
OUString GetDescription() const
Definition: ndnotxt.cxx:282
OUString GetTitle() const
Definition: ndnotxt.cxx:258
SwNoTextNode * GetNoTextNode()
Definition: ndnotxt.hxx:95
const OUString & GetString() const
Definition: hints.hxx:364
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
int nCount
URL aURL
virtual OUString GetURL() const override
virtual SotClipboardFormatId GetFormat(const TransferableDataHelper &aHelper) override
constexpr TypedWhichId< SwStringMsgPoolItem > RES_DESCRIPTION_CHANGED(189)
constexpr TypedWhichId< SwStringMsgPoolItem > RES_TITLE_CHANGED(188)
sal_uInt16 GetWhich() const
Definition: calbck.hxx:75
unsigned char sal_Bool
sal_uInt16 sal_Unicode