Update git submodules
[LibreOffice.git] / sc / source / ui / Accessibility / AccessiblePageHeaderArea.cxx
blob4881e2a8ce600c044eb5f3ecd7f59e69f9d401a6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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,
49 SvxAdjust eAdjust)
50 : ScAccessibleContextBase(rxParent, AccessibleRole::TEXT),
51 mpEditObj(pEditObj->Clone()),
52 mpViewShell(pViewShell),
53 meAdjust(eAdjust)
55 if (mpViewShell)
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 );
65 dispose();
69 void SAL_CALL ScAccessiblePageHeaderArea::disposing()
71 SolarMutexGuard aGuard;
72 if (mpViewShell)
74 mpViewShell->RemoveAccessibilityObject(*this);
75 mpViewShell = nullptr;
77 mpTextHelper.reset();
78 mpEditObj.reset();
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)
89 if (mpTextHelper)
90 mpTextHelper->UpdateChildren();
92 AccessibleEventObject aEvent;
93 aEvent.EventId = AccessibleEventId::VISIBLE_DATA_CHANGED;
94 aEvent.Source = uno::Reference< XAccessibleContext >(this);
95 CommitChange(aEvent);
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;
108 IsObjectValid();
110 if(!mpTextHelper)
111 CreateTextHelper();
113 xRet = mpTextHelper->GetAt(rPoint);
116 return xRet;
119 //===== XAccessibleContext ==============================================
121 sal_Int64 SAL_CALL
122 ScAccessiblePageHeaderArea::getAccessibleChildCount()
124 SolarMutexGuard aGuard;
125 IsObjectValid();
126 if (!mpTextHelper)
127 CreateTextHelper();
128 return mpTextHelper->GetChildCount();
131 uno::Reference< XAccessible > SAL_CALL
132 ScAccessiblePageHeaderArea::getAccessibleChild(sal_Int64 nIndex)
134 SolarMutexGuard aGuard;
135 IsObjectValid();
136 if (!mpTextHelper)
137 CreateTextHelper();
138 return mpTextHelper->GetChild(nIndex);
141 sal_Int64 SAL_CALL ScAccessiblePageHeaderArea::getAccessibleStateSet()
143 SolarMutexGuard aGuard;
144 sal_Int64 nStateSet = 0;
145 if (IsDefunc())
146 nStateSet |= AccessibleStateType::DEFUNC;
147 else
149 nStateSet |= AccessibleStateType::ENABLED;
150 nStateSet |= AccessibleStateType::MULTI_LINE;
151 if (isShowing())
152 nStateSet |= AccessibleStateType::SHOWING;
153 if (isVisible())
154 nStateSet |= AccessibleStateType::VISIBLE;
156 return nStateSet;
159 // XServiceInfo
161 OUString SAL_CALL
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()
185 OUString sDesc;
186 switch (meAdjust)
188 case SvxAdjust::Left :
189 sDesc = STR_ACC_LEFTAREA_DESCR;
190 break;
191 case SvxAdjust::Right:
192 sDesc = STR_ACC_RIGHTAREA_DESCR;
193 break;
194 case SvxAdjust::Center:
195 sDesc = STR_ACC_CENTERAREA_DESCR;
196 break;
197 default:
198 OSL_FAIL("wrong adjustment found");
201 return sDesc;
204 OUString ScAccessiblePageHeaderArea::createAccessibleName()
206 OUString sName;
207 switch (meAdjust)
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");
222 return sName;
225 AbsoluteScreenPixelRectangle ScAccessiblePageHeaderArea::GetBoundingBoxOnScreen() const
227 AbsoluteScreenPixelRectangle aRect;
228 if (mxParent.is())
230 uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
231 uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
232 if (xComp.is())
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()));
242 return aRect;
245 tools::Rectangle ScAccessiblePageHeaderArea::GetBoundingBox() const
247 tools::Rectangle aRect;
248 if (mxParent.is())
250 uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
251 uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
252 if (xComp.is())
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());
257 aRect = aNewRect;
261 return aRect;
264 void ScAccessiblePageHeaderArea::CreateTextHelper()
266 if (!mpTextHelper)
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: */