android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / access / accfrmobj.cxx
blobd8e78836b2a1f486fc7b5b5e5962b7a773998f4b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "accfrmobj.hxx"
22 #include <accmap.hxx>
23 #include "acccontext.hxx"
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>
36 #include <vcl/window.hxx>
38 namespace sw::access {
40 SwAccessibleChild::SwAccessibleChild()
41 : mpFrame( nullptr )
42 , mpDrawObj( nullptr )
43 , mpWindow( nullptr )
46 SwAccessibleChild::SwAccessibleChild( const SdrObject* pDrawObj )
47 : mpFrame( nullptr )
48 , mpDrawObj( nullptr )
49 , mpWindow( nullptr )
51 Init( pDrawObj );
54 SwAccessibleChild::SwAccessibleChild( const SwFrame* pFrame )
55 : mpFrame( nullptr )
56 , mpDrawObj( nullptr )
57 , mpWindow( nullptr )
59 Init( pFrame );
62 SwAccessibleChild::SwAccessibleChild( vcl::Window* pWindow )
63 : mpFrame( nullptr )
64 , mpDrawObj( nullptr )
65 , mpWindow( nullptr )
67 Init( pWindow );
70 SwAccessibleChild::SwAccessibleChild( const SwFrame* pFrame,
71 const SdrObject* pDrawObj,
72 vcl::Window* pWindow )
73 : mpFrame( nullptr )
74 , mpDrawObj( nullptr )
75 , mpWindow( nullptr )
77 if ( pFrame )
79 Init( pFrame );
81 else if ( pDrawObj )
83 Init( pDrawObj );
85 else if ( pWindow )
87 Init( pWindow );
89 OSL_ENSURE( (!pFrame || pFrame == mpFrame) &&
90 (!pDrawObj || pDrawObj == mpDrawObj) &&
91 (!pWindow || pWindow == mpWindow),
92 "invalid frame/object/window combination" );
96 SwAccessibleChild::~SwAccessibleChild() = default;
98 void SwAccessibleChild::Init( const SdrObject* pDrawObj )
100 mpDrawObj = pDrawObj;
101 const SwVirtFlyDrawObj* pFlyDrawObj = dynamic_cast<const SwVirtFlyDrawObj*>(mpDrawObj);
102 mpFrame = pFlyDrawObj ? pFlyDrawObj->GetFlyFrame() : nullptr;
103 mpWindow = nullptr;
106 void SwAccessibleChild::Init( const SwFrame* pFrame )
108 mpFrame = pFrame;
109 mpDrawObj = nullptr;
110 mpWindow = nullptr;
113 void SwAccessibleChild::Init( vcl::Window* pWindow )
115 mpWindow = pWindow;
116 mpFrame = nullptr;
117 mpDrawObj = nullptr;
120 bool SwAccessibleChild::IsAccessible( bool bPagePreview ) const
122 bool bRet( false );
124 if ( mpFrame )
126 bRet = mpFrame->IsAccessibleFrame() &&
127 ( !mpFrame->IsCellFrame() ||
128 static_cast<const SwCellFrame *>( mpFrame )->GetTabBox()->GetSttNd() != nullptr ) &&
129 !mpFrame->IsInCoveredCell() &&
130 ( bPagePreview ||
131 !mpFrame->IsPageFrame() );
133 else if ( mpDrawObj )
135 bRet = true;
137 else if ( mpWindow )
139 bRet = true;
142 return bRet;
145 bool SwAccessibleChild::IsBoundAsChar() const
147 bool bRet( false );
149 if ( mpFrame )
151 bRet = mpFrame->IsFlyFrame() &&
152 static_cast< const SwFlyFrame *>(mpFrame)->IsFlyInContentFrame();
154 else if ( mpDrawObj )
156 const SwFrameFormat* pFrameFormat = ::FindFrameFormat( mpDrawObj );
157 bRet = pFrameFormat
158 && (RndStdIds::FLY_AS_CHAR == pFrameFormat->GetAnchor().GetAnchorId());
160 else if ( mpWindow )
162 bRet = false;
165 return bRet;
168 SwAccessibleChild& SwAccessibleChild::operator=( const SdrObject* pDrawObj )
170 Init( pDrawObj );
171 return *this;
174 SwAccessibleChild& SwAccessibleChild::operator=( const SwFrame* pFrame )
176 Init( pFrame );
177 return *this;
180 SwAccessibleChild& SwAccessibleChild::operator=( vcl::Window* pWindow )
182 Init( pWindow );
183 return *this;
186 bool SwAccessibleChild::IsValid() const
188 return mpFrame != nullptr ||
189 mpDrawObj != nullptr ||
190 mpWindow != nullptr;
193 bool SwAccessibleChild::IsVisibleChildrenOnly() const
195 bool bRet( false );
197 if ( !mpFrame )
199 bRet = true;
201 else
203 bRet = mpFrame->IsRootFrame() ||
204 !( mpFrame->IsTabFrame() ||
205 mpFrame->IsInTab() ||
206 ( IsBoundAsChar() &&
207 static_cast<const SwFlyFrame*>(mpFrame)->GetAnchorFrame()->IsInTab() ) );
210 return bRet;
213 SwRect SwAccessibleChild::GetBox( const SwAccessibleMap& rAccMap ) const
215 SwRect aBox;
217 if ( mpFrame )
219 if ( mpFrame->IsPageFrame() &&
220 static_cast< const SwPageFrame * >( mpFrame )->IsEmptyPage() )
222 aBox = SwRect( mpFrame->getFrameArea().Left(), mpFrame->getFrameArea().Top()-1, 1, 1 );
224 else if ( mpFrame->IsTabFrame() )
226 aBox = mpFrame->getFrameArea();
227 aBox.Intersection( mpFrame->GetUpper()->getFrameArea() );
229 else
231 aBox = mpFrame->getFrameArea();
234 else if( mpDrawObj )
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 *>(
242 pContact->GetAnchoredObj(mpDrawObj))->FindPageFrameOfAnchor());
243 if (pPage) // may end up here with partial layout -> not visible
245 aBox = SwRect( mpDrawObj->GetCurrentBoundRect() );
246 // tdf#91260 drawing object may be partially off-page
247 aBox.Intersection(pPage->getFrameArea());
250 else if ( mpWindow )
252 vcl::Window *pWin = rAccMap.GetShell()->GetWin();
253 if (pWin)
255 aBox = SwRect( pWin->PixelToLogic(
256 tools::Rectangle( mpWindow->GetPosPixel(),
257 mpWindow->GetSizePixel() ) ) );
261 return aBox;
264 SwRect SwAccessibleChild::GetBounds( const SwAccessibleMap& rAccMap ) const
266 SwRect aBound;
268 if( mpFrame )
270 if( mpFrame->IsPageFrame() &&
271 static_cast< const SwPageFrame * >( mpFrame )->IsEmptyPage() )
273 aBound = SwRect( mpFrame->getFrameArea().Left(), mpFrame->getFrameArea().Top()-1, 0, 0 );
275 else
276 aBound = mpFrame->GetPaintArea();
278 else if( mpDrawObj )
280 aBound = GetBox( rAccMap );
282 else if ( mpWindow )
284 aBound = GetBox( rAccMap );
287 return aBound;
290 bool SwAccessibleChild::AlwaysIncludeAsChild() const
292 bool bAlwaysIncludedAsChild( false );
294 if ( mpWindow )
296 bAlwaysIncludedAsChild = true;
299 return bAlwaysIncludedAsChild;
302 const SwFrame* SwAccessibleChild::GetParent( const bool bInPagePreview ) const
304 const SwFrame* pParent( nullptr );
306 if ( mpFrame )
308 if( mpFrame->IsFlyFrame() )
310 const SwFlyFrame* pFly = static_cast< const SwFlyFrame *>( mpFrame );
311 if( pFly->IsFlyInContentFrame() )
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" );
318 else
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();
328 else
330 SwAccessibleChild aUpper( mpFrame->GetUpper() );
331 while( aUpper.GetSwFrame() && !aUpper.IsAccessible(bInPagePreview) )
333 aUpper = aUpper.GetSwFrame()->GetUpper();
335 pParent = aUpper.GetSwFrame();
338 else if( mpDrawObj )
340 const SwDrawContact *pContact =
341 static_cast< const SwDrawContact* >( GetUserCall( mpDrawObj ) );
342 OSL_ENSURE( pContact, "sdr contact is missing" );
343 if( pContact )
345 const SwFrameFormat *pFrameFormat = pContact->GetFormat();
346 OSL_ENSURE( pFrameFormat, "frame format is missing" );
347 if( pFrameFormat && RndStdIds::FLY_AS_CHAR == pFrameFormat->GetAnchor().GetAnchorId() )
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" );
355 else
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
361 if (bInPagePreview)
362 pParent = pAnchor->FindPageFrame();
363 else
364 pParent = pAnchor->getRootFrame();
369 else if ( mpWindow )
371 css::uno::Reference < css::accessibility::XAccessible > xAcc =
372 mpWindow->GetAccessible();
373 if ( xAcc.is() )
375 css::uno::Reference < css::accessibility::XAccessibleContext > xAccContext =
376 xAcc->getAccessibleContext();
377 if ( xAccContext.is() )
379 css::uno::Reference < css::accessibility::XAccessible > xAccParent =
380 xAccContext->getAccessibleParent();
381 if ( xAccParent.is() )
383 SwAccessibleContext* pAccParentImpl =
384 dynamic_cast< SwAccessibleContext *>( xAccParent.get() );
385 if ( pAccParentImpl )
387 pParent = pAccParentImpl->GetFrame();
394 return pParent;
397 } // namespace sw::access
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */