Branch data 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 : :
21 : : #include "AccessiblePageHeader.hxx"
22 : : #include "AccessiblePageHeaderArea.hxx"
23 : : #include "AccessibilityHints.hxx"
24 : : #include "prevwsh.hxx"
25 : : #include "miscuno.hxx"
26 : : #include "prevloc.hxx"
27 : : #include "document.hxx"
28 : : #include "stlpool.hxx"
29 : : #include "scitems.hxx"
30 : : #include "attrib.hxx"
31 : : #include "scresid.hxx"
32 : : #include "sc.hrc"
33 : :
34 : : #include <com/sun/star/accessibility/AccessibleRole.hpp>
35 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
36 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
37 : :
38 : : #include <vcl/window.hxx>
39 : : #include <svl/smplhint.hxx>
40 : : #include <vcl/svapp.hxx>
41 : : #include <unotools/accessiblestatesethelper.hxx>
42 : : #include <svl/style.hxx>
43 : : #include <svl/itempool.hxx>
44 : : #include <editeng/editobj.hxx>
45 : : #include <toolkit/helper/convert.hxx>
46 : :
47 : : #include <algorithm>
48 : :
49 : : using namespace ::com::sun::star;
50 : : using namespace ::com::sun::star::accessibility;
51 : :
52 : : const sal_uInt8 MAX_AREAS = 3;
53 : :
54 : : //===== internal ============================================================
55 : : struct Acquire
56 : : {
57 : 54 : void operator() (ScAccessiblePageHeaderArea* pArea)
58 : : {
59 [ + + ]: 54 : if (pArea)
60 : 28 : pArea->acquire();
61 : 54 : }
62 : : };
63 : :
64 : : struct Release
65 : : {
66 : 54 : void operator() (ScAccessiblePageHeaderArea*& pArea)
67 : : {
68 [ + + ]: 54 : if (pArea)
69 : 28 : pArea->release();
70 : 54 : }
71 : : };
72 : :
73 : : struct Dispose
74 : : {
75 : 60 : void operator() (ScAccessiblePageHeaderArea*& pArea)
76 : : {
77 [ + + ]: 60 : if (pArea)
78 : : {
79 : 24 : pArea->dispose();
80 : 24 : pArea->release();
81 : : }
82 : 60 : pArea = NULL;
83 : 60 : }
84 : : };
85 : :
86 : 20 : ScAccessiblePageHeader::ScAccessiblePageHeader( const ::com::sun::star::uno::Reference<
87 : : ::com::sun::star::accessibility::XAccessible>& rxParent,
88 : : ScPreviewShell* pViewShell, sal_Bool bHeader, sal_Int32 nIndex ) :
89 : : ScAccessibleContextBase( rxParent, bHeader ? AccessibleRole::HEADER : AccessibleRole::FOOTER ),
90 : : mpViewShell( pViewShell ),
91 : : mnIndex( nIndex ),
92 : : mbHeader( bHeader ),
93 : : maAreas(MAX_AREAS, NULL),
94 [ + + ][ + - ]: 20 : mnChildCount(-1)
95 : : {
96 [ + - ]: 20 : if (mpViewShell)
97 [ + - ]: 20 : mpViewShell->AddAccessibilityObject(*this);
98 : 20 : }
99 : :
100 : 20 : ScAccessiblePageHeader::~ScAccessiblePageHeader()
101 : : {
102 [ - + ][ # # ]: 20 : if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
[ - + ]
103 : : {
104 : : // increment refcount to prevent double call off dtor
105 [ # # ]: 0 : osl_incrementInterlockedCount( &m_refCount );
106 [ # # ]: 0 : dispose();
107 : : }
108 [ - + ]: 40 : }
109 : :
110 : 20 : void SAL_CALL ScAccessiblePageHeader::disposing()
111 : : {
112 [ + - ]: 20 : SolarMutexGuard aGuard;
113 [ + - ]: 20 : if (mpViewShell)
114 : : {
115 [ + - ]: 20 : mpViewShell->RemoveAccessibilityObject(*this);
116 : 20 : mpViewShell = NULL;
117 : : }
118 [ + - ]: 20 : std::for_each(maAreas.begin(), maAreas.end(), Dispose());
119 : :
120 [ + - ][ + - ]: 20 : ScAccessibleContextBase::disposing();
121 : 20 : }
122 : :
123 : : //===== SfxListener =====================================================
124 : :
125 : 68 : void ScAccessiblePageHeader::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
126 : : {
127 [ + + ]: 68 : if (rHint.ISA( SfxSimpleHint ) )
128 : : {
129 : 48 : const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
130 : : // only notify if child exist, otherwise it is not necessary
131 [ + + ]: 48 : if ((rRef.GetId() == SC_HINT_DATACHANGED))
132 : : {
133 [ + - ]: 18 : ScHFAreas aOldAreas(maAreas);
134 [ + - ]: 18 : std::for_each(aOldAreas.begin(), aOldAreas.end(), Acquire());
135 : 18 : mnChildCount = -1;
136 [ + - ]: 18 : getAccessibleChildCount();
137 [ + + ]: 72 : for (sal_uInt8 i = 0; i < MAX_AREAS; ++i)
138 : : {
139 [ + + ][ + - ]: 216 : if ((aOldAreas[i] && maAreas[i] && !ScGlobal::EETextObjEqual(aOldAreas[i]->GetEditTextObject(), maAreas[i]->GetEditTextObject())) ||
[ + - ][ + -
+ + + - +
+ + + ]
[ + + ]
140 : 162 : (aOldAreas[i] && !maAreas[i]) || (!aOldAreas[i] && maAreas[i]))
141 : : {
142 [ - + ][ # # ]: 6 : if (aOldAreas[i] && aOldAreas[i]->GetEditTextObject())
[ - + ]
143 : : {
144 [ # # ]: 0 : AccessibleEventObject aEvent;
145 : 0 : aEvent.EventId = AccessibleEventId::CHILD;
146 [ # # ][ # # ]: 0 : aEvent.Source = uno::Reference< XAccessibleContext >(this);
147 [ # # ][ # # ]: 0 : aEvent.OldValue = uno::makeAny(uno::Reference<XAccessible>(aOldAreas[i]));
[ # # ]
148 : :
149 [ # # ]: 0 : CommitChange(aEvent); // child gone - event
150 [ # # ][ # # ]: 0 : aOldAreas[i]->dispose();
151 : : }
152 [ + - ][ + - ]: 6 : if (maAreas[i] && maAreas[i]->GetEditTextObject())
[ + - ]
153 : : {
154 [ + - ]: 6 : AccessibleEventObject aEvent;
155 : 6 : aEvent.EventId = AccessibleEventId::CHILD;
156 [ + - ][ + - ]: 6 : aEvent.Source = uno::Reference< XAccessibleContext >(this);
157 [ + - ][ + - ]: 6 : aEvent.NewValue = uno::makeAny(uno::Reference<XAccessible>(maAreas[i]));
[ + - ]
158 : :
159 [ + - ][ + - ]: 6 : CommitChange(aEvent); // new child - event
160 : : }
161 : : }
162 : : }
163 [ + - ]: 18 : std::for_each(aOldAreas.begin(), aOldAreas.end(), Release());
164 : : }
165 [ + + ]: 30 : else if (rRef.GetId() == SC_HINT_ACC_VISAREACHANGED)
166 : : {
167 [ + - ]: 10 : AccessibleEventObject aEvent;
168 : 10 : aEvent.EventId = AccessibleEventId::VISIBLE_DATA_CHANGED;
169 [ + - ][ + - ]: 10 : aEvent.Source = uno::Reference< XAccessibleContext >(this);
170 [ + - ][ + - ]: 10 : CommitChange(aEvent);
171 : : }
172 : : }
173 : :
174 : 68 : ScAccessibleContextBase::Notify(rBC, rHint);
175 : 68 : }
176 : :
177 : : //===== XAccessibleComponent ============================================
178 : :
179 : 0 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePageHeader::getAccessibleAtPoint( const awt::Point& aPoint )
180 : : throw (uno::RuntimeException)
181 : : {
182 : 0 : uno::Reference<XAccessible> xRet;
183 : :
184 [ # # ][ # # ]: 0 : if (containsPoint(aPoint))
185 : : {
186 [ # # ]: 0 : SolarMutexGuard aGuard;
187 [ # # ]: 0 : IsObjectValid();
188 : :
189 [ # # ]: 0 : sal_Int32 nCount(getAccessibleChildCount()); // fill the areas
190 : :
191 [ # # ]: 0 : if (nCount)
192 : : {
193 : : // return the first with content, because they have all the same Bounding Box
194 : 0 : sal_uInt8 i(0);
195 [ # # ][ # # ]: 0 : while(!xRet.is() && i < MAX_AREAS)
[ # # ]
196 : : {
197 [ # # ]: 0 : if (maAreas[i])
198 [ # # ][ # # ]: 0 : xRet = maAreas[i];
199 : : else
200 : 0 : ++i;
201 : : }
202 [ # # ]: 0 : }
203 : : }
204 : :
205 : 0 : return xRet;
206 : : }
207 : :
208 : 2 : void SAL_CALL ScAccessiblePageHeader::grabFocus() throw (uno::RuntimeException)
209 : : {
210 [ + - ]: 2 : SolarMutexGuard aGuard;
211 [ + - ]: 2 : IsObjectValid();
212 [ + - ][ + - ]: 2 : if (getAccessibleParent().is())
213 : : {
214 [ + - ][ + - ]: 2 : uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
[ + - ][ + - ]
215 [ + - ]: 2 : if (xAccessibleComponent.is())
216 [ + - ][ + - ]: 2 : xAccessibleComponent->grabFocus();
217 [ + - ]: 2 : }
218 : 2 : }
219 : :
220 : : //===== XAccessibleContext ==============================================
221 : :
222 : 96 : sal_Int32 SAL_CALL ScAccessiblePageHeader::getAccessibleChildCount() throw (uno::RuntimeException)
223 : : {
224 [ + - ]: 96 : SolarMutexGuard aGuard;
225 [ + - ]: 96 : IsObjectValid();
226 : :
227 [ + + ][ + - ]: 96 : if((mnChildCount < 0) && mpViewShell)
228 : : {
229 : 36 : mnChildCount = 0;
230 [ + - ]: 36 : ScDocument* pDoc = mpViewShell->GetDocument();
231 [ + - ]: 36 : if (pDoc)
232 : : {
233 : : // find out how many regions (left,center, right) are with content
234 : :
235 [ + - ][ + - ]: 36 : SfxStyleSheetBase* pStyle = pDoc->GetStyleSheetPool()->Find(pDoc->GetPageStyle(mpViewShell->GetLocationData().GetPrintTab()), SFX_STYLE_FAMILY_PAGE);
[ + - ][ + - ]
[ + - ][ + - ]
236 [ + - ]: 36 : if (pStyle)
237 : : {
238 : 36 : sal_uInt16 nPageWhichId(0);
239 [ + + ]: 36 : if (mbHeader)
240 [ + - ][ + - ]: 31 : nPageWhichId = mpViewShell->GetLocationData().IsHeaderLeft() ? ATTR_PAGE_HEADERLEFT : ATTR_PAGE_HEADERRIGHT;
[ - + ]
241 : : else
242 [ + - ][ + - ]: 5 : nPageWhichId = mpViewShell->GetLocationData().IsFooterLeft() ? ATTR_PAGE_FOOTERLEFT : ATTR_PAGE_FOOTERRIGHT;
[ - + ]
243 : :
244 [ + - ][ + - ]: 36 : const ScPageHFItem& rPageItem = static_cast<const ScPageHFItem&>(pStyle->GetItemSet().Get(nPageWhichId));
245 [ + - ]: 36 : AddChild(rPageItem.GetLeftArea(), 0, SVX_ADJUST_LEFT);
246 [ + - ]: 36 : AddChild(rPageItem.GetCenterArea(), 1, SVX_ADJUST_CENTER);
247 [ + - ]: 36 : AddChild(rPageItem.GetRightArea(), 2, SVX_ADJUST_RIGHT);
248 : : }
249 : : }
250 : : }
251 : :
252 [ + - ]: 96 : return mnChildCount;
253 : : }
254 : :
255 : 56 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePageHeader::getAccessibleChild( sal_Int32 nIndex )
256 : : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
257 : : {
258 [ + - ]: 56 : SolarMutexGuard aGuard;
259 [ + - ]: 56 : IsObjectValid();
260 : :
261 : 56 : uno::Reference<XAccessible> xRet;
262 : :
263 [ + + ]: 56 : if(mnChildCount < 0)
264 [ + - ]: 1 : getAccessibleChildCount();
265 : :
266 : 56 : ScHFAreas::iterator aItr = maAreas.begin();
267 : 56 : ScHFAreas::iterator aEndItr = maAreas.end();
268 [ + + ][ + - ]: 168 : while (!xRet.is() && (nIndex >= 0) && (aItr != aEndItr))
[ + - ][ + - ]
[ + + ]
269 : : {
270 [ + + ]: 112 : if (*aItr)
271 : : {
272 [ + + ]: 86 : if (nIndex == 0)
273 [ + - ][ + - ]: 56 : xRet = *aItr;
274 : : else
275 : 30 : --nIndex;
276 : : }
277 : : else
278 : 26 : ++aItr;
279 : : }
280 : :
281 [ - + ]: 56 : if ( !xRet.is() )
282 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
283 : :
284 [ + - ]: 56 : return xRet;
285 : : }
286 : :
287 : 2 : sal_Int32 SAL_CALL ScAccessiblePageHeader::getAccessibleIndexInParent() throw (uno::RuntimeException)
288 : : {
289 : 2 : return mnIndex;
290 : : }
291 : :
292 : 37 : uno::Reference< XAccessibleStateSet > SAL_CALL ScAccessiblePageHeader::getAccessibleStateSet()
293 : : throw (uno::RuntimeException)
294 : : {
295 [ + - ]: 37 : SolarMutexGuard aGuard;
296 : 37 : uno::Reference<XAccessibleStateSet> xParentStates;
297 [ + - ][ + - ]: 37 : if (getAccessibleParent().is())
298 : : {
299 [ + - ][ + - ]: 37 : uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
[ + - ]
300 [ + - ][ + - ]: 37 : xParentStates = xParentContext->getAccessibleStateSet();
[ + - ]
301 : : }
302 [ + - ]: 37 : utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
303 [ + - ][ - + ]: 37 : if (IsDefunc(xParentStates))
304 [ # # ]: 0 : pStateSet->AddState(AccessibleStateType::DEFUNC);
305 : : else
306 : : {
307 [ + - ]: 37 : pStateSet->AddState(AccessibleStateType::ENABLED);
308 [ + - ]: 37 : pStateSet->AddState(AccessibleStateType::OPAQUE);
309 [ + - ][ + - ]: 37 : if (isShowing())
310 [ + - ]: 37 : pStateSet->AddState(AccessibleStateType::SHOWING);
311 [ + - ][ + - ]: 37 : if (isVisible())
312 [ + - ]: 37 : pStateSet->AddState(AccessibleStateType::VISIBLE);
313 : : }
314 [ + - ][ + - ]: 37 : return pStateSet;
[ + - ]
315 : : }
316 : :
317 : : //===== XServiceInfo ====================================================
318 : :
319 : 5 : rtl::OUString SAL_CALL ScAccessiblePageHeader::getImplementationName() throw(uno::RuntimeException)
320 : : {
321 : 5 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScAccessiblePageHeader"));
322 : : }
323 : :
324 : 0 : uno::Sequence<rtl::OUString> SAL_CALL ScAccessiblePageHeader::getSupportedServiceNames()
325 : : throw(uno::RuntimeException)
326 : : {
327 : 0 : uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
328 : 0 : sal_Int32 nOldSize(aSequence.getLength());
329 [ # # ]: 0 : aSequence.realloc(nOldSize + 1);
330 [ # # ]: 0 : ::rtl::OUString* pNames = aSequence.getArray();
331 : :
332 [ # # ]: 0 : pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.AccessibleHeaderFooterView"));
333 : :
334 : 0 : return aSequence;
335 : : }
336 : :
337 : : //==== internal =========================================================
338 : :
339 : 24 : ::rtl::OUString SAL_CALL ScAccessiblePageHeader::createAccessibleDescription(void)
340 : : throw (uno::RuntimeException)
341 : : {
342 [ + - ][ + - ]: 24 : String sDesc(ScResId(mbHeader ? STR_ACC_HEADER_DESCR : STR_ACC_FOOTER_DESCR));
[ + - ]
343 [ + - ][ + - ]: 24 : sDesc.SearchAndReplaceAscii("%1", String(ScResId(SCSTR_UNKNOWN)));
[ + - ][ + - ]
344 [ + - ][ + - ]: 24 : return rtl::OUString( sDesc );
345 : : }
346 : :
347 : 3 : ::rtl::OUString SAL_CALL ScAccessiblePageHeader::createAccessibleName(void)
348 : : throw (uno::RuntimeException)
349 : : {
350 [ + - ][ + - ]: 3 : String sName(ScResId(mbHeader ? STR_ACC_HEADER_NAME : STR_ACC_FOOTER_NAME));
[ + - ]
351 [ + - ][ + - ]: 3 : sName.SearchAndReplaceAscii("%1", String(ScResId(SCSTR_UNKNOWN)));
[ + - ][ + - ]
352 [ + - ][ + - ]: 3 : return rtl::OUString( sName );
353 : : }
354 : :
355 : 4 : Rectangle ScAccessiblePageHeader::GetBoundingBoxOnScreen() const throw (uno::RuntimeException)
356 : : {
357 : 4 : Rectangle aCellRect(GetBoundingBox());
358 [ + - ]: 4 : if (mpViewShell)
359 : : {
360 : 4 : Window* pWindow = mpViewShell->GetWindow();
361 [ + - ]: 4 : if (pWindow)
362 : : {
363 [ + - ]: 4 : Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
364 : 4 : aCellRect.setX(aCellRect.getX() + aRect.getX());
365 : 4 : aCellRect.setY(aCellRect.getY() + aRect.getY());
366 : : }
367 : : }
368 : 4 : return aCellRect;
369 : : }
370 : :
371 : 1819 : Rectangle ScAccessiblePageHeader::GetBoundingBox() const throw (uno::RuntimeException)
372 : : {
373 : 1819 : Rectangle aRect;
374 [ + - ]: 1819 : if (mpViewShell)
375 : : {
376 [ + - ]: 1819 : const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
377 [ + + ]: 1819 : if ( mbHeader )
378 [ + - ]: 1799 : rData.GetHeaderPosition( aRect );
379 : : else
380 [ + - ]: 20 : rData.GetFooterPosition( aRect );
381 : :
382 : : // the Rectangle could contain negative coordinates so it should be cliped
383 [ + - ][ + - ]: 1819 : Rectangle aClipRect(Point(0, 0), aRect.GetSize());
384 : 1819 : Window* pWindow = mpViewShell->GetWindow();
385 [ + - ]: 1819 : if (pWindow)
386 [ + - ][ + - ]: 1819 : aClipRect = pWindow->GetWindowExtentsRelative(pWindow->GetAccessibleParentWindow());
387 [ + - ]: 1819 : aRect = aClipRect.GetIntersection(aRect);
388 : : }
389 [ - + ]: 1819 : if (aRect.IsEmpty())
390 [ # # ]: 0 : aRect.SetSize(Size(-1, -1));
391 : :
392 : 1819 : return aRect;
393 : : }
394 : :
395 : 37 : sal_Bool ScAccessiblePageHeader::IsDefunc( const uno::Reference<XAccessibleStateSet>& rxParentStates )
396 : : {
397 [ + - ][ + - ]: 111 : return ScAccessibleContextBase::IsDefunc() || (mpViewShell == NULL) || !getAccessibleParent().is() ||
[ # # ]
398 [ + - + - ]: 111 : (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
[ + - ][ + - ]
[ + - ][ - + ]
[ + - ]
399 : : }
400 : :
401 : 108 : void ScAccessiblePageHeader::AddChild(const EditTextObject* pArea, sal_uInt32 nIndex, SvxAdjust eAdjust)
402 : : {
403 [ + - ][ + - ]: 108 : if (pArea && (pArea->GetText(0).Len() || (pArea->GetParagraphCount() > 1)))
[ + + ][ + - ]
[ - + ][ + - ]
[ + + # # ]
404 : : {
405 [ + + ]: 52 : if (maAreas[nIndex])
406 : : {
407 [ - + ]: 28 : if (!ScGlobal::EETextObjEqual(maAreas[nIndex]->GetEditTextObject(), pArea))
408 : : {
409 : 0 : maAreas[nIndex]->release();
410 [ # # ]: 0 : maAreas[nIndex] = new ScAccessiblePageHeaderArea(this, mpViewShell, pArea, mbHeader, eAdjust);
411 : 0 : maAreas[nIndex]->acquire();
412 : : }
413 : : }
414 : : else
415 : : {
416 [ + - ]: 24 : maAreas[nIndex] = new ScAccessiblePageHeaderArea(this, mpViewShell, pArea, mbHeader, eAdjust);
417 : 24 : maAreas[nIndex]->acquire();
418 : : }
419 : 52 : ++mnChildCount;
420 : : }
421 : : else
422 : : {
423 [ - + ]: 56 : if (maAreas[nIndex])
424 : : {
425 : 0 : maAreas[nIndex]->release();
426 : 0 : maAreas[nIndex] = NULL;
427 : : }
428 : : }
429 : 108 : }
430 : :
431 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|