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>
31 #include "accnotexthyperlink.hxx"
33 #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
34 
35 using namespace ::com::sun::star;
36 using 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  msTitle(),
63  msDesc()
64 {
65  const SwNoTextNode* pNd = GetNoTextNode();
66  StartListening(const_cast<SwNoTextNode*>(pNd)->GetNotifier());
67  // #i73249#
68  // consider new attributes Title and Description
69  if( pNd )
70  {
71  msTitle = pNd->GetTitle();
72 
73  msDesc = pNd->GetDescription();
74  if ( msDesc.isEmpty() &&
75  msTitle != GetName() )
76  {
77  msDesc = msTitle;
78  }
79  }
80 }
81 
83 {
84 }
85 
87 {
88  if(rHint.GetId() == SfxHintId::Dying)
90  else if(auto pLegacyModifyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
91  {
92  const sal_uInt16 nWhich = pLegacyModifyHint->m_pOld ? pLegacyModifyHint->m_pOld->Which() : pLegacyModifyHint->m_pNew ? pLegacyModifyHint->m_pNew->Which() : 0;
93  if (nWhich != RES_TITLE_CHANGED && nWhich != RES_DESCRIPTION_CHANGED)
94  return;
95  const SwNoTextNode* pNd = GetNoTextNode();
96  switch(nWhich)
97  {
98  // #i73249#
99  case RES_TITLE_CHANGED:
100  {
101  OUString sOldTitle, sNewTitle;
102  const SwStringMsgPoolItem* pOldItem = dynamic_cast<const SwStringMsgPoolItem*>(pLegacyModifyHint->m_pOld);
103  if(pOldItem)
104  sOldTitle = pOldItem->GetString();
105  const SwStringMsgPoolItem* pNewItem = dynamic_cast<const SwStringMsgPoolItem*>(pLegacyModifyHint->m_pNew);
106  if(pNewItem)
107  sNewTitle = pNewItem->GetString();
108  if(sOldTitle == sNewTitle)
109  break;
110  msTitle = sNewTitle;
111  AccessibleEventObject aEvent;
112  aEvent.EventId = AccessibleEventId::NAME_CHANGED;
113  aEvent.OldValue <<= sOldTitle;
114  aEvent.NewValue <<= msTitle;
115  FireAccessibleEvent(aEvent);
116 
117  if(!pNd->GetDescription().isEmpty())
118  break;
119  [[fallthrough]];
120  }
122  {
123  if(pNd && GetFrame())
124  {
125  const OUString sOldDesc(msDesc);
126 
127  const OUString& rDesc = pNd->GetDescription();
128  msDesc = rDesc;
129  if(msDesc.isEmpty() && msTitle != GetName())
130  msDesc = msTitle;
131 
132  if(msDesc != sOldDesc)
133  {
134  AccessibleEventObject aEvent;
135  aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
136  aEvent.OldValue <<= sOldDesc;
137  aEvent.NewValue <<= msDesc;
138  FireAccessibleEvent(aEvent);
139  }
140  }
141  }
142  }
143  }
144 }
145 
146 void SwAccessibleNoTextFrame::Dispose(bool bRecursive, bool bCanSkipInvisible)
147 {
148  SolarMutexGuard aGuard;
149  EndListeningAll();
150  SwAccessibleFrameBase::Dispose(bRecursive, bCanSkipInvisible);
151 }
152 
153 // #i73249#
155 {
156  SolarMutexGuard aGuard;
157 
158  ThrowIfDisposed();
159 
160  if ( !msTitle.isEmpty() )
161  {
162  return msTitle;
163  }
164 
166 }
167 
169 {
170  SolarMutexGuard aGuard;
171 
172  ThrowIfDisposed();
173 
174  return msDesc;
175 }
176 
177 // XInterface
178 
180 {
181  if( aType ==
183  {
184  uno::Reference<XAccessibleImage> xImage = this;
185  return uno::Any(xImage);
186  }
187  else if ( aType == cppu::UnoType<XAccessibleHypertext>::get())
188  {
189  uno::Reference<XAccessibleHypertext> aAccHypertext = this;
190  return uno::Any( aAccHypertext );
191  }
192  else
193  return SwAccessibleContext::queryInterface( aType );
194 }
195 
196 // XTypeProvider
197 
198 uno::Sequence< uno::Type > SAL_CALL SwAccessibleNoTextFrame::getTypes()
199 {
200  return cppu::OTypeCollection(
202  SwAccessibleFrameBase::getTypes() ).getTypes();
203 }
204 
206 
211 {
212  return getAccessibleDescription();
213 }
214 
216 {
217  return getSize().Height;
218 }
219 
221 {
222  return getSize().Width;
223 }
224 
225 // XAccessibleText
226 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getCaretPosition( ){return 0;}
227 sal_Bool SAL_CALL SwAccessibleNoTextFrame::setCaretPosition( sal_Int32 ){return false;}
228 sal_Unicode SAL_CALL SwAccessibleNoTextFrame::getCharacter( sal_Int32 ){return 0;}
229 css::uno::Sequence< css::beans::PropertyValue > SAL_CALL SwAccessibleNoTextFrame::getCharacterAttributes( sal_Int32 , const css::uno::Sequence< OUString >& )
230 {
231  return uno::Sequence<beans::PropertyValue>();
232 }
233 css::awt::Rectangle SAL_CALL SwAccessibleNoTextFrame::getCharacterBounds( sal_Int32 )
234 {
235  return css::awt::Rectangle(0, 0, 0, 0 );
236 }
237 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getCharacterCount( ){return 0;}
238 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getIndexAtPoint( const css::awt::Point& ){return 0;}
239 OUString SAL_CALL SwAccessibleNoTextFrame::getSelectedText( ){return OUString();}
240 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getSelectionStart( ){return 0;}
241 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getSelectionEnd( ){return 0;}
242 sal_Bool SAL_CALL SwAccessibleNoTextFrame::setSelection( sal_Int32 , sal_Int32 ){return true;}
243 OUString SAL_CALL SwAccessibleNoTextFrame::getText( ){return OUString();}
244 OUString SAL_CALL SwAccessibleNoTextFrame::getTextRange( sal_Int32 , sal_Int32 ){return OUString();}
245 css::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextAtIndex( sal_Int32 , sal_Int16 )
246 {
247  css::accessibility::TextSegment aResult;
248  return aResult;
249 }
250 css::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextBeforeIndex( sal_Int32, sal_Int16 )
251 {
252  css::accessibility::TextSegment aResult;
253  return aResult;
254 }
255 css::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextBehindIndex( sal_Int32 , sal_Int16 )
256 {
257  css::accessibility::TextSegment aResult;
258  return aResult;
259 }
260 
261 sal_Bool SAL_CALL SwAccessibleNoTextFrame::copyText( sal_Int32, sal_Int32 ){return true;}
262 
263 // XAccessibleHyperText
264 
266 {
267  SolarMutexGuard aGuard;
268 
269  ThrowIfDisposed();
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 
280 uno::Reference< XAccessibleHyperlink > SAL_CALL
282 {
283  SolarMutexGuard aGuard;
284 
285  ThrowIfDisposed();
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 
305 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getHyperLinkIndex( sal_Int32 )
306 {
307  return 0;
308 }
309 
310 uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleNoTextFrame::getAccessibleRelationSet( )
311 {
312  return new AccessibleRelationSetHelper();
313 }
314 
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Int32 SAL_CALL getAccessibleImageHeight() override
virtual css::awt::Size SAL_CALL getSize() override
Definition: acccontext.cxx:910
void FireAccessibleEvent(css::accessibility::AccessibleEventObject &rEvent)
Definition: acccontext.cxx:440
virtual css::accessibility::TextSegment SAL_CALL getTextBehindIndex(sal_Int32 nIndex, sal_Int16 aTextType) override
virtual sal_Bool SAL_CALL copyText(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual OUString SAL_CALL getTextRange(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual OUString SAL_CALL getAccessibleImageDescription() override
XAccessibleImage.
virtual void Notify(const SfxHint &) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
SfxHintId GetId() const
virtual css::accessibility::TextSegment SAL_CALL getTextBeforeIndex(sal_Int32 nIndex, sal_Int16 aTextType) override
virtual css::awt::Rectangle SAL_CALL getCharacterBounds(sal_Int32 nIndex) override
virtual OUString SAL_CALL getText() override
virtual css::uno::Reference< css::accessibility::XAccessibleHyperlink > SAL_CALL getHyperLink(sal_Int32 nLinkIndex) override
sal_uInt16 sal_Unicode
virtual ~SwAccessibleNoTextFrame() override
virtual sal_Bool SAL_CALL setCaretPosition(sal_Int32 nIndex) override
virtual sal_Int32 SAL_CALL getHyperLinkIndex(sal_Int32 nCharIndex) override
const SwFrame * GetFrame() const
Definition: accframe.hxx:103
virtual sal_Bool SAL_CALL setSelection(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
const OUString & GetString() const
Definition: hints.hxx:293
virtual sal_Int32 SAL_CALL getSelectionEnd() override
virtual sal_Int32 SAL_CALL getIndexAtPoint(const css::awt::Point &aPoint) override
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCharacterAttributes(sal_Int32 nIndex, const css::uno::Sequence< OUString > &aRequestedAttributes) override
void EndListeningAll()
#define RES_TITLE_CHANGED
Definition: hintids.hxx:312
virtual OUString SAL_CALL getAccessibleName() override
const OUString & GetName() const
Definition: acccontext.hxx:333
virtual sal_Int32 SAL_CALL getCharacterCount() override
const SwFrame * Lower() const
Definition: layfrm.hxx:101
SwNoTextNode * GetNoTextNode()
Definition: ndnotxt.hxx:96
SwAccessibleNoTextFrame(std::shared_ptr< SwAccessibleMap > const &pInitMap, sal_Int16 nInitRole, const SwFlyFrame *pFlyFrame)
unsigned char sal_Bool
virtual OUString SAL_CALL getSelectedText() override
friend class SwAccessibleNoTextHyperlink
virtual sal_Unicode SAL_CALL getCharacter(sal_Int32 nIndex) override
OUString GetDescription() const
Definition: ndnotxt.cxx:281
bool StartListening(SvtBroadcaster &rBroadcaster)
const SwNoTextNode * GetNoTextNode() const
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
#define RES_DESCRIPTION_CHANGED
Definition: hintids.hxx:313
virtual sal_Int32 SAL_CALL getAccessibleImageWidth() override
const ImageMap * GetMap() const
Definition: fmturl.hxx:68
const SwContentNode * GetNode() const
Definition: notxtfrm.hxx:60
virtual OUString SAL_CALL getAccessibleName() override
Definition: acccontext.cxx:677
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
general base class for all free-flowing frames
Definition: flyfrm.hxx:60
OUString GetTitle() const
Definition: ndnotxt.cxx:257
bool IsNoTextFrame() const
Definition: frame.hxx:1214
virtual OUString SAL_CALL getAccessibleDescription() override
Return this object's description.
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
css::uno::Reference< css::accessibility::XAccessibleHyperlink > m_xHyperlink
virtual sal_Int32 SAL_CALL getSelectionStart() override
virtual void Dispose(bool bRecursive, bool bCanSkipInvisible=true) override
virtual sal_Int32 SAL_CALL getCaretPosition() override
virtual css::accessibility::TextSegment SAL_CALL getTextAtIndex(sal_Int32 nIndex, sal_Int16 aTextType) override
virtual sal_Int32 SAL_CALL getHyperLinkCount() override
virtual void Dispose(bool bRecursive, bool bCanSkipInvisible=true) override
const OUString & GetURL() const
Definition: fmturl.hxx:66