LibreOffice Module sw (master)  1
accfrmobj.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 "accfrmobj.hxx"
21 
22 #include <accmap.hxx>
23 #include "acccontext.hxx"
24 
25 #include <viewsh.hxx>
26 #include <rootfrm.hxx>
27 #include <flyfrm.hxx>
28 #include <pagefrm.hxx>
29 #include <cellfrm.hxx>
30 #include <swtable.hxx>
31 #include <dflyobj.hxx>
32 #include <frmfmt.hxx>
33 #include <fmtanchr.hxx>
34 #include <dcontact.hxx>
35 
36 #include <pam.hxx>
37 
38 #include <vcl/window.hxx>
39 
40 namespace sw { namespace access {
41 
43  : mpFrame( nullptr )
44  , mpDrawObj( nullptr )
45  , mpWindow( nullptr )
46 {}
47 
49  : mpFrame( nullptr )
50  , mpDrawObj( nullptr )
51  , mpWindow( nullptr )
52 {
53  Init( pDrawObj );
54 }
55 
57  : mpFrame( nullptr )
58  , mpDrawObj( nullptr )
59  , mpWindow( nullptr )
60 {
61  Init( pFrame );
62 }
63 
65  : mpFrame( nullptr )
66  , mpDrawObj( nullptr )
67  , mpWindow( nullptr )
68 {
69  Init( pWindow );
70 }
71 
73  const SdrObject* pDrawObj,
74  vcl::Window* pWindow )
75  : mpFrame( nullptr )
76  , mpDrawObj( nullptr )
77  , mpWindow( nullptr )
78 {
79  if ( pFrame )
80  {
81  Init( pFrame );
82  }
83  else if ( pDrawObj )
84  {
85  Init( pDrawObj );
86  }
87  else if ( pWindow )
88  {
89  Init( pWindow );
90  }
91  OSL_ENSURE( (!pFrame || pFrame == mpFrame) &&
92  (!pDrawObj || pDrawObj == mpDrawObj) &&
93  (!pWindow || pWindow == mpWindow),
94  "invalid frame/object/window combination" );
95 
96 }
97 
99 
100 void SwAccessibleChild::Init( const SdrObject* pDrawObj )
101 {
102  mpDrawObj = pDrawObj;
103  const SwVirtFlyDrawObj* pFlyDrawObj = dynamic_cast<const SwVirtFlyDrawObj*>(mpDrawObj);
104  mpFrame = pFlyDrawObj ? pFlyDrawObj->GetFlyFrame() : nullptr;
105  mpWindow = nullptr;
106 }
107 
108 void SwAccessibleChild::Init( const SwFrame* pFrame )
109 {
110  mpFrame = pFrame;
112  ? static_cast < const SwFlyFrame * >( mpFrame )->GetVirtDrawObj()
113  : nullptr;
114  mpWindow = nullptr;
115 }
116 
118 {
119  mpWindow = pWindow;
120  mpFrame = nullptr;
121  mpDrawObj = nullptr;
122 }
123 
124 bool SwAccessibleChild::IsAccessible( bool bPagePreview ) const
125 {
126  bool bRet( false );
127 
128  if ( mpFrame )
129  {
130  bRet = mpFrame->IsAccessibleFrame() &&
131  ( !mpFrame->IsCellFrame() ||
132  static_cast<const SwCellFrame *>( mpFrame )->GetTabBox()->GetSttNd() != nullptr ) &&
133  !mpFrame->IsInCoveredCell() &&
134  ( bPagePreview ||
135  !mpFrame->IsPageFrame() );
136  }
137  else if ( mpDrawObj )
138  {
139  bRet = true;
140  }
141  else if ( mpWindow )
142  {
143  bRet = true;
144  }
145 
146  return bRet;
147 }
148 
150 {
151  bool bRet( false );
152 
153  if ( mpFrame )
154  {
155  bRet = mpFrame->IsFlyFrame() &&
156  static_cast< const SwFlyFrame *>(mpFrame)->IsFlyInContentFrame();
157  }
158  else if ( mpDrawObj )
159  {
160  const SwFrameFormat* pFrameFormat = ::FindFrameFormat( mpDrawObj );
161  bRet = pFrameFormat
162  && (RndStdIds::FLY_AS_CHAR == pFrameFormat->GetAnchor().GetAnchorId());
163  }
164  else if ( mpWindow )
165  {
166  bRet = false;
167  }
168 
169  return bRet;
170 }
171 
173 {
174  Init( pDrawObj );
175  return *this;
176 }
177 
179 {
180  Init( pFrame );
181  return *this;
182 }
183 
185 {
186  Init( pWindow );
187  return *this;
188 }
189 
191 {
192  return mpFrame == r.mpFrame &&
193  mpDrawObj == r.mpDrawObj &&
194  mpWindow == r.mpWindow;
195 }
196 
198 {
199  return mpFrame != nullptr ||
200  mpDrawObj != nullptr ||
201  mpWindow != nullptr;
202 }
203 
205 {
206  bool bRet( false );
207 
208  if ( !mpFrame )
209  {
210  bRet = true;
211  }
212  else
213  {
214  bRet = mpFrame->IsRootFrame() ||
215  !( mpFrame->IsTabFrame() ||
216  mpFrame->IsInTab() ||
217  ( IsBoundAsChar() &&
218  static_cast<const SwFlyFrame*>(mpFrame)->GetAnchorFrame()->IsInTab() ) );
219  }
220 
221  return bRet;
222 }
223 
225 {
226  SwRect aBox;
227 
228  if ( mpFrame )
229  {
230  if ( mpFrame->IsPageFrame() &&
231  static_cast< const SwPageFrame * >( mpFrame )->IsEmptyPage() )
232  {
233  aBox = SwRect( mpFrame->getFrameArea().Left(), mpFrame->getFrameArea().Top()-1, 1, 1 );
234  }
235  else if ( mpFrame->IsTabFrame() )
236  {
237  aBox = mpFrame->getFrameArea();
239  }
240  else
241  {
242  aBox = mpFrame->getFrameArea();
243  }
244  }
245  else if( mpDrawObj )
246  {
247  const SwContact* const pContact = ::GetUserCall(mpDrawObj);
248  // assume that a) the SwVirt* objects that don't have this are handled
249  // by the mpFrame case above b) for genuine SdrObject this must be set
250  // if it's connected to layout
251  assert(dynamic_cast<SwDrawContact const*>(pContact));
252  SwPageFrame const*const pPage(const_cast<SwAnchoredObject *>(
253  pContact->GetAnchoredObj(mpDrawObj))->FindPageFrameOfAnchor());
254  if (pPage) // may end up here with partial layout -> not visible
255  {
256  aBox = SwRect( mpDrawObj->GetCurrentBoundRect() );
257  // tdf#91260 drawing object may be partially off-page
258  aBox.Intersection(pPage->getFrameArea());
259  }
260  }
261  else if ( mpWindow )
262  {
263  vcl::Window *pWin = rAccMap.GetShell()->GetWin();
264  if (pWin)
265  {
266  aBox = SwRect( pWin->PixelToLogic(
268  mpWindow->GetSizePixel() ) ) );
269  }
270  }
271 
272  return aBox;
273 }
274 
276 {
277  SwRect aBound;
278 
279  if( mpFrame )
280  {
281  if( mpFrame->IsPageFrame() &&
282  static_cast< const SwPageFrame * >( mpFrame )->IsEmptyPage() )
283  {
284  aBound = SwRect( mpFrame->getFrameArea().Left(), mpFrame->getFrameArea().Top()-1, 0, 0 );
285  }
286  else
287  aBound = mpFrame->GetPaintArea();
288  }
289  else if( mpDrawObj )
290  {
291  aBound = GetBox( rAccMap );
292  }
293  else if ( mpWindow )
294  {
295  aBound = GetBox( rAccMap );
296  }
297 
298  return aBound;
299 }
300 
302 {
303  bool bAlwaysIncludedAsChild( false );
304 
305  if ( mpWindow )
306  {
307  bAlwaysIncludedAsChild = true;
308  }
309 
310  return bAlwaysIncludedAsChild;
311 }
312 
313 const SwFrame* SwAccessibleChild::GetParent( const bool bInPagePreview ) const
314 {
315  const SwFrame* pParent( nullptr );
316 
317  if ( mpFrame )
318  {
319  if( mpFrame->IsFlyFrame() )
320  {
321  const SwFlyFrame* pFly = static_cast< const SwFlyFrame *>( mpFrame );
322  if( pFly->IsFlyInContentFrame() )
323  {
324  // For RndStdIds::FLY_AS_CHAR the parent is the anchor
325  pParent = pFly->GetAnchorFrame();
326  OSL_ENSURE( SwAccessibleChild( pParent ).IsAccessible( bInPagePreview ),
327  "parent is not accessible" );
328  }
329  else
330  {
331  // In any other case the parent is the root frm
332  // (in page preview, the page frame)
333  if( bInPagePreview )
334  pParent = pFly->FindPageFrame();
335  else
336  pParent = pFly->getRootFrame();
337  }
338  }
339  else
340  {
341  SwAccessibleChild aUpper( mpFrame->GetUpper() );
342  while( aUpper.GetSwFrame() && !aUpper.IsAccessible(bInPagePreview) )
343  {
344  aUpper = aUpper.GetSwFrame()->GetUpper();
345  }
346  pParent = aUpper.GetSwFrame();
347  }
348  }
349  else if( mpDrawObj )
350  {
351  const SwDrawContact *pContact =
352  static_cast< const SwDrawContact* >( GetUserCall( mpDrawObj ) );
353  OSL_ENSURE( pContact, "sdr contact is missing" );
354  if( pContact )
355  {
356  const SwFrameFormat *pFrameFormat = pContact->GetFormat();
357  OSL_ENSURE( pFrameFormat, "frame format is missing" );
358  if( pFrameFormat && RndStdIds::FLY_AS_CHAR == pFrameFormat->GetAnchor().GetAnchorId() )
359  {
360  // For RndStdIds::FLY_AS_CHAR the parent is the anchor
361  pParent = pContact->GetAnchorFrame();
362  OSL_ENSURE( SwAccessibleChild( pParent ).IsAccessible( bInPagePreview ),
363  "parent is not accessible" );
364 
365  }
366  else
367  {
368  // In any other case the parent is the root frm
369  SwFrame const*const pAnchor(pContact->GetAnchorFrame());
370  if (pAnchor) // null if object removed from layout
371  {
372  if (bInPagePreview)
373  pParent = pAnchor->FindPageFrame();
374  else
375  pParent = pAnchor->getRootFrame();
376  }
377  }
378  }
379  }
380  else if ( mpWindow )
381  {
382  css::uno::Reference < css::accessibility::XAccessible > xAcc =
384  if ( xAcc.is() )
385  {
386  css::uno::Reference < css::accessibility::XAccessibleContext > xAccContext =
387  xAcc->getAccessibleContext();
388  if ( xAccContext.is() )
389  {
390  css::uno::Reference < css::accessibility::XAccessible > xAccParent =
391  xAccContext->getAccessibleParent();
392  if ( xAccParent.is() )
393  {
394  SwAccessibleContext* pAccParentImpl =
395  dynamic_cast< SwAccessibleContext *>( xAccParent.get() );
396  if ( pAccParentImpl )
397  {
398  pParent = pAccParentImpl->GetFrame();
399  }
400  }
401  }
402  }
403  }
404 
405  return pParent;
406 }
407 
408 } } // eof of namespace sw::access
409 
410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Point GetPosPixel() const
Base class for the following contact objects (frame + draw objects).
Definition: dcontact.hxx:66
Base class of the Writer layout elements.
Definition: frame.hxx:295
SwAccessibleChild & operator=(SwAccessibleChild const &)=default
const SdrObject * mpDrawObj
Definition: accfrmobj.hxx:77
virtual const tools::Rectangle & GetCurrentBoundRect() const
bool IsRootFrame() const
Definition: frame.hxx:1150
VclPtr< vcl::Window > mpWindow
Definition: accfrmobj.hxx:78
SwRect GetBounds(const SwAccessibleMap &rAccMap) const
Definition: accfrmobj.cxx:275
virtual Size GetSizePixel() const
Dialog to specify the properties of drop-down form field.
Definition: accfrmobj.cxx:40
bool IsCellFrame() const
Definition: frame.hxx:1202
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
SwContact * GetUserCall(const SdrObject *pObj)
Returns the UserCall if applicable from the group object.
Definition: dcontact.cxx:176
bool IsInCoveredCell() const
Definition: tabfrm.cxx:5707
bool IsFlyFrame() const
Definition: frame.hxx:1186
SwViewShell * GetShell() const
Definition: accmap.hxx:169
void Top(const long nTop)
Definition: swrect.hxx:202
const SwFrame * GetAnchorFrame(const SdrObject *_pDrawObj=nullptr) const
Definition: dcontact.cxx:787
const SwFrame * GetFrame() const
Definition: accframe.hxx:103
const SwRect & getFrameArea() const
Definition: frame.hxx:175
css::uno::Reference< css::accessibility::XAccessible > GetAccessible(bool bCreate=true)
bool IsInTab() const
Definition: frame.hxx:931
SwRect & Intersection(const SwRect &rRect)
Definition: swrect.cxx:57
bool operator==(const SwAccessibleChild &r) const
Definition: accfrmobj.cxx:190
SwFrameFormat * FindFrameFormat(SdrObject *pObj)
The Get reverse way: seeks the format to the specified object.
Definition: dcontact.cxx:125
bool IsVisibleChildrenOnly() const
Definition: accfrmobj.cxx:204
bool IsFlyInContentFrame() const
Definition: flyfrm.hxx:193
const SwRect GetPaintArea() const
|* The paintarea is the area, in which the content of a frame is allowed |* to be displayed...
Definition: ssfrm.cxx:619
const SwFrame * GetSwFrame() const
Definition: accfrmobj.hxx:58
VclPtr< vcl::Window > mpWindow
Style of a layout element.
Definition: frmfmt.hxx:57
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:81
SwFrameFormat * GetFormat()
Definition: dcontact.hxx:112
RndStdIds GetAnchorId() const
Definition: fmtanchr.hxx:65
void Init(const SdrObject *pDrawObj)
Definition: accfrmobj.cxx:100
const SwFrame * GetParent(const bool bInPagePreview) const
Definition: accfrmobj.cxx:313
SwPageFrame * FindPageFrame()
Definition: frame.hxx:658
SwLayoutFrame * GetUpper()
Definition: frame.hxx:656
bool AlwaysIncludeAsChild() const
indicating, if accessible child is included even, if the corresponding object is not visible...
Definition: accfrmobj.cxx:301
virtual const SwAnchoredObject * GetAnchoredObj(const SdrObject *_pSdrObj) const =0
A page of the document layout.
Definition: pagefrm.hxx:40
Point PixelToLogic(const Point &rDevicePt) const
void Left(const long nLeft)
Definition: swrect.hxx:193
SwFlyFrame * GetFlyFrame()
Definition: dflyobj.hxx:127
bool IsTabFrame() const
Definition: frame.hxx:1194
general base class for all free-flowing frames
Definition: flyfrm.hxx:60
vcl::Window * GetWin() const
Definition: viewsh.hxx:340
bool IsAccessible(bool bPagePreview) const
Definition: accfrmobj.cxx:124
bool IsPageFrame() const
Definition: frame.hxx:1154
bool IsAccessibleFrame() const
Definition: frame.hxx:1226
SwRect GetBox(const SwAccessibleMap &rAccMap) const
Definition: accfrmobj.cxx:224
const SwFrame * GetAnchorFrame() const
SwRootFrame * getRootFrame()
Definition: frame.hxx:657
SwCellFrame is one table cell in the document layout.
Definition: cellfrm.hxx:30