update dev300-m58
[ooovba.git] / sw / source / core / access / accnotextframe.cxx
blob4bb7c73362aa61b533f3f55bbef7cea4341601ef
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accnotextframe.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <vos/mutex.hxx>
36 #include <vcl/svapp.hxx>
37 #include <com/sun/star/accessibility/AccessibleRole.hpp>
38 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
39 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
40 #include <unotools/accessiblestatesethelper.hxx>
41 #include <frmfmt.hxx>
42 #include <ndnotxt.hxx>
43 #include <flyfrm.hxx>
44 #include <cntfrm.hxx>
45 // --> OD 2009-07-14 #i73249#
46 #include <hints.hxx>
47 // <--
48 #include "accnotextframe.hxx"
50 using namespace ::com::sun::star;
51 using namespace ::com::sun::star::accessibility;
52 using ::rtl::OUString;
54 const SwNoTxtNode *SwAccessibleNoTextFrame::GetNoTxtNode() const
56 const SwNoTxtNode *pNd = 0;
57 const SwFlyFrm *pFlyFrm = static_cast< const SwFlyFrm *>( GetFrm() );
58 if( pFlyFrm->Lower() && pFlyFrm->Lower()->IsNoTxtFrm() )
60 const SwCntntFrm *pCntFrm =
61 static_cast<const SwCntntFrm *>( pFlyFrm->Lower() );
62 pNd = pCntFrm->GetNode()->GetNoTxtNode();
65 return pNd;
68 SwAccessibleNoTextFrame::SwAccessibleNoTextFrame(
69 SwAccessibleMap* pInitMap,
70 sal_Int16 nInitRole,
71 const SwFlyFrm* pFlyFrm ) :
72 SwAccessibleFrameBase( pInitMap, nInitRole, pFlyFrm ),
73 aDepend( this, const_cast < SwNoTxtNode * >( GetNoTxtNode() ) ),
74 msTitle(),
75 msDesc()
77 const SwNoTxtNode* pNd = GetNoTxtNode();
78 // --> OD 2009-07-14 #i73249#
79 // consider new attributes Title and Description
80 if( pNd )
82 msTitle = pNd->GetTitle();
84 msDesc = pNd->GetDescription();
85 if ( msDesc.getLength() == 0 &&
86 msTitle != GetName() )
88 msDesc = msTitle;
91 // <--
94 SwAccessibleNoTextFrame::~SwAccessibleNoTextFrame()
98 void SwAccessibleNoTextFrame::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew)
100 const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
101 // --> OD 2009-07-14 #i73249#
102 // suppress handling of RES_NAME_CHANGED in case that attribute Title is
103 // used as the accessible name.
104 if ( nWhich != RES_NAME_CHANGED ||
105 msTitle.getLength() == 0 )
107 SwAccessibleFrameBase::Modify( pOld, pNew );
110 const SwNoTxtNode *pNd = GetNoTxtNode();
111 ASSERT( pNd == aDepend.GetRegisteredIn(), "invalid frame" );
112 switch( nWhich )
114 // --> OD 2009-07-14 #i73249#
115 case RES_TITLE_CHANGED:
117 const String& sOldTitle(
118 dynamic_cast<SwStringMsgPoolItem*>(pOld)->GetString() );
119 const String& sNewTitle(
120 dynamic_cast<SwStringMsgPoolItem*>(pNew)->GetString() );
121 if ( sOldTitle == sNewTitle )
123 break;
125 msTitle = sNewTitle;
126 AccessibleEventObject aEvent;
127 aEvent.EventId = AccessibleEventId::NAME_CHANGED;
128 aEvent.OldValue <<= OUString( sOldTitle );
129 aEvent.NewValue <<= msTitle;
130 FireAccessibleEvent( aEvent );
132 if ( pNd->GetDescription().Len() != 0 )
134 break;
137 // intentional no break here
138 case RES_DESCRIPTION_CHANGED:
140 if ( pNd && GetFrm() )
142 const OUString sOldDesc( msDesc );
144 const String& rDesc = pNd->GetDescription();
145 msDesc = rDesc;
146 if ( msDesc.getLength() == 0 &&
147 msTitle != GetName() )
149 msDesc = msTitle;
152 if ( msDesc != sOldDesc )
154 AccessibleEventObject aEvent;
155 aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
156 aEvent.OldValue <<= sOldDesc;
157 aEvent.NewValue <<= msDesc;
158 FireAccessibleEvent( aEvent );
162 break;
163 // <--
165 case RES_OBJECTDYING:
166 if( aDepend.GetRegisteredIn() ==
167 static_cast< SwModify *>( static_cast< SwPtrMsgPoolItem * >( pOld )->pObject ) )
168 const_cast < SwModify *>( aDepend.GetRegisteredIn()->Remove( aDepend );
169 break;
171 case RES_FMT_CHG:
172 if( static_cast< SwFmtChg * >(pNew)->pChangedFmt == GetRegisteredIn() &&
173 static_cast< SwFmtChg * >(pOld)->pChangedFmt->IsFmtInDTOR() )
174 pRegisteredIn->Remove( this );
175 break;
180 void SwAccessibleNoTextFrame::Dispose( sal_Bool bRecursive )
182 vos::OGuard aGuard(Application::GetSolarMutex());
184 if( aDepend.GetRegisteredIn() )
185 const_cast < SwModify *>( aDepend.GetRegisteredIn() )->Remove( &aDepend );
187 SwAccessibleFrameBase::Dispose( bRecursive );
190 // --> OD 2009-07-14 #i73249#
191 OUString SAL_CALL SwAccessibleNoTextFrame::getAccessibleName (void)
192 throw (uno::RuntimeException)
194 vos::OGuard aGuard(Application::GetSolarMutex());
196 CHECK_FOR_DEFUNC( XAccessibleContext )
198 if ( msTitle.getLength() != 0 )
200 return msTitle;
203 return SwAccessibleFrameBase::getAccessibleName();
205 // <--
207 OUString SAL_CALL SwAccessibleNoTextFrame::getAccessibleDescription (void)
208 throw (uno::RuntimeException)
210 vos::OGuard aGuard(Application::GetSolarMutex());
212 CHECK_FOR_DEFUNC( XAccessibleContext )
214 return msDesc;
220 // XInterface
223 uno::Any SAL_CALL SwAccessibleNoTextFrame::queryInterface( const uno::Type& aType )
224 throw (uno::RuntimeException)
226 if( aType ==
227 ::getCppuType( static_cast<uno::Reference<XAccessibleImage>*>( NULL ) ) )
229 uno::Reference<XAccessibleImage> xImage = this;
230 uno::Any aAny;
231 aAny <<= xImage;
232 return aAny;
234 else
235 return SwAccessibleContext::queryInterface( aType );
239 //====== XTypeProvider ====================================================
240 uno::Sequence< uno::Type > SAL_CALL SwAccessibleNoTextFrame::getTypes() throw(uno::RuntimeException)
242 uno::Sequence< uno::Type > aTypes( SwAccessibleFrameBase::getTypes() );
244 sal_Int32 nIndex = aTypes.getLength();
245 aTypes.realloc( nIndex + 1 );
247 uno::Type* pTypes = aTypes.getArray();
248 pTypes[nIndex] = ::getCppuType( static_cast< uno::Reference< XAccessibleImage > * >( 0 ) );
250 return aTypes;
255 // XAccessibleImage
258 // implementation of the XAccessibleImage methods is a no-brainer, as
259 // all releveant information is already accessible through other
260 // methods. So we just delegate to those.
262 OUString SAL_CALL SwAccessibleNoTextFrame::getAccessibleImageDescription()
263 throw ( uno::RuntimeException )
265 return getAccessibleDescription();
268 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getAccessibleImageHeight( )
269 throw ( uno::RuntimeException )
271 return getSize().Height;
274 sal_Int32 SAL_CALL SwAccessibleNoTextFrame::getAccessibleImageWidth( )
275 throw ( uno::RuntimeException )
277 return getSize().Width;