LibreOffice Module sc (master) 1
AccessiblePageHeaderArea.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
20#include <sal/config.h>
21
22#include <tools/gen.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>
30
31#include <com/sun/star/accessibility/AccessibleRole.hpp>
32#include <com/sun/star/accessibility/AccessibleStateType.hpp>
33#include <com/sun/star/accessibility/AccessibleEventId.hpp>
35#include <editeng/editobj.hxx>
38#include <vcl/svapp.hxx>
39
40using namespace ::com::sun::star;
41using namespace ::com::sun::star::accessibility;
42
43 //===== internal ========================================================
44
46 const uno::Reference<XAccessible>& rxParent,
47 ScPreviewShell* pViewShell,
48 const EditTextObject* pEditObj,
49 SvxAdjust eAdjust)
50 : ScAccessibleContextBase(rxParent, AccessibleRole::TEXT),
51 mpEditObj(pEditObj->Clone()),
52 mpViewShell(pViewShell),
53 meAdjust(eAdjust)
54{
55 if (mpViewShell)
57}
58
60{
61 if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
62 {
63 // increment refcount to prevent double call off dtor
64 osl_atomic_increment( &m_refCount );
65 dispose();
66 }
67}
68
70{
71 SolarMutexGuard aGuard;
72 if (mpViewShell)
73 {
75 mpViewShell = nullptr;
76 }
77 mpTextHelper.reset();
78 mpEditObj.reset();
80}
81
82//===== SfxListener =====================================================
83
85{
86 // only notify if child exist, otherwise it is not necessary
87 if (rHint.GetId() == SfxHintId::ScAccVisAreaChanged)
88 {
89 if (mpTextHelper)
90 mpTextHelper->UpdateChildren();
91
92 AccessibleEventObject aEvent;
93 aEvent.EventId = AccessibleEventId::VISIBLE_DATA_CHANGED;
94 aEvent.Source = uno::Reference< XAccessibleContext >(this);
96 }
98}
99 //===== XAccessibleComponent ============================================
100
101uno::Reference< XAccessible > SAL_CALL ScAccessiblePageHeaderArea::getAccessibleAtPoint(
102 const awt::Point& rPoint )
103{
104 uno::Reference<XAccessible> xRet;
105 if (containsPoint(rPoint))
106 {
107 SolarMutexGuard aGuard;
109
110 if(!mpTextHelper)
112
113 xRet = mpTextHelper->GetAt(rPoint);
114 }
115
116 return xRet;
117}
118
119 //===== XAccessibleContext ==============================================
120
121sal_Int64 SAL_CALL
123{
124 SolarMutexGuard aGuard;
126 if (!mpTextHelper)
128 return mpTextHelper->GetChildCount();
129}
130
131uno::Reference< XAccessible > SAL_CALL
133{
134 SolarMutexGuard aGuard;
136 if (!mpTextHelper)
138 return mpTextHelper->GetChild(nIndex);
139}
140
142{
143 SolarMutexGuard aGuard;
144 sal_Int64 nStateSet = 0;
145 if (IsDefunc())
146 nStateSet |= AccessibleStateType::DEFUNC;
147 else
148 {
149 nStateSet |= AccessibleStateType::ENABLED;
150 nStateSet |= AccessibleStateType::MULTI_LINE;
151 if (isShowing())
152 nStateSet |= AccessibleStateType::SHOWING;
153 if (isVisible())
154 nStateSet |= AccessibleStateType::VISIBLE;
155 }
156 return nStateSet;
157}
158
159// XServiceInfo
160
161OUString SAL_CALL
163{
164 return "ScAccessiblePageHeaderArea";
165}
166
167uno::Sequence< OUString> SAL_CALL
169{
170 const css::uno::Sequence<OUString> vals { "com.sun.star.sheet.AccessiblePageHeaderFooterAreasView" };
172}
173
174//===== XTypeProvider =======================================================
175
176uno::Sequence<sal_Int8> SAL_CALL
178{
179 return css::uno::Sequence<sal_Int8>();
180}
181
182//===== internal ==============================================================
184{
185 OUString sDesc;
186 switch (meAdjust)
187 {
188 case SvxAdjust::Left :
190 break;
191 case SvxAdjust::Right:
193 break;
194 case SvxAdjust::Center:
196 break;
197 default:
198 OSL_FAIL("wrong adjustment found");
199 }
200
201 return sDesc;
202}
203
205{
206 OUString sName;
207 switch (meAdjust)
208 {
209 case SvxAdjust::Left :
210 sName = ScResId(STR_ACC_LEFTAREA_NAME);
211 break;
212 case SvxAdjust::Right:
213 sName = ScResId(STR_ACC_RIGHTAREA_NAME);
214 break;
215 case SvxAdjust::Center:
216 sName = ScResId(STR_ACC_CENTERAREA_NAME);
217 break;
218 default:
219 OSL_FAIL("wrong adjustment found");
220 }
221
222 return sName;
223}
224
226{
227 tools::Rectangle aRect;
228 if (mxParent.is())
229 {
230 uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
231 uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
232 if (xComp.is())
233 {
234 // has the same size and position on screen like the parent
235 aRect = tools::Rectangle(VCLPoint(xComp->getLocationOnScreen()), VCLRectangle(xComp->getBounds()).GetSize());
236 }
237 }
238 return aRect;
239}
240
242{
243 tools::Rectangle aRect;
244 if (mxParent.is())
245 {
246 uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
247 uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
248 if (xComp.is())
249 {
250 // has the same size and position on screen like the parent and so the pos is (0, 0)
251 tools::Rectangle aNewRect(Point(0, 0), VCLRectangle(xComp->getBounds()).GetSize());
252 aRect = aNewRect;
253 }
254 }
255
256 return aRect;
257}
258
260{
261 if (!mpTextHelper)
262 {
263 mpTextHelper.reset( new ::accessibility::AccessibleTextHelper(
264 std::make_unique<ScAccessibilityEditSource>(
265 std::make_unique<ScAccessibleHeaderTextData>(
266 mpViewShell, mpEditObj.get(), meAdjust))) );
267 mpTextHelper->SetEventSource(this);
268 }
269}
270
271/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
virtual sal_Bool SAL_CALL containsPoint(const css::awt::Point &rPoint) override
===== XAccessibleComponent ============================================
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 =====================================================
css::uno::Reference< css::accessibility::XAccessible > mxParent
Reference to the parent object.
void CommitChange(const css::accessibility::AccessibleEventObject &rEvent) const
Calls all Listener to tell they the change.
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
===== XAccessibleContext ==============================================
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &rPoint) override
===== XAccessibleComponent ============================================
virtual void SAL_CALL disposing() override
virtual ~ScAccessiblePageHeaderArea() override
ScAccessiblePageHeaderArea(const css::uno::Reference< css::accessibility::XAccessible > &rxParent, ScPreviewShell *pViewShell, const EditTextObject *pEditObj, SvxAdjust eAdjust)
virtual tools::Rectangle GetBoundingBoxOnScreen() const override
Return the object's current bounding box relative to the desktop.
virtual OUString SAL_CALL getImplementationName() override
===== XServiceInfo ====================================================
virtual OUString createAccessibleDescription() override
Return this object's description.
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 nIndex) override
Return the specified child or NULL if index is invalid.
virtual tools::Rectangle GetBoundingBox() const override
Return the object's current bounding box relative to the parent object.
std::unique_ptr< EditTextObject > mpEditObj
std::unique_ptr< accessibility::AccessibleTextHelper > mpTextHelper
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 sal_Int64 SAL_CALL getAccessibleStateSet() override
Return the set of current states.
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
===== XTypeProvider ===================================================
virtual OUString createAccessibleName() override
Return the object's current name.
void AddAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1142
void RemoveAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1150
SfxHintId GetId() const
constexpr Size GetSize() const
inline ::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
inline ::Point VCLPoint(const css::awt::Point &rAWTPoint)
ULONG m_refCount
OUString sName
sal_Int32 nIndex
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
void dispose()
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
constexpr OUStringLiteral STR_ACC_RIGHTAREA_DESCR
Definition: strings.hxx:24
constexpr OUStringLiteral STR_ACC_LEFTAREA_DESCR
Definition: strings.hxx:22
constexpr OUStringLiteral STR_ACC_CENTERAREA_DESCR
Definition: strings.hxx:23
SvxAdjust
TEXT