LibreOffice Module sw (master)  1
acctextframe.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 <com/sun/star/accessibility/XAccessibleContext.hpp>
23 #include <vcl/svapp.hxx>
24 #include <sal/log.hxx>
25 #include <com/sun/star/accessibility/AccessibleRole.hpp>
26 #include <com/sun/star/accessibility/AccessibleRelation.hpp>
27 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
28 #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
29 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
30 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
32 #include <frmfmt.hxx>
33 #include <flyfrm.hxx>
34 #include <accmap.hxx>
36 #include <doc.hxx>
37 #include <hints.hxx>
38 #include "acctextframe.hxx"
39 
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::accessibility;
42 
44 using ::com::sun::star::accessibility::XAccessibleContext;
45 
47  std::shared_ptr<SwAccessibleMap> const& pInitMap,
48  const SwFlyFrame& rFlyFrame ) :
49  SwAccessibleFrameBase( pInitMap, AccessibleRole::TEXT_FRAME, &rFlyFrame ),
50  msTitle(),
51  msDesc()
52 {
53  const SwFlyFrameFormat* pFlyFrameFormat = rFlyFrame.GetFormat();
54  msTitle = pFlyFrameFormat->GetObjTitle();
55 
56  msDesc = pFlyFrameFormat->GetObjDescription();
57  if ( msDesc.isEmpty() &&
58  msTitle != GetName() )
59  {
60  msDesc = msTitle;
61  }
62 }
63 
65 {
66 }
67 
68 void SwAccessibleTextFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
69 {
70  const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
71  // #i73249# - suppress handling of RES_NAME_CHANGED
72  // in case that attribute Title is used as the accessible name.
73  if ( nWhich != RES_NAME_CHANGED ||
74  msTitle.isEmpty() )
75  {
76  SwAccessibleFrameBase::Modify( pOld, pNew );
77  }
78 
79  const SwFlyFrame *pFlyFrame = static_cast< const SwFlyFrame * >( GetFrame() );
80  switch( nWhich )
81  {
82  // #i73249#
83  case RES_TITLE_CHANGED:
84  {
85  OUString sOldTitle, sNewTitle;
86  const SwStringMsgPoolItem *pOldItem = dynamic_cast<const SwStringMsgPoolItem*>(pOld);
87  if (pOldItem)
88  sOldTitle = pOldItem->GetString();
89  const SwStringMsgPoolItem *pNewItem = dynamic_cast<const SwStringMsgPoolItem*>(pNew);
90  if (pNewItem)
91  sNewTitle = pNewItem->GetString();
92  if (sOldTitle == sNewTitle)
93  {
94  break;
95  }
96  msTitle = sNewTitle;
97  AccessibleEventObject aEvent;
98  aEvent.EventId = AccessibleEventId::NAME_CHANGED;
99  aEvent.OldValue <<= sOldTitle;
100  aEvent.NewValue <<= msTitle;
101  FireAccessibleEvent( aEvent );
102 
103  const SwFlyFrameFormat* pFlyFrameFormat = pFlyFrame->GetFormat();
104  if (!pFlyFrameFormat || !pFlyFrameFormat->GetObjDescription().isEmpty())
105  {
106  break;
107  }
108  [[fallthrough]];
109  }
111  {
112  if ( pFlyFrame )
113  {
114  const OUString sOldDesc( msDesc );
115 
116  const SwFlyFrameFormat* pFlyFrameFormat = pFlyFrame->GetFormat();
117  const OUString& rDesc = pFlyFrameFormat->GetObjDescription();
118  msDesc = rDesc;
119  if ( msDesc.isEmpty() &&
120  msTitle != GetName() )
121  {
122  msDesc = msTitle;
123  }
124 
125  if ( msDesc != sOldDesc )
126  {
127  AccessibleEventObject aEvent;
128  aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
129  aEvent.OldValue <<= sOldDesc;
130  aEvent.NewValue <<= msDesc;
131  FireAccessibleEvent( aEvent );
132  }
133  }
134  }
135  break;
136  }
137 }
138 
139 // XInterface
140 
141 css::uno::Any SAL_CALL
142  SwAccessibleTextFrame::queryInterface (const css::uno::Type & rType)
143 {
144  css::uno::Any aReturn = SwAccessibleContext::queryInterface (rType);
145  if ( ! aReturn.hasValue())
146  aReturn = ::cppu::queryInterface (rType,
147  static_cast< css::accessibility::XAccessibleSelection* >(this)
148  );
149  return aReturn;
150 }
151 
152 void SAL_CALL
154  throw ()
155 {
156  SwAccessibleContext::acquire ();
157 }
158 
159 void SAL_CALL
161  throw ()
162 {
163  SwAccessibleContext::release ();
164 }
165 
166 // XAccessibleSelection
167 
169 {
170  SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::selectAccessibleChild( sal_Int32 )> - missing implementation");
171 }
172 
174 {
175  SolarMutexGuard g;
176 
177  uno::Reference<XAccessible> xAcc = getAccessibleChild( nChildIndex );
178  uno::Reference<XAccessibleContext> xContext;
179  if( xAcc.is() )
180  xContext = xAcc->getAccessibleContext();
181 
182  if( xContext.is() )
183  {
184  if( xContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
185  {
186  uno::Reference< css::accessibility::XAccessibleText >
187  xText(xAcc, uno::UNO_QUERY);
188  if( xText.is() )
189  {
190  if( xText->getSelectionStart() >= 0 ) return true;
191  }
192  }
193  }
194 
195  return false;
196 }
197 
199 {
200  SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::clearAccessibleSelection()> - missing implementation");
201 }
202 
204 {
205  SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::selectAllAccessibleChildren()> - missing implementation");
206 }
207 
209 {
210  sal_Int32 nCount = 0;
211  sal_Int32 TotalCount = getAccessibleChildCount();
212  for( sal_Int32 i = 0; i < TotalCount; i++ )
213  if( isAccessibleChildSelected(i) ) nCount++;
214 
215  return nCount;
216 }
217 
218 uno::Reference<XAccessible> SAL_CALL SwAccessibleTextFrame::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
219 {
220  SolarMutexGuard g;
221 
222  if ( nSelectedChildIndex > getSelectedAccessibleChildCount() )
223  throw lang::IndexOutOfBoundsException();
224  sal_Int32 i1, i2;
225  for( i1 = 0, i2 = 0; i1 < getAccessibleChildCount(); i1++ )
226  if( isAccessibleChildSelected(i1) )
227  {
228  if( i2 == nSelectedChildIndex )
229  return getAccessibleChild( i1 );
230  i2++;
231  }
232  return uno::Reference<XAccessible>();
233 }
234 
236 {
237  SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::selectAllAccessibleChildren( sal_Int32 )> - missing implementation");
238 }
239 
240 // #i73249#
242 {
243  SolarMutexGuard aGuard;
244 
245  ThrowIfDisposed();
246 
247  if ( !msTitle.isEmpty() )
248  {
249  return msTitle;
250  }
251 
253 }
254 
256 {
257  SolarMutexGuard aGuard;
258 
259  ThrowIfDisposed();
260 
261  return msDesc;
262 
263 }
264 
266 {
267  return "com.sun.star.comp.Writer.SwAccessibleTextFrameView";
268 }
269 
270 sal_Bool SAL_CALL SwAccessibleTextFrame::supportsService(const OUString& sTestServiceName)
271 {
272  return cppu::supportsService(this, sTestServiceName);
273 }
274 
275 uno::Sequence< OUString > SAL_CALL SwAccessibleTextFrame::getSupportedServiceNames()
276 {
277  return { "com.sun.star.text.AccessibleTextFrameView", sAccessibleServiceName };
278 }
279 
280 uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleTextFrame::getImplementationId()
281 {
282  return css::uno::Sequence<sal_Int8>();
283 }
284 
285 // XAccessibleRelationSet
286 
288 {
289  SwFlyFrame* pFlyFrame = nullptr;
290 
291  const SwFrame* pFrame = GetFrame();
292  assert(pFrame);
293  if( pFrame->IsFlyFrame() )
294  {
295  pFlyFrame = static_cast<SwFlyFrame*>( const_cast<SwFrame*>( pFrame ) );
296  }
297 
298  return pFlyFrame;
299 }
300 
301 AccessibleRelation SwAccessibleTextFrame::makeRelation( sal_Int16 nType, const SwFlyFrame* pFrame )
302 {
303  uno::Sequence<uno::Reference<XInterface> > aSequence { GetMap()->GetContext( pFrame ) };
304  return AccessibleRelation( nType, aSequence );
305 }
306 
307 uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleTextFrame::getAccessibleRelationSet( )
308 {
309  SolarMutexGuard aGuard;
310 
311  ThrowIfDisposed();
312 
313  // get the frame, and insert prev/next relations into helper
314 
316 
317  SwFlyFrame* pFlyFrame = getFlyFrame();
318  assert(pFlyFrame);
319 
320  const SwFlyFrame* pPrevFrame = pFlyFrame->GetPrevLink();
321  if( pPrevFrame != nullptr )
322  pHelper->AddRelation( makeRelation(
323  AccessibleRelationType::CONTENT_FLOWS_FROM, pPrevFrame ) );
324 
325  const SwFlyFrame* pNextFrame = pFlyFrame->GetNextLink();
326  if( pNextFrame != nullptr )
327  pHelper->AddRelation( makeRelation(
328  AccessibleRelationType::CONTENT_FLOWS_TO, pNextFrame ) );
329 
330  return pHelper;
331 }
332 
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class of the Writer layout elements.
Definition: frame.hxx:295
void FireAccessibleEvent(css::accessibility::AccessibleEventObject &rEvent)
Definition: acccontext.cxx:443
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:2816
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
OUString GetObjDescription() const
Definition: atrfrm.cxx:3138
virtual void SAL_CALL deselectAccessibleChild(sal_Int32 nSelectedChildIndex) override
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
virtual sal_Int32 SAL_CALL getAccessibleChildCount() override
Definition: acccontext.cxx:569
const sal_Char sAccessibleServiceName[]
Definition: acccontext.hxx:43
virtual void SAL_CALL selectAllAccessibleChildren() override
SwAccessibleTextFrame(std::shared_ptr< SwAccessibleMap > const &pInitMap, const SwFlyFrame &rFlyFrame)
virtual sal_Bool SAL_CALL isAccessibleChildSelected(sal_Int32 nChildIndex) override
virtual void SAL_CALL clearAccessibleSelection() override
bool IsFlyFrame() const
Definition: frame.hxx:1186
const SwFrame * GetFrame() const
Definition: accframe.hxx:103
SwFlyFrame * GetPrevLink() const
Definition: flyfrm.hxx:172
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void AddRelation(const css::accessibility::AccessibleRelation &rRelation)
OUString GetObjTitle() const
Definition: atrfrm.cxx:3101
css::accessibility::AccessibleRelation makeRelation(sal_Int16 nType, const SwFlyFrame *pFrame)
const OUString & GetString() const
Definition: hints.hxx:293
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
Return whether the specified service is supported by this class.
#define RES_TITLE_CHANGED
Definition: hintids.hxx:311
const OUString & GetName() const
Definition: acccontext.hxx:333
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex) override
int i
unsigned char sal_Bool
virtual void SAL_CALL selectAccessibleChild(sal_Int32 nChildIndex) override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int32 nIndex) override
Definition: acccontext.cxx:579
#define RES_DESCRIPTION_CHANGED
Definition: hintids.hxx:312
virtual OUString SAL_CALL getAccessibleName() override
virtual OUString SAL_CALL getAccessibleName() override
Definition: acccontext.cxx:680
virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount() override
general base class for all free-flowing frames
Definition: flyfrm.hxx:60
virtual void SAL_CALL release() override
virtual ~SwAccessibleTextFrame() override
#define RES_NAME_CHANGED
Definition: hintids.hxx:310
SwFlyFrame * GetNextLink() const
Definition: flyfrm.hxx:173
css::uno::Reference< css::accessibility::XAccessible > GetContext(const SwFrame *pFrame, bool bCreate=true)
Definition: accmap.cxx:1810
SwAccessibleMap * GetMap()
Definition: acccontext.hxx:112
SwFlyFrame * getFlyFrame() const
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
#define SAL_WARN(area, stream)
virtual void SAL_CALL acquire() override
virtual OUString SAL_CALL getImplementationName() override
Returns an identifier for the implementation of this object.
sal_uInt16 Which() const
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
virtual OUString SAL_CALL getAccessibleDescription() override
Return this object's description.