LibreOffice Module sc (master) 1
AccessiblePageHeader.cxx
Go to the documentation of this file.
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
22#include <prevwsh.hxx>
23#include <prevloc.hxx>
24#include <document.hxx>
25#include <stlpool.hxx>
26#include <scitems.hxx>
27#include <attrib.hxx>
28#include <scresid.hxx>
29#include <strings.hrc>
30#include <strings.hxx>
31
32#include <com/sun/star/accessibility/AccessibleRole.hpp>
33#include <com/sun/star/accessibility/AccessibleStateType.hpp>
34#include <com/sun/star/accessibility/AccessibleEventId.hpp>
35#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
37
38#include <vcl/window.hxx>
39#include <svl/hint.hxx>
40#include <svl/itemset.hxx>
41#include <vcl/svapp.hxx>
42#include <svl/style.hxx>
43#include <editeng/editobj.hxx>
44
45using namespace ::com::sun::star;
46using namespace ::com::sun::star::accessibility;
47
49
50ScAccessiblePageHeader::ScAccessiblePageHeader( const css::uno::Reference<css::accessibility::XAccessible>& rxParent,
51 ScPreviewShell* pViewShell, bool bHeader, sal_Int32 nIndex ) :
52ScAccessibleContextBase( rxParent, bHeader ? AccessibleRole::HEADER : AccessibleRole::FOOTER ),
53 mpViewShell( pViewShell ),
54 mnIndex( nIndex ),
55 mbHeader( bHeader ),
57 mnChildCount(-1)
58{
59 if (mpViewShell)
61}
62
64{
65 if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
66 {
67 // increment refcount to prevent double call off dtor
68 osl_atomic_increment( &m_refCount );
69 dispose();
70 }
71}
72
74{
75 SolarMutexGuard aGuard;
76 if (mpViewShell)
77 {
79 mpViewShell = nullptr;
80 }
81 for (auto & i : maAreas)
82 {
83 if (i.is())
84 {
85 i->dispose();
86 i.clear();
87 }
88 }
89
91}
92
93//===== SfxListener =====================================================
94
96{
97 // only notify if child exist, otherwise it is not necessary
98 if (rHint.GetId() == SfxHintId::ScDataChanged)
99 {
100 std::vector<rtl::Reference<ScAccessiblePageHeaderArea>> aOldAreas(maAreas);
101 mnChildCount = -1;
103 for (sal_uInt8 i = 0; i < MAX_AREAS; ++i)
104 {
105 if ((aOldAreas[i].is() && maAreas[i].is() && !ScGlobal::EETextObjEqual(aOldAreas[i]->GetEditTextObject(), maAreas[i]->GetEditTextObject())) ||
106 (aOldAreas[i].is() && !maAreas[i].is()) || (!aOldAreas[i].is() && maAreas[i].is()))
107 {
108 if (aOldAreas[i].is() && aOldAreas[i]->GetEditTextObject())
109 {
110 AccessibleEventObject aEvent;
111 aEvent.EventId = AccessibleEventId::CHILD;
112 aEvent.Source = uno::Reference< XAccessibleContext >(this);
113 aEvent.OldValue <<= uno::Reference<XAccessible>(aOldAreas[i]);
114 aEvent.IndexHint = -1;
115
116 CommitChange(aEvent); // child gone - event
117 aOldAreas[i]->dispose();
118 }
119 if (maAreas[i].is() && maAreas[i]->GetEditTextObject())
120 {
121 AccessibleEventObject aEvent;
122 aEvent.EventId = AccessibleEventId::CHILD;
123 aEvent.Source = uno::Reference< XAccessibleContext >(this);
124 aEvent.NewValue <<= uno::Reference<XAccessible>(maAreas[i]);
125 aEvent.IndexHint = -1;
126
127 CommitChange(aEvent); // new child - event
128 }
129 }
130 }
131 }
132 else if (rHint.GetId() == SfxHintId::ScAccVisAreaChanged)
133 {
134 AccessibleEventObject aEvent;
135 aEvent.EventId = AccessibleEventId::VISIBLE_DATA_CHANGED;
136 aEvent.Source = uno::Reference< XAccessibleContext >(this);
138 }
139
141}
142
143//===== XAccessibleComponent ============================================
144
145uno::Reference< XAccessible > SAL_CALL ScAccessiblePageHeader::getAccessibleAtPoint( const awt::Point& aPoint )
146{
147 uno::Reference<XAccessible> xRet;
148
149 if (containsPoint(aPoint))
150 {
151 SolarMutexGuard aGuard;
153
154 sal_Int64 nCount(getAccessibleChildCount()); // fill the areas
155
156 if (nCount)
157 {
158 // return the first with content, because they have all the same Bounding Box
159 sal_uInt8 i(0);
160 while(!xRet.is() && i < MAX_AREAS)
161 {
162 if (maAreas[i].is())
163 xRet = maAreas[i].get();
164 else
165 ++i;
166 }
167 }
168 }
169
170 return xRet;
171}
172
174{
175 SolarMutexGuard aGuard;
177 if (getAccessibleParent().is())
178 {
179 uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
180 if (xAccessibleComponent.is())
181 xAccessibleComponent->grabFocus();
182 }
183}
184
185//===== XAccessibleContext ==============================================
186
188{
189 SolarMutexGuard aGuard;
191
192 if((mnChildCount < 0) && mpViewShell)
193 {
194 mnChildCount = 0;
196 // find out how many regions (left,center, right) are with content
197
198 SfxStyleSheetBase* pStyle = rDoc.GetStyleSheetPool()->Find(rDoc.GetPageStyle(mpViewShell->GetLocationData().GetPrintTab()), SfxStyleFamily::Page);
199 if (pStyle)
200 {
201 sal_uInt16 nPageWhichId(0);
202 if (mbHeader)
204 else
206
207 const ScPageHFItem& rPageItem = static_cast<const ScPageHFItem&>(pStyle->GetItemSet().Get(nPageWhichId));
208 AddChild(rPageItem.GetLeftArea(), 0, SvxAdjust::Left);
209 AddChild(rPageItem.GetCenterArea(), 1, SvxAdjust::Center);
210 AddChild(rPageItem.GetRightArea(), 2, SvxAdjust::Right);
211 }
212 }
213
214 return mnChildCount;
215}
216
217uno::Reference< XAccessible > SAL_CALL ScAccessiblePageHeader::getAccessibleChild( sal_Int64 nIndex )
218{
219 SolarMutexGuard aGuard;
221
222 uno::Reference<XAccessible> xRet;
223
224 if(mnChildCount < 0)
226
227 if (nIndex >= 0)
228 for (const auto& rxArea : maAreas)
229 {
230 if (rxArea.is())
231 {
232 if (nIndex == 0)
233 {
234 xRet = rxArea.get();
235 break;
236 }
237 else
238 --nIndex;
239 }
240 }
241
242 if ( !xRet.is() )
243 throw lang::IndexOutOfBoundsException();
244
245 return xRet;
246}
247
249{
250 return mnIndex;
251}
252
254{
255 SolarMutexGuard aGuard;
256 sal_Int64 nParentStates = 0;
257 if (getAccessibleParent().is())
258 {
259 uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
260 nParentStates = xParentContext->getAccessibleStateSet();
261 }
262 sal_Int64 nStateSet = 0;
263 if (IsDefunc(nParentStates))
264 nStateSet |= AccessibleStateType::DEFUNC;
265 else
266 {
267 nStateSet |= AccessibleStateType::ENABLED;
268 nStateSet |= AccessibleStateType::OPAQUE;
269 if (isShowing())
270 nStateSet |= AccessibleStateType::SHOWING;
271 if (isVisible())
272 nStateSet |= AccessibleStateType::VISIBLE;
273 }
274 return nStateSet;
275}
276
277//===== XServiceInfo ====================================================
278
280{
281 return "ScAccessiblePageHeader";
282}
283
284uno::Sequence<OUString> SAL_CALL ScAccessiblePageHeader::getSupportedServiceNames()
285{
286 const css::uno::Sequence<OUString> vals { "com.sun.star.text.AccessibleHeaderFooterView" };
288}
289
290//==== internal =========================================================
291
293{
294 OUString sDesc(mbHeader ? OUString(STR_ACC_HEADER_DESCR) : OUString(STR_ACC_FOOTER_DESCR));
295 return sDesc.replaceFirst("%1", ScResId(SCSTR_UNKNOWN));
296}
297
299{
300 OUString sName(ScResId(mbHeader ? STR_ACC_HEADER_NAME : STR_ACC_FOOTER_NAME));
301 return sName.replaceFirst("%1", ScResId(SCSTR_UNKNOWN));
302}
303
305{
306 tools::Rectangle aCellRect(GetBoundingBox());
307 if (mpViewShell)
308 {
309 vcl::Window* pWindow = mpViewShell->GetWindow();
310 if (pWindow)
311 {
313 aCellRect.Move(aRect.Left(), aRect.Top());
314 }
315 }
316 return aCellRect;
317}
318
320{
321 tools::Rectangle aRect;
322 if (mpViewShell)
323 {
325 if ( mbHeader )
326 rData.GetHeaderPosition( aRect );
327 else
328 rData.GetFooterPosition( aRect );
329
330 // the Rectangle could contain negative coordinates so it should be clipped
331 tools::Rectangle aClipRect(Point(0, 0), aRect.GetSize());
332 vcl::Window* pWindow = mpViewShell->GetWindow();
333 if (pWindow)
334 aClipRect = pWindow->GetWindowExtentsRelative(*pWindow->GetAccessibleParentWindow());
335 aRect = aClipRect.GetIntersection(aRect);
336 }
337 if (aRect.IsEmpty())
338 aRect.SetSize(Size(-1, -1));
339
340 return aRect;
341}
342
343bool ScAccessiblePageHeader::IsDefunc( sal_Int64 nParentStates )
344{
345 return ScAccessibleContextBase::IsDefunc() || (mpViewShell == nullptr) || !getAccessibleParent().is() ||
346 (nParentStates & AccessibleStateType::DEFUNC);
347}
348
349void ScAccessiblePageHeader::AddChild(const EditTextObject* pArea, sal_uInt32 nIndex, SvxAdjust eAdjust)
350{
351 if (pArea && (!pArea->GetText(0).isEmpty() || (pArea->GetParagraphCount() > 1)))
352 {
353 if (maAreas[nIndex].is())
354 {
355 if (!ScGlobal::EETextObjEqual(maAreas[nIndex]->GetEditTextObject(), pArea))
356 {
357 maAreas[nIndex] = new ScAccessiblePageHeaderArea(this, mpViewShell, pArea, eAdjust);
358 }
359 }
360 else
361 {
362 maAreas[nIndex] = new ScAccessiblePageHeaderArea(this, mpViewShell, pArea, eAdjust);
363 }
364 ++mnChildCount;
365 }
366 else
367 {
368 maAreas[nIndex].clear();
369 }
370}
371
372/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_uInt8 MAX_AREAS
AnyEventRef aEvent
virtual sal_Int32 GetParagraphCount() const=0
virtual OUString GetText(sal_Int32 nPara) const=0
virtual sal_Bool SAL_CALL containsPoint(const css::awt::Point &rPoint) override
===== XAccessibleComponent ============================================
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
===== XAccessible =====================================================
virtual void SAL_CALL disposing() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
===== SfxListener =====================================================
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
Return a reference to the parent.
void CommitChange(const css::accessibility::AccessibleEventObject &rEvent) const
Calls all Listener to tell they the change.
void AddChild(const EditTextObject *pArea, sal_uInt32 nIndex, SvxAdjust eAdjust)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
virtual OUString SAL_CALL getImplementationName() override
===== XServiceInfo ====================================================
ScAccessiblePageHeader(const css::uno::Reference< css::accessibility::XAccessible > &rxParent, ScPreviewShell *pViewShell, bool bHeader, sal_Int32 nIndex)
virtual void SAL_CALL disposing() override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
===== SfxListener =====================================================
std::vector< rtl::Reference< ScAccessiblePageHeaderArea > > maAreas
virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override
Return this objects index among the parents children.
virtual tools::Rectangle GetBoundingBox() const override
Return the object's current bounding box relative to the parent object.
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
Return the set of current states.
virtual tools::Rectangle GetBoundingBoxOnScreen() const override
Return the object's current bounding box relative to the desktop.
virtual void SAL_CALL grabFocus() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 i) override
Return the specified child or NULL if index is invalid.
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
virtual OUString createAccessibleDescription() override
Return this object's description.
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
===== XAccessibleContext ==============================================
virtual ~ScAccessiblePageHeader() override
virtual OUString createAccessibleName() override
Return the object's current name.
SC_DLLPUBLIC OUString GetPageStyle(SCTAB nTab) const
Definition: document.cxx:6176
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6055
static bool EETextObjEqual(const EditTextObject *pObj1, const EditTextObject *pObj2)
Definition: global.cxx:798
const EditTextObject * GetCenterArea() const
Definition: attrib.hxx:191
const EditTextObject * GetLeftArea() const
Definition: attrib.hxx:190
const EditTextObject * GetRightArea() const
Definition: attrib.hxx:192
bool GetHeaderPosition(tools::Rectangle &rHeaderRect) const
Definition: prevloc.cxx:334
bool IsFooterLeft() const
Definition: prevloc.cxx:376
bool IsHeaderLeft() const
Definition: prevloc.cxx:362
bool GetFooterPosition(tools::Rectangle &rFooterRect) const
Definition: prevloc.cxx:348
SCTAB GetPrintTab() const
Definition: prevloc.hxx:117
const ScPreviewLocationData & GetLocationData()
Definition: prevwsh.cxx:1171
void AddAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1142
ScDocument & GetDocument()
Definition: prevwsh.cxx:1176
void RemoveAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1150
SfxHintId GetId() const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
virtual SfxItemSet & GetItemSet()
vcl::Window * GetWindow() const
tools::Rectangle GetIntersection(const tools::Rectangle &rRect) const
constexpr tools::Long Top() const
void SetSize(const Size &)
constexpr Size GetSize() const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
constexpr tools::Long Left() const
constexpr bool IsEmpty() const
tools::Rectangle GetWindowExtentsAbsolute() const
vcl::Window * GetAccessibleParentWindow() const
tools::Rectangle GetWindowExtentsRelative(const vcl::Window &rRelativeWindow) const
int nCount
ULONG m_refCount
OUString sName
sal_Int32 nIndex
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
Reference
int i
void dispose()
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_FOOTERLEFT(179)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERLEFT(178)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_FOOTERRIGHT(181)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERRIGHT(180)
constexpr OUStringLiteral STR_ACC_HEADER_DESCR
Definition: strings.hxx:25
constexpr OUStringLiteral STR_ACC_FOOTER_DESCR
Definition: strings.hxx:26
sal_uInt32 mnIndex
SvxAdjust
unsigned char sal_uInt8