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 : : #include <osl/mutex.hxx>
30 : : #include <com/sun/star/accessibility/AccessibleRole.hpp>
31 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
32 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
33 : : #include <unotools/accessiblestatesethelper.hxx>
34 : : #include <comphelper/servicehelper.hxx>
35 : : #include <vcl/svapp.hxx>
36 : : #include <cellfrm.hxx>
37 : : #include <tabfrm.hxx>
38 : : #include <swtable.hxx>
39 : : #include "crsrsh.hxx"
40 : : #include "viscrs.hxx"
41 : : #include <accfrmobj.hxx>
42 : : #include <accfrmobjslist.hxx>
43 : : #include "frmfmt.hxx"
44 : : #include "cellatr.hxx"
45 : : #include "accmap.hxx"
46 : : #include <acccell.hxx>
47 : :
48 : : #include <cfloat>
49 : : #include <limits.h>
50 : :
51 : : using namespace ::com::sun::star;
52 : : using namespace ::com::sun::star::accessibility;
53 : : using ::rtl::OUString;
54 : : using namespace sw::access;
55 : :
56 : : const sal_Char sServiceName[] = "com.sun.star.table.AccessibleCellView";
57 : : const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleCellView";
58 : :
59 : 52 : sal_Bool SwAccessibleCell::IsSelected()
60 : : {
61 : 52 : sal_Bool bRet = sal_False;
62 : :
63 : : OSL_ENSURE( GetMap(), "no map?" );
64 : 52 : const ViewShell *pVSh = GetMap()->GetShell();
65 : : OSL_ENSURE( pVSh, "no shell?" );
66 [ + - ]: 52 : if( pVSh->ISA( SwCrsrShell ) )
67 : : {
68 : 52 : const SwCrsrShell *pCSh = static_cast< const SwCrsrShell * >( pVSh );
69 [ + + ]: 52 : if( pCSh->IsTableMode() )
70 : : {
71 : : const SwCellFrm *pCFrm =
72 : 36 : static_cast< const SwCellFrm * >( GetFrm() );
73 : : SwTableBox *pBox =
74 : 36 : const_cast< SwTableBox *>( pCFrm->GetTabBox() );
75 [ + - ][ + - ]: 36 : bRet = pCSh->GetTableCrsr()->GetBoxes().find( pBox ) != pCSh->GetTableCrsr()->GetBoxes().end();
76 : : }
77 : : }
78 : :
79 : 52 : return bRet;
80 : : }
81 : :
82 : 8 : void SwAccessibleCell::GetStates( ::utl::AccessibleStateSetHelper& rStateSet )
83 : : {
84 : 8 : SwAccessibleContext::GetStates( rStateSet );
85 : :
86 : : // SELECTABLE
87 : 8 : const ViewShell *pVSh = GetMap()->GetShell();
88 : : OSL_ENSURE( pVSh, "no shell?" );
89 [ + - ]: 8 : if( pVSh->ISA( SwCrsrShell ) )
90 : 8 : rStateSet.AddState( AccessibleStateType::SELECTABLE );
91 : :
92 : : // SELECTED
93 [ - + ]: 8 : if( IsSelected() )
94 : : {
95 [ # # ]: 0 : rStateSet.AddState( AccessibleStateType::SELECTED );
96 : : OSL_ENSURE( bIsSelected, "bSelected out of sync" );
97 : 0 : ::rtl::Reference < SwAccessibleContext > xThis( this );
98 [ # # ]: 0 : GetMap()->SetCursorContext( xThis );
99 : : }
100 : 8 : }
101 : :
102 : 14 : SwAccessibleCell::SwAccessibleCell( SwAccessibleMap *pInitMap,
103 : : const SwCellFrm *pCellFrm )
104 : : : SwAccessibleContext( pInitMap, AccessibleRole::TABLE_CELL, pCellFrm )
105 : 14 : , bIsSelected( sal_False )
106 : : {
107 [ + - ]: 14 : SolarMutexGuard aGuard;
108 [ + - ][ + - ]: 14 : OUString sBoxName( pCellFrm->GetTabBox()->GetName() );
[ + - ]
109 : 14 : SetName( sBoxName );
110 : :
111 [ + - ][ + - ]: 14 : bIsSelected = IsSelected();
112 : 14 : }
113 : :
114 : 30 : sal_Bool SwAccessibleCell::_InvalidateMyCursorPos()
115 : : {
116 : 30 : sal_Bool bNew = IsSelected();
117 : : sal_Bool bOld;
118 : : {
119 [ + - ]: 30 : osl::MutexGuard aGuard( aMutex );
120 : 30 : bOld = bIsSelected;
121 [ + - ]: 30 : bIsSelected = bNew;
122 : : }
123 [ + + ]: 30 : if( bNew )
124 : : {
125 : : // remember that object as the one that has the caret. This is
126 : : // neccessary to notify that object if the cursor leaves it.
127 : 26 : ::rtl::Reference < SwAccessibleContext > xThis( this );
128 [ + - ]: 26 : GetMap()->SetCursorContext( xThis );
129 : : }
130 : :
131 : 30 : sal_Bool bChanged = bOld != bNew;
132 [ + + ]: 30 : if( bChanged )
133 : 10 : FireStateChangedEvent( AccessibleStateType::SELECTED, bNew );
134 : :
135 : 30 : return bChanged;
136 : : }
137 : :
138 : 60 : sal_Bool SwAccessibleCell::_InvalidateChildrenCursorPos( const SwFrm *pFrm )
139 : : {
140 : 60 : sal_Bool bChanged = sal_False;
141 : :
142 [ + - ]: 60 : const SwAccessibleChildSList aVisList( GetVisArea(), *pFrm, *GetMap() );
143 [ + - ]: 60 : SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
144 [ + - ][ + - ]: 180 : while( aIter != aVisList.end() )
[ + + ]
145 : : {
146 : 120 : const SwAccessibleChild& rLower = *aIter;
147 [ + - ]: 120 : const SwFrm *pLower = rLower.GetSwFrm();
148 [ + - ]: 120 : if( pLower )
149 : : {
150 [ + - ][ + + ]: 120 : if( rLower.IsAccessible( GetMap()->GetShell()->IsPreView() ) )
151 : : {
152 : : ::rtl::Reference< SwAccessibleContext > xAccImpl(
153 [ + - ]: 80 : GetMap()->GetContextImpl( pLower, sal_False ) );
154 [ + + ]: 80 : if( xAccImpl.is() )
155 : : {
156 : : OSL_ENSURE( xAccImpl->GetFrm()->IsCellFrm(),
157 : : "table child is not a cell frame" );
158 : : bChanged |= static_cast< SwAccessibleCell *>(
159 [ + - ]: 30 : xAccImpl.get() )->_InvalidateMyCursorPos();
160 : : }
161 : : else
162 : 80 : bChanged = sal_True; // If the context is not know we
163 : : // don't know whether the selection
164 : : // changed or not.
165 : : }
166 : : else
167 : : {
168 : : // This is a box with sub rows.
169 [ + - ]: 40 : bChanged |= _InvalidateChildrenCursorPos( pLower );
170 : : }
171 : : }
172 [ + - ]: 120 : ++aIter;
173 : : }
174 : :
175 : 60 : return bChanged;
176 : : }
177 : :
178 : 20 : void SwAccessibleCell::_InvalidateCursorPos()
179 : : {
180 : :
181 [ + - ]: 20 : const SwFrm *pParent = GetParent( SwAccessibleChild(GetFrm()), IsInPagePreview() );
182 : : OSL_ENSURE( pParent->IsTabFrm(), "parent is not a tab frame" );
183 : 20 : const SwTabFrm *pTabFrm = static_cast< const SwTabFrm * >( pParent );
184 [ - + ]: 20 : if( pTabFrm->IsFollow() )
185 : 0 : pTabFrm = pTabFrm->FindMaster();
186 : :
187 [ + + ]: 40 : while( pTabFrm )
188 : : {
189 : 20 : sal_Bool bChanged = _InvalidateChildrenCursorPos( pTabFrm );
190 [ + - ]: 20 : if( bChanged )
191 : : {
192 : : ::rtl::Reference< SwAccessibleContext > xAccImpl(
193 [ + - ]: 20 : GetMap()->GetContextImpl( pTabFrm, sal_False ) );
194 [ + - ]: 20 : if( xAccImpl.is() )
195 : : {
196 [ + - ]: 20 : AccessibleEventObject aEvent;
197 : 20 : aEvent.EventId = AccessibleEventId::SELECTION_CHANGED;
198 [ + - ][ + - ]: 20 : xAccImpl->FireAccessibleEvent( aEvent );
199 : 20 : }
200 : : }
201 : :
202 : 20 : pTabFrm = pTabFrm->GetFollow();
203 : : }
204 : 20 : }
205 : :
206 : 14 : sal_Bool SwAccessibleCell::HasCursor()
207 : : {
208 [ + - ]: 14 : osl::MutexGuard aGuard( aMutex );
209 [ + - ]: 14 : return bIsSelected;
210 : : }
211 : :
212 : 14 : SwAccessibleCell::~SwAccessibleCell()
213 : : {
214 [ - + ]: 28 : }
215 : :
216 : 14 : OUString SAL_CALL SwAccessibleCell::getAccessibleDescription (void)
217 : : throw (uno::RuntimeException)
218 : : {
219 : 14 : return GetName();
220 : : }
221 : :
222 : 6 : OUString SAL_CALL SwAccessibleCell::getImplementationName()
223 : : throw( uno::RuntimeException )
224 : : {
225 : 6 : return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationName));
226 : : }
227 : :
228 : 0 : sal_Bool SAL_CALL SwAccessibleCell::supportsService(
229 : : const ::rtl::OUString& sTestServiceName)
230 : : throw (uno::RuntimeException)
231 : : {
232 : : return sTestServiceName.equalsAsciiL( sServiceName,
233 : 0 : sizeof(sServiceName)-1 ) ||
234 : : sTestServiceName.equalsAsciiL( sAccessibleServiceName,
235 [ # # ][ # # ]: 0 : sizeof(sAccessibleServiceName)-1 );
236 : : }
237 : :
238 : 0 : uno::Sequence< OUString > SAL_CALL SwAccessibleCell::getSupportedServiceNames()
239 : : throw( uno::RuntimeException )
240 : : {
241 : 0 : uno::Sequence< OUString > aRet(2);
242 [ # # ]: 0 : OUString* pArray = aRet.getArray();
243 [ # # ]: 0 : pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceName) );
244 [ # # ]: 0 : pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) );
245 : 0 : return aRet;
246 : : }
247 : :
248 : 4 : void SwAccessibleCell::Dispose( sal_Bool bRecursive )
249 : : {
250 [ + - ][ + - ]: 4 : const SwFrm *pParent = GetParent( SwAccessibleChild(GetFrm()), IsInPagePreview() );
251 : : ::rtl::Reference< SwAccessibleContext > xAccImpl(
252 [ + - ]: 4 : GetMap()->GetContextImpl( pParent, sal_False ) );
253 [ + - ]: 4 : if( xAccImpl.is() )
254 [ + - ][ + - ]: 4 : xAccImpl->DisposeChild( SwAccessibleChild(GetFrm()), bRecursive );
255 [ + - ]: 4 : SwAccessibleContext::Dispose( bRecursive );
256 : 4 : }
257 : :
258 : 0 : void SwAccessibleCell::InvalidatePosOrSize( const SwRect& rOldBox )
259 : : {
260 [ # # ][ # # ]: 0 : const SwFrm *pParent = GetParent( SwAccessibleChild(GetFrm()), IsInPagePreview() );
261 : : ::rtl::Reference< SwAccessibleContext > xAccImpl(
262 [ # # ]: 0 : GetMap()->GetContextImpl( pParent, sal_False ) );
263 [ # # ]: 0 : if( xAccImpl.is() )
264 [ # # ][ # # ]: 0 : xAccImpl->InvalidateChildPosOrSize( SwAccessibleChild(GetFrm()), rOldBox );
265 [ # # ]: 0 : SwAccessibleContext::InvalidatePosOrSize( rOldBox );
266 : 0 : }
267 : :
268 : :
269 : : // ===== XAccessibleInterface ===========================================
270 : :
271 : 176 : uno::Any SwAccessibleCell::queryInterface( const uno::Type& rType )
272 : : throw( uno::RuntimeException )
273 : : {
274 [ + + ]: 176 : if ( rType == ::getCppuType( static_cast< uno::Reference< XAccessibleValue > * >( 0 ) ) )
275 : : {
276 [ + - ]: 2 : uno::Reference<XAccessibleValue> xValue = this;
277 : 2 : uno::Any aRet;
278 [ + - ]: 2 : aRet <<= xValue;
279 : 2 : return aRet;
280 : : }
281 : : else
282 : : {
283 : 176 : return SwAccessibleContext::queryInterface( rType );
284 : : }
285 : : }
286 : :
287 : : //====== XTypeProvider ====================================================
288 : 0 : uno::Sequence< uno::Type > SAL_CALL SwAccessibleCell::getTypes()
289 : : throw(uno::RuntimeException)
290 : : {
291 : 0 : uno::Sequence< uno::Type > aTypes( SwAccessibleContext::getTypes() );
292 : :
293 : 0 : sal_Int32 nIndex = aTypes.getLength();
294 [ # # ]: 0 : aTypes.realloc( nIndex + 1 );
295 : :
296 [ # # ]: 0 : uno::Type* pTypes = aTypes.getArray();
297 [ # # ]: 0 : pTypes[nIndex] = ::getCppuType( static_cast< uno::Reference< XAccessibleValue > * >( 0 ) );
298 : :
299 : 0 : return aTypes;
300 : : }
301 : :
302 : : namespace
303 : : {
304 : : class theSwAccessibleCellImplementationId : public rtl::Static< UnoTunnelIdInit, theSwAccessibleCellImplementationId > {};
305 : : }
306 : :
307 : 0 : uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleCell::getImplementationId()
308 : : throw(uno::RuntimeException)
309 : : {
310 : 0 : return theSwAccessibleCellImplementationId::get().getSeq();
311 : : }
312 : :
313 : : // ===== XAccessibleValue ===============================================
314 : :
315 : 22 : SwFrmFmt* SwAccessibleCell::GetTblBoxFormat() const
316 : : {
317 : : OSL_ENSURE( GetFrm() != NULL, "no frame?" );
318 : : OSL_ENSURE( GetFrm()->IsCellFrm(), "no cell frame?" );
319 : :
320 : 22 : const SwCellFrm* pCellFrm = static_cast<const SwCellFrm*>( GetFrm() );
321 : 22 : return pCellFrm->GetTabBox()->GetFrmFmt();
322 : : }
323 : :
324 : :
325 : 12 : uno::Any SwAccessibleCell::getCurrentValue( )
326 : : throw( uno::RuntimeException )
327 : : {
328 [ + - ]: 12 : SolarMutexGuard aGuard;
329 [ + - ][ - + ]: 12 : CHECK_FOR_DEFUNC( XAccessibleValue );
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
330 : :
331 : 12 : uno::Any aAny;
332 [ + - ][ + - ]: 12 : aAny <<= GetTblBoxFormat()->GetTblBoxValue().GetValue();
333 [ + - ]: 12 : return aAny;
334 : : }
335 : :
336 : 10 : sal_Bool SwAccessibleCell::setCurrentValue( const uno::Any& aNumber )
337 : : throw( uno::RuntimeException )
338 : : {
339 [ + - ]: 10 : SolarMutexGuard aGuard;
340 [ + - ][ - + ]: 10 : CHECK_FOR_DEFUNC( XAccessibleValue );
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
341 : :
342 : 10 : double fValue = 0;
343 : 10 : sal_Bool bValid = (aNumber >>= fValue);
344 [ + - ]: 10 : if( bValid )
345 : : {
346 [ + - ]: 10 : SwTblBoxValue aValue( fValue );
347 [ + - ][ + - ]: 10 : GetTblBoxFormat()->SetFmtAttr( aValue );
348 : : }
349 [ + - ]: 10 : return bValid;
350 : : }
351 : :
352 : 2 : uno::Any SwAccessibleCell::getMaximumValue( )
353 : : throw( uno::RuntimeException )
354 : : {
355 : 2 : uno::Any aAny;
356 [ + - ]: 2 : aAny <<= DBL_MAX;
357 : 2 : return aAny;
358 : : }
359 : :
360 : 2 : uno::Any SwAccessibleCell::getMinimumValue( )
361 : : throw( uno::RuntimeException )
362 : : {
363 : 2 : uno::Any aAny;
364 [ + - ]: 2 : aAny <<= -DBL_MAX;
365 : 2 : return aAny;
366 : : }
367 : :
368 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|