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>
34 #include <comphelper/sequence.hxx>
35 #include <editeng/editobj.hxx>
39 #include <vcl/svapp.hxx>
40 
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::accessibility;
43 
44  //===== internal ========================================================
45 
47  const uno::Reference<XAccessible>& rxParent,
48  ScPreviewShell* pViewShell,
49  const EditTextObject* pEditObj,
50  SvxAdjust eAdjust)
51  : ScAccessibleContextBase(rxParent, AccessibleRole::TEXT),
52  mpEditObj(pEditObj->Clone()),
53  mpViewShell(pViewShell),
54  meAdjust(eAdjust)
55 {
56  if (mpViewShell)
58 }
59 
61 {
62  if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
63  {
64  // increment refcount to prevent double call off dtor
65  osl_atomic_increment( &m_refCount );
66  dispose();
67  }
68 }
69 
71 {
72  SolarMutexGuard aGuard;
73  if (mpViewShell)
74  {
76  mpViewShell = nullptr;
77  }
78  mpTextHelper.reset();
79  mpEditObj.reset();
81 }
82 
83 //===== SfxListener =====================================================
84 
86 {
87  // only notify if child exist, otherwise it is not necessary
88  if (rHint.GetId() == SfxHintId::ScAccVisAreaChanged)
89  {
90  if (mpTextHelper)
91  mpTextHelper->UpdateChildren();
92 
93  AccessibleEventObject aEvent;
94  aEvent.EventId = AccessibleEventId::VISIBLE_DATA_CHANGED;
95  aEvent.Source = uno::Reference< XAccessibleContext >(this);
96  CommitChange(aEvent);
97  }
99 }
100  //===== XAccessibleComponent ============================================
101 
102 uno::Reference< XAccessible > SAL_CALL ScAccessiblePageHeaderArea::getAccessibleAtPoint(
103  const awt::Point& rPoint )
104 {
105  uno::Reference<XAccessible> xRet;
106  if (containsPoint(rPoint))
107  {
108  SolarMutexGuard aGuard;
109  IsObjectValid();
110 
111  if(!mpTextHelper)
113 
114  xRet = mpTextHelper->GetAt(rPoint);
115  }
116 
117  return xRet;
118 }
119 
120  //===== XAccessibleContext ==============================================
121 
122 sal_Int32 SAL_CALL
124 {
125  SolarMutexGuard aGuard;
126  IsObjectValid();
127  if (!mpTextHelper)
129  return mpTextHelper->GetChildCount();
130 }
131 
132 uno::Reference< XAccessible > SAL_CALL
134 {
135  SolarMutexGuard aGuard;
136  IsObjectValid();
137  if (!mpTextHelper)
139  return mpTextHelper->GetChild(nIndex);
140 }
141 
142 uno::Reference<XAccessibleStateSet> SAL_CALL
144 {
145  SolarMutexGuard aGuard;
146  uno::Reference<XAccessibleStateSet> xParentStates;
147  if (getAccessibleParent().is())
148  {
149  uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
150  xParentStates = xParentContext->getAccessibleStateSet();
151  }
153  if (IsDefunc())
154  pStateSet->AddState(AccessibleStateType::DEFUNC);
155  else
156  {
157  pStateSet->AddState(AccessibleStateType::ENABLED);
158  pStateSet->AddState(AccessibleStateType::MULTI_LINE);
159  if (isShowing())
160  pStateSet->AddState(AccessibleStateType::SHOWING);
161  if (isVisible())
162  pStateSet->AddState(AccessibleStateType::VISIBLE);
163  }
164  return pStateSet;
165 }
166 
167 // XServiceInfo
168 
169 OUString SAL_CALL
171 {
172  return "ScAccessiblePageHeaderArea";
173 }
174 
175 uno::Sequence< OUString> SAL_CALL
177 {
178  const css::uno::Sequence<OUString> vals { "com.sun.star.sheet.AccessiblePageHeaderFooterAreasView" };
180 }
181 
182 //===== XTypeProvider =======================================================
183 
184 uno::Sequence<sal_Int8> SAL_CALL
186 {
187  return css::uno::Sequence<sal_Int8>();
188 }
189 
190 //===== internal ==============================================================
192 {
193  OUString sDesc;
194  switch (meAdjust)
195  {
196  case SvxAdjust::Left :
197  sDesc = STR_ACC_LEFTAREA_DESCR;
198  break;
199  case SvxAdjust::Right:
200  sDesc = STR_ACC_RIGHTAREA_DESCR;
201  break;
202  case SvxAdjust::Center:
203  sDesc = STR_ACC_CENTERAREA_DESCR;
204  break;
205  default:
206  OSL_FAIL("wrong adjustment found");
207  }
208 
209  return sDesc;
210 }
211 
213 {
214  OUString sName;
215  switch (meAdjust)
216  {
217  case SvxAdjust::Left :
218  sName = ScResId(STR_ACC_LEFTAREA_NAME);
219  break;
220  case SvxAdjust::Right:
221  sName = ScResId(STR_ACC_RIGHTAREA_NAME);
222  break;
223  case SvxAdjust::Center:
224  sName = ScResId(STR_ACC_CENTERAREA_NAME);
225  break;
226  default:
227  OSL_FAIL("wrong adjustment found");
228  }
229 
230  return sName;
231 }
232 
234 {
235  tools::Rectangle aRect;
236  if (mxParent.is())
237  {
238  uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
239  uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
240  if (xComp.is())
241  {
242  // has the same size and position on screen like the parent
243  aRect = tools::Rectangle(VCLPoint(xComp->getLocationOnScreen()), VCLRectangle(xComp->getBounds()).GetSize());
244  }
245  }
246  return aRect;
247 }
248 
250 {
251  tools::Rectangle aRect;
252  if (mxParent.is())
253  {
254  uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
255  uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
256  if (xComp.is())
257  {
258  // has the same size and position on screen like the parent and so the pos is (0, 0)
259  tools::Rectangle aNewRect(Point(0, 0), VCLRectangle(xComp->getBounds()).GetSize());
260  aRect = aNewRect;
261  }
262  }
263 
264  return aRect;
265 }
266 
268 {
269  if (!mpTextHelper)
270  {
271  mpTextHelper.reset( new ::accessibility::AccessibleTextHelper(
272  std::make_unique<ScAccessibilityEditSource>(
273  std::make_unique<ScAccessibleHeaderTextData>(
274  mpViewShell, mpEditObj.get(), meAdjust))) );
275  mpTextHelper->SetEventSource(this);
276  }
277 }
278 
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > 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.
void AddAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1149
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
ULONG m_refCount
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
Return a reference to the parent.
virtual sal_Bool SAL_CALL containsPoint(const css::awt::Point &rPoint) override
===== XAccessibleComponent ============================================
SfxHintId GetId() const
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int32 nIndex) override
Return the specified child or NULL if index is invalid.
virtual OUString createAccessibleDescription() override
Return this object's description.
std::unique_ptr< EditTextObject > mpEditObj
virtual OUString SAL_CALL getImplementationName() override
===== XServiceInfo ====================================================
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
===== SfxListener =====================================================
const char * sName
#define STR_ACC_LEFTAREA_DESCR
Definition: strings.hxx:20
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 =====================================================
SvxAdjust
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
virtual ~ScAccessiblePageHeaderArea() override
inline::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
===== XTypeProvider ===================================================
virtual tools::Rectangle GetBoundingBox() const override
Return the object's current bounding box relative to the parent object.
virtual sal_Int32 SAL_CALL getAccessibleChildCount() override
===== XAccessibleContext ==============================================
inline::Point VCLPoint(const css::awt::Point &rAWTPoint)
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &...rSn)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
virtual void SAL_CALL disposing() override
void RemoveAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1157
#define STR_ACC_CENTERAREA_DESCR
Definition: strings.hxx:21
virtual void SAL_CALL disposing() override
ScAccessiblePageHeaderArea(const css::uno::Reference< css::accessibility::XAccessible > &rxParent, ScPreviewShell *pViewShell, const EditTextObject *pEditObj, SvxAdjust eAdjust)
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &rPoint) override
===== XAccessibleComponent ============================================
#define STR_ACC_RIGHTAREA_DESCR
Definition: strings.hxx:22
std::unique_ptr< accessibility::AccessibleTextHelper > mpTextHelper
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.
void dispose()
virtual OUString createAccessibleName() override
Return the object's current name.
TEXT
AnyEventRef aEvent