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 <editeng/editobj.hxx>
38 #include <vcl/svapp.hxx>
39 
40 using namespace ::com::sun::star;
41 using 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);
95  CommitChange(aEvent);
96  }
98 }
99  //===== XAccessibleComponent ============================================
100 
101 uno::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;
108  IsObjectValid();
109 
110  if(!mpTextHelper)
112 
113  xRet = mpTextHelper->GetAt(rPoint);
114  }
115 
116  return xRet;
117 }
118 
119  //===== XAccessibleContext ==============================================
120 
121 sal_Int32 SAL_CALL
123 {
124  SolarMutexGuard aGuard;
125  IsObjectValid();
126  if (!mpTextHelper)
128  return mpTextHelper->GetChildCount();
129 }
130 
131 uno::Reference< XAccessible > SAL_CALL
133 {
134  SolarMutexGuard aGuard;
135  IsObjectValid();
136  if (!mpTextHelper)
138  return mpTextHelper->GetChild(nIndex);
139 }
140 
141 uno::Reference<XAccessibleStateSet> SAL_CALL
143 {
144  SolarMutexGuard aGuard;
145  uno::Reference<XAccessibleStateSet> xParentStates;
146  if (getAccessibleParent().is())
147  {
148  uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
149  xParentStates = xParentContext->getAccessibleStateSet();
150  }
152  if (IsDefunc())
153  pStateSet->AddState(AccessibleStateType::DEFUNC);
154  else
155  {
156  pStateSet->AddState(AccessibleStateType::ENABLED);
157  pStateSet->AddState(AccessibleStateType::MULTI_LINE);
158  if (isShowing())
159  pStateSet->AddState(AccessibleStateType::SHOWING);
160  if (isVisible())
161  pStateSet->AddState(AccessibleStateType::VISIBLE);
162  }
163  return pStateSet;
164 }
165 
166 // XServiceInfo
167 
168 OUString SAL_CALL
170 {
171  return "ScAccessiblePageHeaderArea";
172 }
173 
174 uno::Sequence< OUString> SAL_CALL
176 {
177  uno::Sequence< OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
178  sal_Int32 nOldSize(aSequence.getLength());
179  aSequence.realloc(nOldSize + 1);
180 
181  aSequence[nOldSize] = "com.sun.star.sheet.AccessiblePageHeaderFooterAreasView";
182 
183  return aSequence;
184 }
185 
186 //===== XTypeProvider =======================================================
187 
188 uno::Sequence<sal_Int8> SAL_CALL
190 {
191  return css::uno::Sequence<sal_Int8>();
192 }
193 
194 //===== internal ==============================================================
196 {
197  OUString sDesc;
198  switch (meAdjust)
199  {
200  case SvxAdjust::Left :
201  sDesc = STR_ACC_LEFTAREA_DESCR;
202  break;
203  case SvxAdjust::Right:
204  sDesc = STR_ACC_RIGHTAREA_DESCR;
205  break;
206  case SvxAdjust::Center:
207  sDesc = STR_ACC_CENTERAREA_DESCR;
208  break;
209  default:
210  OSL_FAIL("wrong adjustment found");
211  }
212 
213  return sDesc;
214 }
215 
217 {
218  OUString sName;
219  switch (meAdjust)
220  {
221  case SvxAdjust::Left :
222  sName = ScResId(STR_ACC_LEFTAREA_NAME);
223  break;
224  case SvxAdjust::Right:
225  sName = ScResId(STR_ACC_RIGHTAREA_NAME);
226  break;
227  case SvxAdjust::Center:
228  sName = ScResId(STR_ACC_CENTERAREA_NAME);
229  break;
230  default:
231  OSL_FAIL("wrong adjustment found");
232  }
233 
234  return sName;
235 }
236 
238 {
239  tools::Rectangle aRect;
240  if (mxParent.is())
241  {
242  uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
243  uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
244  if (xComp.is())
245  {
246  // has the same size and position on screen like the parent
247  aRect = tools::Rectangle(VCLPoint(xComp->getLocationOnScreen()), VCLRectangle(xComp->getBounds()).GetSize());
248  }
249  }
250  return aRect;
251 }
252 
254 {
255  tools::Rectangle aRect;
256  if (mxParent.is())
257  {
258  uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
259  uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
260  if (xComp.is())
261  {
262  // has the same size and position on screen like the parent and so the pos is (0, 0)
263  tools::Rectangle aNewRect(Point(0, 0), VCLRectangle(xComp->getBounds()).GetSize());
264  aRect = aNewRect;
265  }
266  }
267 
268  return aRect;
269 }
270 
272 {
273  if (!mpTextHelper)
274  {
275  mpTextHelper.reset( new ::accessibility::AccessibleTextHelper(
276  std::make_unique<ScAccessibilityEditSource>(
277  std::make_unique<ScAccessibleHeaderTextData>(
278  mpViewShell, mpEditObj.get(), meAdjust))) );
279  mpTextHelper->SetEventSource(this);
280  }
281 }
282 
283 /* 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:1148
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)
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
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)
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:1156
#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()
void AddState(sal_Int16 aState)
virtual OUString createAccessibleName() override
Return the object's current name.
TEXT
AnyEventRef aEvent