Line data Source code
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 <osl/mutex.hxx>
21 : #include <vcl/svapp.hxx>
22 : #include <com/sun/star/accessibility/AccessibleRole.hpp>
23 : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
24 : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
25 : #include <unotools/accessiblestatesethelper.hxx>
26 : #include <frmfmt.hxx>
27 : #include <ndnotxt.hxx>
28 : #include <flyfrm.hxx>
29 : #include <cntfrm.hxx>
30 : #include <hints.hxx>
31 : #include "accnotextframe.hxx"
32 : #include <fmturl.hxx>
33 : #include <accnotexthyperlink.hxx>
34 : #include <svtools/imap.hxx>
35 : #include <unotools/accessiblerelationsethelper.hxx>
36 : #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
37 : #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
38 : #include <doc.hxx>
39 :
40 : using namespace ::com::sun::star;
41 : using namespace ::com::sun::star::accessibility;
42 : using utl::AccessibleRelationSetHelper;
43 :
44 4 : const SwNoTxtNode *SwAccessibleNoTextFrame::GetNoTxtNode() const
45 : {
46 4 : const SwNoTxtNode *pNd = 0;
47 4 : const SwFlyFrm *pFlyFrm = static_cast< const SwFlyFrm *>( GetFrm() );
48 4 : if( pFlyFrm->Lower() && pFlyFrm->Lower()->IsNoTxtFrm() )
49 : {
50 : const SwCntntFrm *pCntFrm =
51 4 : static_cast<const SwCntntFrm *>( pFlyFrm->Lower() );
52 4 : const SwCntntNode* pSwCntntNode = pCntFrm->GetNode();
53 4 : if(pSwCntntNode != NULL)
54 : {
55 4 : pNd = pSwCntntNode->GetNoTxtNode();
56 : }
57 : }
58 :
59 4 : return pNd;
60 : }
61 :
62 2 : SwAccessibleNoTextFrame::SwAccessibleNoTextFrame(
63 : SwAccessibleMap* pInitMap,
64 : sal_Int16 nInitRole,
65 : const SwFlyFrm* pFlyFrm ) :
66 : SwAccessibleFrameBase( pInitMap, nInitRole, pFlyFrm ),
67 2 : aDepend( this, const_cast < SwNoTxtNode * >( GetNoTxtNode() ) ),
68 : msTitle(),
69 4 : msDesc()
70 : {
71 2 : const SwNoTxtNode* pNd = GetNoTxtNode();
72 : // #i73249#
73 : // consider new attributes Title and Description
74 2 : if( pNd )
75 : {
76 2 : msTitle = pNd->GetTitle();
77 :
78 2 : msDesc = pNd->GetDescription();
79 4 : if ( msDesc.isEmpty() &&
80 2 : msTitle != GetName() )
81 : {
82 2 : msDesc = msTitle;
83 : }
84 : }
85 2 : }
86 :
87 2 : SwAccessibleNoTextFrame::~SwAccessibleNoTextFrame()
88 : {
89 2 : }
90 :
91 0 : void SwAccessibleNoTextFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
92 : {
93 0 : const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
94 : // #i73249#
95 : // suppress handling of RES_NAME_CHANGED in case that attribute Title is
96 : // used as the accessible name.
97 0 : if ( nWhich != RES_NAME_CHANGED ||
98 0 : msTitle.isEmpty() )
99 : {
100 0 : SwAccessibleFrameBase::Modify( pOld, pNew );
101 0 : if (!GetRegisteredIn())
102 0 : return; // probably was deleted - avoid doing anything
103 : }
104 :
105 0 : const SwNoTxtNode *pNd = GetNoTxtNode();
106 : OSL_ENSURE( pNd == aDepend.GetRegisteredIn(), "invalid frame" );
107 0 : switch( nWhich )
108 : {
109 : // #i73249#
110 : case RES_TITLE_CHANGED:
111 : {
112 0 : OUString sOldTitle, sNewTitle;
113 0 : const SwStringMsgPoolItem* pOldItem = dynamic_cast<const SwStringMsgPoolItem*>(pOld);
114 0 : if (pOldItem)
115 0 : sOldTitle = pOldItem->GetString();
116 0 : const SwStringMsgPoolItem* pNewItem = dynamic_cast<const SwStringMsgPoolItem*>(pNew);
117 0 : if (pNewItem)
118 0 : sNewTitle = pNewItem->GetString();
119 0 : if ( sOldTitle == sNewTitle )
120 : {
121 0 : break;
122 : }
123 0 : msTitle = sNewTitle;
124 0 : AccessibleEventObject aEvent;
125 0 : aEvent.EventId = AccessibleEventId::NAME_CHANGED;
126 0 : aEvent.OldValue <<= sOldTitle;
127 0 : aEvent.NewValue <<= msTitle;
128 0 : FireAccessibleEvent( aEvent );
129 :
130 0 : if ( !pNd->GetDescription().isEmpty() )
131 : {
132 0 : break;
133 0 : }
134 : }
135 : // intentional no break here
136 : case RES_DESCRIPTION_CHANGED:
137 : {
138 0 : if ( pNd && GetFrm() )
139 : {
140 0 : const OUString sOldDesc( msDesc );
141 :
142 0 : const OUString& rDesc = pNd->GetDescription();
143 0 : msDesc = rDesc;
144 0 : if ( msDesc.isEmpty() &&
145 0 : msTitle != GetName() )
146 : {
147 0 : msDesc = msTitle;
148 : }
149 :
150 0 : if ( msDesc != sOldDesc )
151 : {
152 0 : AccessibleEventObject aEvent;
153 0 : aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
154 0 : aEvent.OldValue <<= sOldDesc;
155 0 : aEvent.NewValue <<= msDesc;
156 0 : FireAccessibleEvent( aEvent );
157 0 : }
158 : }
159 : }
160 0 : break;
161 : }
162 : }
163 :
164 2 : void SwAccessibleNoTextFrame::Dispose( bool bRecursive )
165 : {
166 2 : SolarMutexGuard aGuard;
167 :
168 2 : if( aDepend.GetRegisteredIn() )
169 2 : const_cast < SwModify *>( aDepend.GetRegisteredIn() )->Remove( &aDepend );
170 :
171 2 : SwAccessibleFrameBase::Dispose( bRecursive );
172 2 : }
173 :
174 : // #i73249#
175 0 : OUString SAL_CALL SwAccessibleNoTextFrame::getAccessibleName (void)
176 : throw (uno::RuntimeException, std::exception)
177 : {
178 0 : SolarMutexGuard aGuard;
179 :
180 0 : CHECK_FOR_DEFUNC( XAccessibleContext )
181 :
182 0 : if ( !msTitle.isEmpty() )
183 : {
184 0 : return msTitle;
185 : }
186 :
187 0 : return SwAccessibleFrameBase::getAccessibleName();
188 : }
189 :
190 0 : OUString SAL_CALL SwAccessibleNoTextFrame::getAccessibleDescription (void)
191 : throw (uno::RuntimeException, std::exception)
192 : {
193 0 : SolarMutexGuard aGuard;
194 :
195 0 : CHECK_FOR_DEFUNC( XAccessibleContext )
196 :
197 0 : return msDesc;
198 : }
199 :
200 : // XInterface
201 :
202 140 : uno::Any SAL_CALL SwAccessibleNoTextFrame::queryInterface( const uno::Type& aType )
203 : throw (uno::RuntimeException, std::exception)
204 : {
205 140 : if( aType ==
206 140 : ::cppu::UnoType<XAccessibleImage>::get() )
207 : {
208 0 : uno::Reference<XAccessibleImage> xImage = this;
209 0 : uno::Any aAny;
210 0 : aAny <<= xImage;
211 0 : return aAny;
212 : }
213 140 : else if ( aType == cppu::UnoType<XAccessibleHypertext>::get())
214 : {
215 0 : uno::Reference<XAccessibleHypertext> aAccHypertext = this;
216 0 : uno::Any aAny;
217 0 : aAny <<= aAccHypertext;
218 0 : return aAny;
219 : }
220 : else
221 140 : return SwAccessibleContext::queryInterface( aType );
222 : }
223 :
224 : // XTypeProvider
225 :
226 0 : uno::Sequence< uno::Type > SAL_CALL SwAccessibleNoTextFrame::getTypes() throw(uno::RuntimeException, std::exception)
227 : {
228 0 : uno::Sequence< uno::Type > aTypes( SwAccessibleFrameBase::getTypes() );
229 :
230 0 : sal_Int32 nIndex = aTypes.getLength();
231 0 : aTypes.realloc( nIndex + 1 );
232 :
233 0 : uno::Type* pTypes = aTypes.getArray();
234 0 : pTypes[nIndex] = ::cppu::UnoType<XAccessibleImage>::get();
235 :
236 0 : return aTypes;
237 : }
238 :
239 : /// XAccessibleImage
240 : /** implementation of the XAccessibleImage methods is a no-brainer, as
241 : all relevant information is already accessible through other
242 : methods. So we just delegate to those. */
243 :
244 0 : OUString SAL_CALL SwAccessibleNoTextFrame::getAccessibleImageDescription()
245 : throw ( uno::RuntimeException, std::exception )
246 : {
247 0 : return getAccessibleDescription();
248 : }
249 :
250 0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getAccessibleImageHeight( )
251 : throw ( uno::RuntimeException, std::exception )
252 : {
253 0 : return getSize().Height;
254 : }
255 :
256 0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getAccessibleImageWidth( )
257 : throw ( uno::RuntimeException, std::exception )
258 : {
259 0 : return getSize().Width;
260 : }
261 :
262 : // XAccesibleText
263 0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException, std::exception){return 0;}
264 0 : sal_Bool SAL_CALL SwAccessibleNoTextFrame::setCaretPosition( sal_Int32 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception){return 0;}
265 0 : sal_Unicode SAL_CALL SwAccessibleNoTextFrame::getCharacter( sal_Int32 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception){return 0;}
266 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL SwAccessibleNoTextFrame::getCharacterAttributes( sal_Int32 , const ::com::sun::star::uno::Sequence< OUString >& ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
267 : {
268 0 : uno::Sequence<beans::PropertyValue> aValues(0);
269 0 : return aValues;
270 : }
271 0 : ::com::sun::star::awt::Rectangle SAL_CALL SwAccessibleNoTextFrame::getCharacterBounds( sal_Int32 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
272 : {
273 0 : return com::sun::star::awt::Rectangle(0, 0, 0, 0 );
274 : }
275 0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception){return 0;}
276 0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getIndexAtPoint( const ::com::sun::star::awt::Point& ) throw (::com::sun::star::uno::RuntimeException, std::exception){return 0;}
277 0 : OUString SAL_CALL SwAccessibleNoTextFrame::getSelectedText( ) throw (::com::sun::star::uno::RuntimeException, std::exception){return OUString();}
278 0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException, std::exception){return 0;}
279 0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException, std::exception){return 0;}
280 0 : sal_Bool SAL_CALL SwAccessibleNoTextFrame::setSelection( sal_Int32 , sal_Int32 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception){return sal_True;}
281 0 : OUString SAL_CALL SwAccessibleNoTextFrame::getText( ) throw (::com::sun::star::uno::RuntimeException, std::exception){return OUString();}
282 0 : OUString SAL_CALL SwAccessibleNoTextFrame::getTextRange( sal_Int32 , sal_Int32 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception){return OUString();}
283 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextAtIndex( sal_Int32 , sal_Int16 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
284 : {
285 0 : ::com::sun::star::accessibility::TextSegment aResult;
286 0 : return aResult;
287 : }
288 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextBeforeIndex( sal_Int32, sal_Int16 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
289 : {
290 0 : ::com::sun::star::accessibility::TextSegment aResult;
291 0 : return aResult;
292 : }
293 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL SwAccessibleNoTextFrame::getTextBehindIndex( sal_Int32 , sal_Int16 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
294 : {
295 0 : ::com::sun::star::accessibility::TextSegment aResult;
296 0 : return aResult;
297 : }
298 :
299 0 : sal_Bool SAL_CALL SwAccessibleNoTextFrame::copyText( sal_Int32, sal_Int32 ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception){return sal_True;}
300 :
301 : // XAccessibleHyperText
302 :
303 0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getHyperLinkCount()
304 : throw (uno::RuntimeException, std::exception)
305 : {
306 0 : SolarMutexGuard aGuard;
307 :
308 0 : CHECK_FOR_DEFUNC( XAccessibleHypertext );
309 :
310 0 : sal_Int32 nCount = 0;
311 0 : SwFmtURL aURL( ((SwLayoutFrm*)GetFrm())->GetFmt()->GetURL() );
312 :
313 0 : if(aURL.GetMap() || !aURL.GetURL().isEmpty())
314 0 : nCount = 1;
315 :
316 0 : return nCount;
317 : }
318 :
319 : uno::Reference< XAccessibleHyperlink > SAL_CALL
320 0 : SwAccessibleNoTextFrame::getHyperLink( sal_Int32 nLinkIndex )
321 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
322 : {
323 0 : SolarMutexGuard aGuard;
324 0 : CHECK_FOR_DEFUNC( XAccessibleHypertext );
325 :
326 0 : uno::Reference< XAccessibleHyperlink > xRet;
327 :
328 0 : SwFmtURL aURL( ((SwLayoutFrm*)GetFrm())->GetFmt()->GetURL() );
329 :
330 0 : if( nLinkIndex > 0 )
331 0 : throw lang::IndexOutOfBoundsException();
332 :
333 0 : if( aURL.GetMap() || !aURL.GetURL().isEmpty() )
334 : {
335 0 : if ( !alink.is() )
336 : {
337 0 : alink = new SwAccessibleNoTextHyperlink( this, GetFrm() );
338 : }
339 :
340 0 : return alink;
341 : }
342 :
343 0 : return NULL;
344 : }
345 :
346 0 : sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getHyperLinkIndex( sal_Int32 )
347 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
348 : {
349 0 : SolarMutexGuard aGuard;
350 :
351 0 : return 0;
352 : }
353 :
354 0 : uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleNoTextFrame::getAccessibleRelationSet( )
355 : throw ( uno::RuntimeException, std::exception )
356 : {
357 0 : SolarMutexGuard aGuard;
358 :
359 0 : return new AccessibleRelationSetHelper();
360 270 : }
361 :
362 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|