Update ooo320-m1
[ooovba.git] / sw / source / core / access / acctextframe.cxx
blobd91a9ef514f1afd9be5d0c2779b447a7f344bbc3
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: acctextframe.cxx,v $
10 * $Revision: 1.16 $
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"
34 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
35 #include <rtl/uuid.h>
36 #include <vos/mutex.hxx>
37 #include <vcl/svapp.hxx>
38 #include <com/sun/star/accessibility/AccessibleRole.hpp>
39 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
40 #include <com/sun/star/accessibility/AccessibleRelation.hpp>
41 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
42 #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
43 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
44 #include <unotools/accessiblestatesethelper.hxx>
45 #include <frmfmt.hxx>
46 #include <flyfrm.hxx>
47 #include <accmap.hxx>
48 #include <unotools/accessiblerelationsethelper.hxx>
49 // --> OD 2009-07-14 #i73249#
50 #include <hints.hxx>
51 // <--
52 #include "acctextframe.hxx"
54 using namespace ::com::sun::star;
55 using namespace ::com::sun::star::accessibility;
56 using ::rtl::OUString;
58 using utl::AccessibleRelationSetHelper;
59 using ::com::sun::star::accessibility::XAccessibleContext;
61 const sal_Char sServiceName[] = "com.sun.star.text.AccessibleTextFrameView";
62 const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleTextFrameView";
64 SwAccessibleTextFrame::SwAccessibleTextFrame(
65 SwAccessibleMap* pInitMap,
66 const SwFlyFrm* pFlyFrm ) :
67 SwAccessibleFrameBase( pInitMap, AccessibleRole::TEXT_FRAME, pFlyFrm ),
68 msTitle(),
69 msDesc()
71 if ( pFlyFrm )
73 const SwFlyFrmFmt* pFlyFrmFmt =
74 dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
75 msTitle = pFlyFrmFmt->GetObjTitle();
77 msDesc = pFlyFrmFmt->GetObjDescription();
78 if ( msDesc.getLength() == 0 &&
79 msTitle != GetName() )
81 msDesc = msTitle;
86 SwAccessibleTextFrame::~SwAccessibleTextFrame()
90 void SwAccessibleTextFrame::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew)
92 const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
93 // --> OD 2009-07-14 #i73249#
94 // suppress handling of RES_NAME_CHANGED in case that attribute Title is
95 // used as the accessible name.
96 if ( nWhich != RES_NAME_CHANGED ||
97 msTitle.getLength() == 0 )
99 SwAccessibleFrameBase::Modify( pOld, pNew );
102 const SwFlyFrm *pFlyFrm = static_cast< const SwFlyFrm * >( GetFrm() );
103 switch( nWhich )
105 // --> OD 2009-07-14 #i73249#
106 case RES_TITLE_CHANGED:
108 const String& sOldTitle(
109 dynamic_cast<SwStringMsgPoolItem*>(pOld)->GetString() );
110 const String& sNewTitle(
111 dynamic_cast<SwStringMsgPoolItem*>(pNew)->GetString() );
112 if ( sOldTitle == sNewTitle )
114 break;
116 msTitle = sNewTitle;
117 AccessibleEventObject aEvent;
118 aEvent.EventId = AccessibleEventId::NAME_CHANGED;
119 aEvent.OldValue <<= OUString( sOldTitle );
120 aEvent.NewValue <<= msTitle;
121 FireAccessibleEvent( aEvent );
123 const SwFlyFrmFmt* pFlyFrmFmt =
124 dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
125 if ( pFlyFrmFmt->GetObjDescription().Len() != 0 )
127 break;
130 // intentional no break here
131 case RES_DESCRIPTION_CHANGED:
133 if ( pFlyFrm )
135 const OUString sOldDesc( msDesc );
137 const SwFlyFrmFmt* pFlyFrmFmt =
138 dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
139 const String& rDesc = pFlyFrmFmt->GetObjDescription();
140 msDesc = rDesc;
141 if ( msDesc.getLength() == 0 &&
142 msTitle != GetName() )
144 msDesc = msTitle;
147 if ( msDesc != sOldDesc )
149 AccessibleEventObject aEvent;
150 aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
151 aEvent.OldValue <<= sOldDesc;
152 aEvent.NewValue <<= msDesc;
153 FireAccessibleEvent( aEvent );
157 break;
158 // <--
162 // --> OD 2009-07-14 #i73249#
163 OUString SAL_CALL SwAccessibleTextFrame::getAccessibleName (void)
164 throw (uno::RuntimeException)
166 vos::OGuard aGuard(Application::GetSolarMutex());
168 CHECK_FOR_DEFUNC( XAccessibleContext )
170 if ( msTitle.getLength() != 0 )
172 return msTitle;
175 return SwAccessibleFrameBase::getAccessibleName();
177 // <--
178 OUString SAL_CALL SwAccessibleTextFrame::getAccessibleDescription (void)
179 throw (uno::RuntimeException)
181 vos::OGuard aGuard(Application::GetSolarMutex());
183 CHECK_FOR_DEFUNC( XAccessibleContext )
185 return msDesc;
189 OUString SAL_CALL SwAccessibleTextFrame::getImplementationName()
190 throw( uno::RuntimeException )
192 return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationName));
195 sal_Bool SAL_CALL SwAccessibleTextFrame::supportsService(
196 const OUString& sTestServiceName)
197 throw (uno::RuntimeException)
199 return sTestServiceName.equalsAsciiL( sServiceName,
200 sizeof(sServiceName)-1 ) ||
201 sTestServiceName.equalsAsciiL( sAccessibleServiceName,
202 sizeof(sAccessibleServiceName)-1 );
205 uno::Sequence< OUString > SAL_CALL SwAccessibleTextFrame::getSupportedServiceNames()
206 throw( uno::RuntimeException )
208 uno::Sequence< OUString > aRet(2);
209 OUString* pArray = aRet.getArray();
210 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceName) );
211 pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) );
212 return aRet;
215 uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleTextFrame::getImplementationId()
216 throw(uno::RuntimeException)
218 vos::OGuard aGuard(Application::GetSolarMutex());
219 static uno::Sequence< sal_Int8 > aId( 16 );
220 static sal_Bool bInit = sal_False;
221 if(!bInit)
223 rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
224 bInit = sal_True;
226 return aId;
231 // XAccessibleRelationSet
235 SwFlyFrm* SwAccessibleTextFrame::getFlyFrm() const
237 SwFlyFrm* pFlyFrm = NULL;
239 const SwFrm* pFrm = GetFrm();
240 DBG_ASSERT( pFrm != NULL, "frame expected" );
241 if( pFrm->IsFlyFrm() )
243 pFlyFrm = static_cast<SwFlyFrm*>( const_cast<SwFrm*>( pFrm ) );
246 return pFlyFrm;
249 AccessibleRelation SwAccessibleTextFrame::makeRelation( sal_Int16 nType, const SwFlyFrm* pFrm )
251 uno::Sequence<uno::Reference<XInterface> > aSequence(1);
252 aSequence[0] = GetMap()->GetContext( pFrm );
253 return AccessibleRelation( nType, aSequence );
257 uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleTextFrame::getAccessibleRelationSet( )
258 throw ( uno::RuntimeException )
260 vos::OGuard aGuard(Application::GetSolarMutex());
261 CHECK_FOR_DEFUNC( XAccessibleContext );
263 // get the frame, and insert prev/next relations into helper
265 AccessibleRelationSetHelper* pHelper = new AccessibleRelationSetHelper();
267 SwFlyFrm* pFlyFrm = getFlyFrm();
268 DBG_ASSERT( pFlyFrm != NULL, "fly frame expected" );
270 const SwFlyFrm* pPrevFrm = pFlyFrm->GetPrevLink();
271 if( pPrevFrm != NULL )
272 pHelper->AddRelation( makeRelation(
273 AccessibleRelationType::CONTENT_FLOWS_FROM, pPrevFrm ) );
275 const SwFlyFrm* pNextFrm = pFlyFrm->GetNextLink();
276 if( pNextFrm != NULL )
277 pHelper->AddRelation( makeRelation(
278 AccessibleRelationType::CONTENT_FLOWS_TO, pNextFrm ) );
280 return pHelper;