Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
31 : : #include <comphelper/servicehelper.hxx>
32 : : #include <osl/mutex.hxx>
33 : : #include <vcl/svapp.hxx>
34 : : #include <com/sun/star/accessibility/AccessibleRole.hpp>
35 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
36 : : #include <com/sun/star/accessibility/AccessibleRelation.hpp>
37 : : #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
38 : : #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
39 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
40 : : #include <unotools/accessiblestatesethelper.hxx>
41 : : #include <frmfmt.hxx>
42 : : #include <flyfrm.hxx>
43 : : #include <accmap.hxx>
44 : : #include <unotools/accessiblerelationsethelper.hxx>
45 : : #include <hints.hxx> // #i73249#
46 : : #include "acctextframe.hxx"
47 : :
48 : : using namespace ::com::sun::star;
49 : : using namespace ::com::sun::star::accessibility;
50 : : using ::rtl::OUString;
51 : :
52 : : using utl::AccessibleRelationSetHelper;
53 : : using ::com::sun::star::accessibility::XAccessibleContext;
54 : :
55 : : const sal_Char sServiceName[] = "com.sun.star.text.AccessibleTextFrameView";
56 : : const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleTextFrameView";
57 : :
58 : 0 : SwAccessibleTextFrame::SwAccessibleTextFrame(
59 : : SwAccessibleMap* pInitMap,
60 : : const SwFlyFrm* pFlyFrm ) :
61 : : SwAccessibleFrameBase( pInitMap, AccessibleRole::TEXT_FRAME, pFlyFrm ),
62 : : msTitle(),
63 : 0 : msDesc()
64 : : {
65 [ # # ]: 0 : if ( pFlyFrm )
66 : : {
67 : : const SwFlyFrmFmt* pFlyFrmFmt =
68 [ # # ]: 0 : dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
69 [ # # ][ # # ]: 0 : msTitle = pFlyFrmFmt->GetObjTitle();
[ # # ]
70 : :
71 [ # # ][ # # ]: 0 : msDesc = pFlyFrmFmt->GetObjDescription();
[ # # ]
72 [ # # # # ]: 0 : if ( msDesc.isEmpty() &&
[ # # ]
73 : 0 : msTitle != GetName() )
74 : : {
75 : 0 : msDesc = msTitle;
76 : : }
77 : : }
78 : 0 : }
79 : :
80 : 0 : SwAccessibleTextFrame::~SwAccessibleTextFrame()
81 : : {
82 [ # # ]: 0 : }
83 : :
84 : 0 : void SwAccessibleTextFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
85 : : {
86 [ # # ][ # # ]: 0 : const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
87 : : // #i73249# - suppress handling of RES_NAME_CHANGED
88 : : // in case that attribute Title is used as the accessible name.
89 [ # # # # ]: 0 : if ( nWhich != RES_NAME_CHANGED ||
[ # # ]
90 : 0 : msTitle.isEmpty() )
91 : : {
92 : 0 : SwAccessibleFrameBase::Modify( pOld, pNew );
93 : : }
94 : :
95 : 0 : const SwFlyFrm *pFlyFrm = static_cast< const SwFlyFrm * >( GetFrm() );
96 [ # # # ]: 0 : switch( nWhich )
97 : : {
98 : : // #i73249#
99 : : case RES_TITLE_CHANGED:
100 : : {
101 : : const String& sOldTitle(
102 [ # # ]: 0 : dynamic_cast<const SwStringMsgPoolItem*>(pOld)->GetString() );
103 : : const String& sNewTitle(
104 [ # # ]: 0 : dynamic_cast<const SwStringMsgPoolItem*>(pNew)->GetString() );
105 [ # # ][ # # ]: 0 : if ( sOldTitle == sNewTitle )
106 : : {
107 : : break;
108 : : }
109 [ # # ]: 0 : msTitle = sNewTitle;
110 [ # # ]: 0 : AccessibleEventObject aEvent;
111 : 0 : aEvent.EventId = AccessibleEventId::NAME_CHANGED;
112 [ # # ][ # # ]: 0 : aEvent.OldValue <<= OUString( sOldTitle );
113 [ # # ]: 0 : aEvent.NewValue <<= msTitle;
114 [ # # ]: 0 : FireAccessibleEvent( aEvent );
115 : :
116 : : const SwFlyFrmFmt* pFlyFrmFmt =
117 [ # # ]: 0 : dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
118 [ # # ][ # # ]: 0 : if ( pFlyFrmFmt->GetObjDescription().Len() != 0 )
[ # # ]
119 : : {
120 : : break;
121 [ # # ][ # # ]: 0 : }
122 : : }
123 : : // intentional no break here
124 : : case RES_DESCRIPTION_CHANGED:
125 : : {
126 [ # # ]: 0 : if ( pFlyFrm )
127 : : {
128 : 0 : const OUString sOldDesc( msDesc );
129 : :
130 : : const SwFlyFrmFmt* pFlyFrmFmt =
131 [ # # ]: 0 : dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
132 [ # # ]: 0 : const String& rDesc = pFlyFrmFmt->GetObjDescription();
133 [ # # ]: 0 : msDesc = rDesc;
134 [ # # ]: 0 : if ( msDesc.isEmpty() &&
[ # # # # ]
135 : 0 : msTitle != GetName() )
136 : : {
137 : 0 : msDesc = msTitle;
138 : : }
139 : :
140 [ # # ]: 0 : if ( msDesc != sOldDesc )
141 : : {
142 [ # # ]: 0 : AccessibleEventObject aEvent;
143 : 0 : aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
144 [ # # ]: 0 : aEvent.OldValue <<= sOldDesc;
145 [ # # ]: 0 : aEvent.NewValue <<= msDesc;
146 [ # # ][ # # ]: 0 : FireAccessibleEvent( aEvent );
147 [ # # ]: 0 : }
148 : : }
149 : : }
150 : 0 : break;
151 : : }
152 : 0 : }
153 : :
154 : : // #i73249#
155 : 0 : OUString SAL_CALL SwAccessibleTextFrame::getAccessibleName (void)
156 : : throw (uno::RuntimeException)
157 : : {
158 [ # # ]: 0 : SolarMutexGuard aGuard;
159 : :
160 [ # # ][ # # ]: 0 : CHECK_FOR_DEFUNC( XAccessibleContext )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
161 : :
162 [ # # ]: 0 : if ( !msTitle.isEmpty() )
163 : : {
164 : 0 : return msTitle;
165 : : }
166 : :
167 [ # # ][ # # ]: 0 : return SwAccessibleFrameBase::getAccessibleName();
168 : : }
169 : 0 : OUString SAL_CALL SwAccessibleTextFrame::getAccessibleDescription (void)
170 : : throw (uno::RuntimeException)
171 : : {
172 [ # # ]: 0 : SolarMutexGuard aGuard;
173 : :
174 [ # # ][ # # ]: 0 : CHECK_FOR_DEFUNC( XAccessibleContext )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
175 : :
176 [ # # ]: 0 : return msDesc;
177 : :
178 : : }
179 : :
180 : 0 : OUString SAL_CALL SwAccessibleTextFrame::getImplementationName()
181 : : throw( uno::RuntimeException )
182 : : {
183 : 0 : return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationName));
184 : : }
185 : :
186 : 0 : sal_Bool SAL_CALL SwAccessibleTextFrame::supportsService(
187 : : const OUString& sTestServiceName)
188 : : throw (uno::RuntimeException)
189 : : {
190 : : return sTestServiceName.equalsAsciiL( sServiceName,
191 : 0 : sizeof(sServiceName)-1 ) ||
192 : : sTestServiceName.equalsAsciiL( sAccessibleServiceName,
193 [ # # ][ # # ]: 0 : sizeof(sAccessibleServiceName)-1 );
194 : : }
195 : :
196 : 0 : uno::Sequence< OUString > SAL_CALL SwAccessibleTextFrame::getSupportedServiceNames()
197 : : throw( uno::RuntimeException )
198 : : {
199 : 0 : uno::Sequence< OUString > aRet(2);
200 [ # # ]: 0 : OUString* pArray = aRet.getArray();
201 [ # # ]: 0 : pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceName) );
202 [ # # ]: 0 : pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) );
203 : 0 : return aRet;
204 : : }
205 : :
206 : : namespace
207 : : {
208 : : class theSwAccessibleTextFrameImplementationId : public rtl::Static< UnoTunnelIdInit, theSwAccessibleTextFrameImplementationId > {};
209 : : }
210 : :
211 : 0 : uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleTextFrame::getImplementationId()
212 : : throw(uno::RuntimeException)
213 : : {
214 : 0 : return theSwAccessibleTextFrameImplementationId::get().getSeq();
215 : : }
216 : :
217 : :
218 : : //
219 : : // XAccessibleRelationSet
220 : : //
221 : :
222 : :
223 : 0 : SwFlyFrm* SwAccessibleTextFrame::getFlyFrm() const
224 : : {
225 : 0 : SwFlyFrm* pFlyFrm = NULL;
226 : :
227 : 0 : const SwFrm* pFrm = GetFrm();
228 : : OSL_ENSURE( pFrm != NULL, "frame expected" );
229 [ # # ]: 0 : if( pFrm->IsFlyFrm() )
230 : : {
231 : 0 : pFlyFrm = static_cast<SwFlyFrm*>( const_cast<SwFrm*>( pFrm ) );
232 : : }
233 : :
234 : 0 : return pFlyFrm;
235 : : }
236 : :
237 : 0 : AccessibleRelation SwAccessibleTextFrame::makeRelation( sal_Int16 nType, const SwFlyFrm* pFrm )
238 : : {
239 [ # # ]: 0 : uno::Sequence<uno::Reference<XInterface> > aSequence(1);
240 [ # # ][ # # ]: 0 : aSequence[0] = GetMap()->GetContext( pFrm );
[ # # ]
241 [ # # ][ # # ]: 0 : return AccessibleRelation( nType, aSequence );
242 : : }
243 : :
244 : :
245 : 0 : uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleTextFrame::getAccessibleRelationSet( )
246 : : throw ( uno::RuntimeException )
247 : : {
248 [ # # ]: 0 : SolarMutexGuard aGuard;
249 [ # # ][ # # ]: 0 : CHECK_FOR_DEFUNC( XAccessibleContext );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
250 : :
251 : : // get the frame, and insert prev/next relations into helper
252 : :
253 [ # # ]: 0 : AccessibleRelationSetHelper* pHelper = new AccessibleRelationSetHelper();
254 : :
255 : 0 : SwFlyFrm* pFlyFrm = getFlyFrm();
256 : : OSL_ENSURE( pFlyFrm != NULL, "fly frame expected" );
257 : :
258 : 0 : const SwFlyFrm* pPrevFrm = pFlyFrm->GetPrevLink();
259 [ # # ]: 0 : if( pPrevFrm != NULL )
260 : : pHelper->AddRelation( makeRelation(
261 [ # # ][ # # ]: 0 : AccessibleRelationType::CONTENT_FLOWS_FROM, pPrevFrm ) );
[ # # ]
262 : :
263 : 0 : const SwFlyFrm* pNextFrm = pFlyFrm->GetNextLink();
264 [ # # ]: 0 : if( pNextFrm != NULL )
265 : : pHelper->AddRelation( makeRelation(
266 [ # # ][ # # ]: 0 : AccessibleRelationType::CONTENT_FLOWS_TO, pNextFrm ) );
[ # # ]
267 : :
268 [ # # ][ # # ]: 0 : return pHelper;
[ # # ]
269 : : }
270 : :
271 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|