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>
31 #include <frmfmt.hxx>
32 #include <flyfrm.hxx>
33 #include <accmap.hxx>
35 #include <hints.hxx>
36 #include "acctextframe.hxx"
37 
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::accessibility;
40 
42 using ::com::sun::star::accessibility::XAccessibleContext;
43 
45  std::shared_ptr<SwAccessibleMap> const& pInitMap,
46  const SwFlyFrame& rFlyFrame ) :
47  SwAccessibleFrameBase( pInitMap, AccessibleRole::TEXT_FRAME, &rFlyFrame ),
48  msTitle(),
49  msDesc()
50 {
51  const SwFlyFrameFormat* pFlyFrameFormat = rFlyFrame.GetFormat();
52  msTitle = pFlyFrameFormat->GetObjTitle();
53 
54  msDesc = pFlyFrameFormat->GetObjDescription();
55  if ( msDesc.isEmpty() &&
56  msTitle != GetName() )
57  {
58  msDesc = msTitle;
59  }
60 }
61 
63 {
64 }
65 
67 {
68  if(rHint.GetId() == SfxHintId::Dying)
70  else if(auto pLegacyModifyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
71  {
72  const sal_uInt16 nWhich = pLegacyModifyHint->m_pOld ? pLegacyModifyHint->m_pOld->Which() : pLegacyModifyHint->m_pNew ? pLegacyModifyHint->m_pNew->Which() : 0;
73  const SwFlyFrame* pFlyFrame = static_cast<const SwFlyFrame*>(GetFrame());
74  switch(nWhich)
75  {
76  // #i73249#
77  case RES_TITLE_CHANGED:
78  {
79  OUString sOldTitle, sNewTitle;
80  const SwStringMsgPoolItem *pOldItem = dynamic_cast<const SwStringMsgPoolItem*>(pLegacyModifyHint->m_pOld);
81  if(pOldItem)
82  sOldTitle = pOldItem->GetString();
83  const SwStringMsgPoolItem *pNewItem = dynamic_cast<const SwStringMsgPoolItem*>(pLegacyModifyHint->m_pNew);
84  if(pNewItem)
85  sNewTitle = pNewItem->GetString();
86  if(sOldTitle == sNewTitle)
87  break;
88  msTitle = sNewTitle;
89  AccessibleEventObject aEvent;
90  aEvent.EventId = AccessibleEventId::NAME_CHANGED;
91  aEvent.OldValue <<= sOldTitle;
92  aEvent.NewValue <<= msTitle;
93  FireAccessibleEvent( aEvent );
94 
95  const SwFlyFrameFormat* pFlyFrameFormat = pFlyFrame->GetFormat();
96  if(!pFlyFrameFormat || !pFlyFrameFormat->GetObjDescription().isEmpty())
97  break;
98  [[fallthrough]];
99  }
101  {
102  if(pFlyFrame)
103  {
104  const OUString sOldDesc(msDesc);
105 
106  const SwFlyFrameFormat* pFlyFrameFormat = pFlyFrame->GetFormat();
107  const OUString& rDesc = pFlyFrameFormat->GetObjDescription();
108  msDesc = rDesc;
109  if(msDesc.isEmpty() && msTitle != GetName())
110  msDesc = msTitle;
111 
112  if(msDesc != sOldDesc)
113  {
114  AccessibleEventObject aEvent;
115  aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
116  aEvent.OldValue <<= sOldDesc;
117  aEvent.NewValue <<= msDesc;
118  FireAccessibleEvent(aEvent);
119  }
120  }
121  }
122  }
123  }
124 }
125 
126 // XInterface
127 
128 css::uno::Any SAL_CALL
129  SwAccessibleTextFrame::queryInterface (const css::uno::Type & rType)
130 {
131  css::uno::Any aReturn = SwAccessibleContext::queryInterface (rType);
132  if ( ! aReturn.hasValue())
133  aReturn = ::cppu::queryInterface (rType,
134  static_cast< css::accessibility::XAccessibleSelection* >(this)
135  );
136  return aReturn;
137 }
138 
139 void SAL_CALL
141  throw ()
142 {
143  SwAccessibleContext::acquire ();
144 }
145 
146 void SAL_CALL
148  throw ()
149 {
150  SwAccessibleContext::release ();
151 }
152 
153 // XAccessibleSelection
154 
156 {
157  SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::selectAccessibleChild( sal_Int32 )> - missing implementation");
158 }
159 
161 {
162  SolarMutexGuard g;
163 
164  uno::Reference<XAccessible> xAcc = getAccessibleChild( nChildIndex );
165  uno::Reference<XAccessibleContext> xContext;
166  if( xAcc.is() )
167  xContext = xAcc->getAccessibleContext();
168 
169  if( xContext.is() )
170  {
171  if( xContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
172  {
173  uno::Reference< css::accessibility::XAccessibleText >
174  xText(xAcc, uno::UNO_QUERY);
175  if( xText.is() )
176  {
177  if( xText->getSelectionStart() >= 0 ) return true;
178  }
179  }
180  }
181 
182  return false;
183 }
184 
186 {
187  SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::clearAccessibleSelection()> - missing implementation");
188 }
189 
191 {
192  SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::selectAllAccessibleChildren()> - missing implementation");
193 }
194 
196 {
197  sal_Int32 nCount = 0;
198  sal_Int32 TotalCount = getAccessibleChildCount();
199  for( sal_Int32 i = 0; i < TotalCount; i++ )
200  if( isAccessibleChildSelected(i) ) nCount++;
201 
202  return nCount;
203 }
204 
205 uno::Reference<XAccessible> SAL_CALL SwAccessibleTextFrame::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
206 {
207  SolarMutexGuard g;
208 
209  if ( nSelectedChildIndex > getSelectedAccessibleChildCount() )
210  throw lang::IndexOutOfBoundsException();
211  sal_Int32 i1, i2;
212  for( i1 = 0, i2 = 0; i1 < getAccessibleChildCount(); i1++ )
213  if( isAccessibleChildSelected(i1) )
214  {
215  if( i2 == nSelectedChildIndex )
216  return getAccessibleChild( i1 );
217  i2++;
218  }
219  return uno::Reference<XAccessible>();
220 }
221 
223 {
224  SAL_WARN("sw.a11y", "<SwAccessibleTextFrame::selectAllAccessibleChildren( sal_Int32 )> - missing implementation");
225 }
226 
227 // #i73249#
229 {
230  SolarMutexGuard aGuard;
231 
232  ThrowIfDisposed();
233 
234  if ( !msTitle.isEmpty() )
235  {
236  return msTitle;
237  }
238 
240 }
241 
243 {
244  SolarMutexGuard aGuard;
245 
246  ThrowIfDisposed();
247 
248  return msDesc;
249 
250 }
251 
253 {
254  return "com.sun.star.comp.Writer.SwAccessibleTextFrameView";
255 }
256 
257 sal_Bool SAL_CALL SwAccessibleTextFrame::supportsService(const OUString& sTestServiceName)
258 {
259  return cppu::supportsService(this, sTestServiceName);
260 }
261 
262 uno::Sequence< OUString > SAL_CALL SwAccessibleTextFrame::getSupportedServiceNames()
263 {
264  return { "com.sun.star.text.AccessibleTextFrameView", sAccessibleServiceName };
265 }
266 
267 uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleTextFrame::getImplementationId()
268 {
269  return css::uno::Sequence<sal_Int8>();
270 }
271 
272 // XAccessibleRelationSet
273 
275 {
276  SwFlyFrame* pFlyFrame = nullptr;
277 
278  const SwFrame* pFrame = GetFrame();
279  assert(pFrame);
280  if( pFrame->IsFlyFrame() )
281  {
282  pFlyFrame = static_cast<SwFlyFrame*>( const_cast<SwFrame*>( pFrame ) );
283  }
284 
285  return pFlyFrame;
286 }
287 
288 AccessibleRelation SwAccessibleTextFrame::makeRelation( sal_Int16 nType, const SwFlyFrame* pFrame )
289 {
290  uno::Sequence<uno::Reference<XInterface> > aSequence { GetMap()->GetContext( pFrame ) };
291  return AccessibleRelation( nType, aSequence );
292 }
293 
294 uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleTextFrame::getAccessibleRelationSet( )
295 {
296  SolarMutexGuard aGuard;
297 
298  ThrowIfDisposed();
299 
300  // get the frame, and insert prev/next relations into helper
301 
303 
304  SwFlyFrame* pFlyFrame = getFlyFrame();
305  assert(pFlyFrame);
306 
307  const SwFlyFrame* pPrevFrame = pFlyFrame->GetPrevLink();
308  if( pPrevFrame != nullptr )
309  pHelper->AddRelation( makeRelation(
310  AccessibleRelationType::CONTENT_FLOWS_FROM, pPrevFrame ) );
311 
312  const SwFlyFrame* pNextFrame = pFlyFrame->GetNextLink();
313  if( pNextFrame != nullptr )
314  pHelper->AddRelation( makeRelation(
315  AccessibleRelationType::CONTENT_FLOWS_TO, pNextFrame ) );
316 
317  return pHelper;
318 }
319 
320 /* 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:440
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:2814
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
OUString GetObjDescription() const
Definition: atrfrm.cxx:3160
virtual void SAL_CALL deselectAccessibleChild(sal_Int32 nSelectedChildIndex) override
virtual sal_Int32 SAL_CALL getAccessibleChildCount() override
Definition: acccontext.cxx:566
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
SfxHintId GetId() const
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:3123
css::accessibility::AccessibleRelation makeRelation(sal_Int16 nType, const SwFlyFrame *pFrame)
const OUString & GetString() const
Definition: hints.hxx:293
void EndListeningAll()
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:312
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:576
#define RES_DESCRIPTION_CHANGED
Definition: hintids.hxx:313
virtual OUString SAL_CALL getAccessibleName() override
virtual OUString SAL_CALL getAccessibleName() override
Definition: acccontext.cxx:677
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
SwFlyFrame * GetNextLink() const
Definition: flyfrm.hxx:173
css::uno::Reference< css::accessibility::XAccessible > GetContext(const SwFrame *pFrame, bool bCreate=true)
Definition: accmap.cxx:1848
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.
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
virtual OUString SAL_CALL getAccessibleDescription() override
Return this object's description.
virtual void Notify(const SfxHint &) override