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