android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / access / accnotextframe.cxx
blobd3f7c38bae77dcdb489bbc350f4f262943ecd41a
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 <vcl/svapp.hxx>
21 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
22 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23 #include <cppuhelper/typeprovider.hxx>
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"
32 #include <unotools/accessiblerelationsethelper.hxx>
33 #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::accessibility;
37 using utl::AccessibleRelationSetHelper;
39 const SwNoTextNode *SwAccessibleNoTextFrame::GetNoTextNode() const
41 const SwNoTextNode *pNd = nullptr;
42 const SwFlyFrame *pFlyFrame = static_cast< const SwFlyFrame *>( GetFrame() );
43 if( pFlyFrame->Lower() && pFlyFrame->Lower()->IsNoTextFrame() )
45 const SwNoTextFrame *pContentFrame =
46 static_cast<const SwNoTextFrame *>(pFlyFrame->Lower());
47 const SwContentNode* pSwContentNode = pContentFrame->GetNode();
48 if(pSwContentNode != nullptr)
50 pNd = pSwContentNode->GetNoTextNode();
54 return pNd;
57 SwAccessibleNoTextFrame::SwAccessibleNoTextFrame(
58 std::shared_ptr<SwAccessibleMap> const& pInitMap,
59 sal_Int16 nInitRole,
60 const SwFlyFrame* pFlyFrame ) :
61 SwAccessibleFrameBase( pInitMap, nInitRole, pFlyFrame )
63 const SwNoTextNode* pNd = GetNoTextNode();
64 // #i73249#
65 // consider new attributes Title and Description
66 if( pNd )
68 StartListening(const_cast<SwNoTextNode*>(pNd)->GetNotifier());
69 msTitle = pNd->GetTitle();
71 msDesc = pNd->GetDescription();
72 if ( msDesc.isEmpty() &&
73 msTitle != GetName() )
75 msDesc = msTitle;
80 SwAccessibleNoTextFrame::~SwAccessibleNoTextFrame()
84 void SwAccessibleNoTextFrame::Notify(const SfxHint& rHint)
86 const SwNoTextNode* pNd = GetNoTextNode();
87 switch(rHint.GetId())
89 case SfxHintId::Dying:
90 EndListeningAll();
91 return;
92 default:
93 return;
94 case SfxHintId::SwTitleChanged:
96 auto rTitleChanged = static_cast<const sw::TitleChanged&>(rHint);
97 if(rTitleChanged.m_sOld == rTitleChanged.m_sNew)
98 break;
99 msTitle = rTitleChanged.m_sNew;
100 AccessibleEventObject aEvent;
101 aEvent.EventId = AccessibleEventId::NAME_CHANGED;
102 aEvent.OldValue <<= rTitleChanged.m_sOld;
103 aEvent.NewValue <<= msTitle;
104 FireAccessibleEvent(aEvent);
106 if(!pNd->GetDescription().isEmpty())
107 break;
108 [[fallthrough]];
110 case SfxHintId::SwDescriptionChanged:
111 if(pNd && GetFrame())
113 const OUString sOldDesc(msDesc);
114 msDesc = pNd->GetDescription();
115 if(msDesc.isEmpty() && msTitle != GetName())
116 msDesc = msTitle;
117 if(msDesc == sOldDesc)
118 return;
119 AccessibleEventObject aEvent;
120 aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
121 aEvent.OldValue <<= sOldDesc;
122 aEvent.NewValue <<= msDesc;
123 FireAccessibleEvent(aEvent);
125 return;
129 void SwAccessibleNoTextFrame::Dispose(bool bRecursive, bool bCanSkipInvisible)
131 SolarMutexGuard aGuard;
132 EndListeningAll();
133 SwAccessibleFrameBase::Dispose(bRecursive, bCanSkipInvisible);
136 // #i73249#
137 OUString SAL_CALL SwAccessibleNoTextFrame::getAccessibleName()
139 SolarMutexGuard aGuard;
141 ThrowIfDisposed();
143 if ( !msTitle.isEmpty() )
145 return msTitle;
148 return SwAccessibleFrameBase::getAccessibleName();
151 OUString SAL_CALL SwAccessibleNoTextFrame::getAccessibleDescription()
153 SolarMutexGuard aGuard;
155 ThrowIfDisposed();
157 return msDesc;
160 // XInterface
162 uno::Any SAL_CALL SwAccessibleNoTextFrame::queryInterface( const uno::Type& aType )
164 if( aType ==
165 ::cppu::UnoType<XAccessibleImage>::get() )
167 uno::Reference<XAccessibleImage> xImage = this;
168 return uno::Any(xImage);
170 else if ( aType == cppu::UnoType<XAccessibleHypertext>::get())
172 uno::Reference<XAccessibleHypertext> aAccHypertext = this;
173 return uno::Any( aAccHypertext );
175 else
176 return SwAccessibleContext::queryInterface( aType );
179 // XTypeProvider
181 uno::Sequence< uno::Type > SAL_CALL SwAccessibleNoTextFrame::getTypes()
183 return cppu::OTypeCollection(
184 ::cppu::UnoType<XAccessibleImage>::get(),
185 SwAccessibleFrameBase::getTypes() ).getTypes();
188 /// XAccessibleImage
189 /** implementation of the XAccessibleImage methods is a no-brainer, as
190 all relevant information is already accessible through other
191 methods. So we just delegate to those. */
193 OUString SAL_CALL SwAccessibleNoTextFrame::getAccessibleImageDescription()
195 return getAccessibleDescription();
198 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getAccessibleImageHeight( )
200 return getSize().Height;
203 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getAccessibleImageWidth( )
205 return getSize().Width;
208 // XAccessibleText
209 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getCaretPosition( ){return 0;}
210 sal_Bool SAL_CALL SwAccessibleNoTextFrame::setCaretPosition( sal_Int32 ){return false;}
211 sal_Unicode SAL_CALL SwAccessibleNoTextFrame::getCharacter( sal_Int32 ){return 0;}
212 css::uno::Sequence< css::beans::PropertyValue > SAL_CALL SwAccessibleNoTextFrame::getCharacterAttributes( sal_Int32 , const css::uno::Sequence< OUString >& )
214 return uno::Sequence<beans::PropertyValue>();
216 css::awt::Rectangle SAL_CALL SwAccessibleNoTextFrame::getCharacterBounds( sal_Int32 )
218 return css::awt::Rectangle(0, 0, 0, 0 );
220 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getCharacterCount( ){return 0;}
221 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getIndexAtPoint( const css::awt::Point& ){return 0;}
222 OUString SAL_CALL SwAccessibleNoTextFrame::getSelectedText( ){return OUString();}
223 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getSelectionStart( ){return 0;}
224 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getSelectionEnd( ){return 0;}
225 sal_Bool SAL_CALL SwAccessibleNoTextFrame::setSelection( sal_Int32 , sal_Int32 ){return true;}
226 OUString SAL_CALL SwAccessibleNoTextFrame::getText( ){return OUString();}
227 OUString SAL_CALL SwAccessibleNoTextFrame::getTextRange( sal_Int32 , sal_Int32 ){return OUString();}
228 css::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextAtIndex( sal_Int32 , sal_Int16 )
230 css::accessibility::TextSegment aResult;
231 return aResult;
233 css::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextBeforeIndex( sal_Int32, sal_Int16 )
235 css::accessibility::TextSegment aResult;
236 return aResult;
238 css::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextBehindIndex( sal_Int32 , sal_Int16 )
240 css::accessibility::TextSegment aResult;
241 return aResult;
244 sal_Bool SAL_CALL SwAccessibleNoTextFrame::copyText( sal_Int32, sal_Int32 ){return true;}
245 sal_Bool SAL_CALL SwAccessibleNoTextFrame::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType ){return false;}
247 // XAccessibleHyperText
249 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getHyperLinkCount()
251 SolarMutexGuard aGuard;
253 ThrowIfDisposed();
255 sal_Int32 nCount = 0;
256 SwFormatURL aURL( static_cast<const SwLayoutFrame*>(GetFrame())->GetFormat()->GetURL() );
258 if(aURL.GetMap() || !aURL.GetURL().isEmpty())
259 nCount = 1;
261 return nCount;
264 uno::Reference< XAccessibleHyperlink > SAL_CALL
265 SwAccessibleNoTextFrame::getHyperLink( sal_Int32 nLinkIndex )
267 SolarMutexGuard aGuard;
269 ThrowIfDisposed();
271 SwFormatURL aURL( static_cast<const SwLayoutFrame*>(GetFrame())->GetFormat()->GetURL() );
273 if( nLinkIndex > 0 )
274 throw lang::IndexOutOfBoundsException();
276 if( aURL.GetMap() || !aURL.GetURL().isEmpty() )
278 if ( !m_xHyperlink.is() )
280 m_xHyperlink = new SwAccessibleNoTextHyperlink( this, GetFrame() );
283 return m_xHyperlink;
286 return nullptr;
289 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getHyperLinkIndex( sal_Int32 )
291 return 0;
294 uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleNoTextFrame::getAccessibleRelationSet( )
296 return new AccessibleRelationSetHelper();
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */