1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <tools/gen.hxx>
23 #include <AccessiblePageHeaderArea.hxx>
24 #include <AccessibleText.hxx>
25 #include <editsrc.hxx>
26 #include <prevwsh.hxx>
27 #include <scresid.hxx>
28 #include <strings.hrc>
29 #include <strings.hxx>
31 #include <com/sun/star/accessibility/AccessibleRole.hpp>
32 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
33 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
34 #include <comphelper/sequence.hxx>
35 #include <editeng/editobj.hxx>
36 #include <svx/AccessibleTextHelper.hxx>
37 #include <vcl/svapp.hxx>
38 #include <vcl/unohelp.hxx>
40 using namespace ::com::sun::star
;
41 using namespace ::com::sun::star::accessibility
;
43 //===== internal ========================================================
45 ScAccessiblePageHeaderArea::ScAccessiblePageHeaderArea(
46 const uno::Reference
<XAccessible
>& rxParent
,
47 ScPreviewShell
* pViewShell
,
48 const EditTextObject
* pEditObj
,
50 : ScAccessibleContextBase(rxParent
, AccessibleRole::TEXT
),
51 mpEditObj(pEditObj
->Clone()),
52 mpViewShell(pViewShell
),
56 mpViewShell
->AddAccessibilityObject(*this);
59 ScAccessiblePageHeaderArea::~ScAccessiblePageHeaderArea()
61 if (!ScAccessibleContextBase::IsDefunc() && !rBHelper
.bInDispose
)
63 // increment refcount to prevent double call off dtor
64 osl_atomic_increment( &m_refCount
);
69 void SAL_CALL
ScAccessiblePageHeaderArea::disposing()
71 SolarMutexGuard aGuard
;
74 mpViewShell
->RemoveAccessibilityObject(*this);
75 mpViewShell
= nullptr;
79 ScAccessibleContextBase::disposing();
82 //===== SfxListener =====================================================
84 void ScAccessiblePageHeaderArea::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
86 // only notify if child exist, otherwise it is not necessary
87 if (rHint
.GetId() == SfxHintId::ScAccVisAreaChanged
)
90 mpTextHelper
->UpdateChildren();
92 AccessibleEventObject aEvent
;
93 aEvent
.EventId
= AccessibleEventId::VISIBLE_DATA_CHANGED
;
94 aEvent
.Source
= uno::Reference
< XAccessibleContext
>(this);
97 ScAccessibleContextBase::Notify(rBC
, rHint
);
99 //===== XAccessibleComponent ============================================
101 uno::Reference
< XAccessible
> SAL_CALL
ScAccessiblePageHeaderArea::getAccessibleAtPoint(
102 const awt::Point
& rPoint
)
104 uno::Reference
<XAccessible
> xRet
;
105 if (containsPoint(rPoint
))
107 SolarMutexGuard aGuard
;
113 xRet
= mpTextHelper
->GetAt(rPoint
);
119 //===== XAccessibleContext ==============================================
122 ScAccessiblePageHeaderArea::getAccessibleChildCount()
124 SolarMutexGuard aGuard
;
128 return mpTextHelper
->GetChildCount();
131 uno::Reference
< XAccessible
> SAL_CALL
132 ScAccessiblePageHeaderArea::getAccessibleChild(sal_Int64 nIndex
)
134 SolarMutexGuard aGuard
;
138 return mpTextHelper
->GetChild(nIndex
);
141 sal_Int64 SAL_CALL
ScAccessiblePageHeaderArea::getAccessibleStateSet()
143 SolarMutexGuard aGuard
;
144 sal_Int64 nStateSet
= 0;
146 nStateSet
|= AccessibleStateType::DEFUNC
;
149 nStateSet
|= AccessibleStateType::ENABLED
;
150 nStateSet
|= AccessibleStateType::MULTI_LINE
;
152 nStateSet
|= AccessibleStateType::SHOWING
;
154 nStateSet
|= AccessibleStateType::VISIBLE
;
162 ScAccessiblePageHeaderArea::getImplementationName()
164 return u
"ScAccessiblePageHeaderArea"_ustr
;
167 uno::Sequence
< OUString
> SAL_CALL
168 ScAccessiblePageHeaderArea::getSupportedServiceNames()
170 const css::uno::Sequence
<OUString
> vals
{ u
"com.sun.star.sheet.AccessiblePageHeaderFooterAreasView"_ustr
};
171 return comphelper::concatSequences(ScAccessibleContextBase::getSupportedServiceNames(), vals
);
174 //===== XTypeProvider =======================================================
176 uno::Sequence
<sal_Int8
> SAL_CALL
177 ScAccessiblePageHeaderArea::getImplementationId()
179 return css::uno::Sequence
<sal_Int8
>();
182 //===== internal ==============================================================
183 OUString
ScAccessiblePageHeaderArea::createAccessibleDescription()
188 case SvxAdjust::Left
:
189 sDesc
= STR_ACC_LEFTAREA_DESCR
;
191 case SvxAdjust::Right
:
192 sDesc
= STR_ACC_RIGHTAREA_DESCR
;
194 case SvxAdjust::Center
:
195 sDesc
= STR_ACC_CENTERAREA_DESCR
;
198 OSL_FAIL("wrong adjustment found");
204 OUString
ScAccessiblePageHeaderArea::createAccessibleName()
209 case SvxAdjust::Left
:
210 sName
= ScResId(STR_ACC_LEFTAREA_NAME
);
212 case SvxAdjust::Right
:
213 sName
= ScResId(STR_ACC_RIGHTAREA_NAME
);
215 case SvxAdjust::Center
:
216 sName
= ScResId(STR_ACC_CENTERAREA_NAME
);
219 OSL_FAIL("wrong adjustment found");
225 AbsoluteScreenPixelRectangle
ScAccessiblePageHeaderArea::GetBoundingBoxOnScreen() const
227 AbsoluteScreenPixelRectangle aRect
;
230 uno::Reference
<XAccessibleContext
> xContext
= mxParent
->getAccessibleContext();
231 uno::Reference
<XAccessibleComponent
> xComp(xContext
, uno::UNO_QUERY
);
234 // has the same size and position on screen like the parent
235 aRect
= AbsoluteScreenPixelRectangle(
236 AbsoluteScreenPixelPoint(
237 vcl::unohelper::ConvertToVCLPoint(xComp
->getLocationOnScreen())),
238 AbsoluteScreenPixelSize(
239 vcl::unohelper::ConvertToVCLRect(xComp
->getBounds()).GetSize()));
245 tools::Rectangle
ScAccessiblePageHeaderArea::GetBoundingBox() const
247 tools::Rectangle aRect
;
250 uno::Reference
<XAccessibleContext
> xContext
= mxParent
->getAccessibleContext();
251 uno::Reference
<XAccessibleComponent
> xComp(xContext
, uno::UNO_QUERY
);
254 // has the same size and position on screen like the parent and so the pos is (0, 0)
255 tools::Rectangle
aNewRect(Point(0, 0),
256 vcl::unohelper::ConvertToVCLRect(xComp
->getBounds()).GetSize());
264 void ScAccessiblePageHeaderArea::CreateTextHelper()
268 mpTextHelper
.reset( new ::accessibility::AccessibleTextHelper(
269 std::make_unique
<ScAccessibilityEditSource
>(
270 std::make_unique
<ScAccessibleHeaderTextData
>(
271 mpViewShell
, mpEditObj
.get(), meAdjust
))) );
272 mpTextHelper
->SetEventSource(this);
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */