Files
libreoffice/sw/source/core/access/accframe.cxx

507 lines
17 KiB
C++
Raw Normal View History

2002-02-04 13:10:18 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2002-02-04 13:10:18 +00:00
*
* Copyright 2008 by Sun Microsystems, Inc.
2002-02-04 13:10:18 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2002-02-04 13:10:18 +00:00
*
* $RCSfile: accframe.cxx,v $
* $Revision: 1.26 $
2002-02-04 13:10:18 +00:00
*
* This file is part of OpenOffice.org.
2002-02-04 13:10:18 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2002-02-04 13:10:18 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2002-02-04 13:10:18 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2002-02-04 13:10:18 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"
2002-02-04 13:10:18 +00:00
2002-04-05 11:18:25 +00:00
2002-02-05 14:52:06 +00:00
#include <hintids.hxx>
#include <svx/brshitem.hxx>
#include <flyfrm.hxx>
2002-02-04 13:10:18 +00:00
#include <rootfrm.hxx>
#include <txtfrm.hxx>
2002-02-05 14:52:06 +00:00
#include <sectfrm.hxx>
2002-04-05 11:18:25 +00:00
#include <pagefrm.hxx>
2002-02-05 14:52:06 +00:00
#include <section.hxx>
2002-02-04 13:10:18 +00:00
#include <viewsh.hxx>
2002-02-05 14:52:06 +00:00
#include <viewopt.hxx>
#include <doc.hxx>
#include <frmatr.hxx>
2002-04-11 13:04:40 +00:00
#include <pagefrm.hxx>
#include <pagedesc.hxx>
2002-05-15 12:22:47 +00:00
#include <fmtanchr.hxx>
2002-04-11 13:04:40 +00:00
#include <fldbas.hxx>
2002-05-15 12:22:47 +00:00
#include <dcontact.hxx>
#include <accmap.hxx>
2002-04-05 11:18:25 +00:00
#include <accfrmobjslist.hxx>
#include <accfrmobjmap.hxx>
2002-02-04 13:10:18 +00:00
#include <accframe.hxx>
2002-04-05 11:18:25 +00:00
2002-02-11 11:51:16 +00:00
// Regarding visibilily (or in terms of accessibility: regarding the showing
// state): A frame is visible and therfor contained in the tree if its frame
// size overlaps with the visible area. The bounding box however is the
// frame's paint area.
2002-04-11 13:04:40 +00:00
sal_Int32 SwAccessibleFrame::GetChildCount( const SwRect& rVisArea,
2002-05-22 10:48:43 +00:00
const SwFrm *pFrm,
sal_Bool bInPagePreview )
2002-02-04 13:10:18 +00:00
{
sal_Int32 nCount = 0;
2002-04-05 11:18:25 +00:00
2002-04-11 13:04:40 +00:00
const SwFrmOrObjSList aVisList( rVisArea, pFrm );
SwFrmOrObjSList::const_iterator aIter( aVisList.begin() );
while( aIter != aVisList.end() )
2002-02-04 13:10:18 +00:00
{
2002-04-05 11:18:25 +00:00
const SwFrmOrObj& rLower = *aIter;
2002-05-22 10:48:43 +00:00
if( rLower.IsAccessible( bInPagePreview ) )
2002-02-04 13:10:18 +00:00
{
2002-04-11 13:04:40 +00:00
nCount++;
}
else if( rLower.GetSwFrm() )
{
// There are no unaccessible SdrObjects that count
2002-05-22 10:48:43 +00:00
nCount += GetChildCount( rVisArea, rLower.GetSwFrm(),
bInPagePreview );
2002-02-04 13:10:18 +00:00
}
2002-04-05 11:18:25 +00:00
++aIter;
2002-02-04 13:10:18 +00:00
}
return nCount;
}
2002-04-11 13:04:40 +00:00
SwFrmOrObj SwAccessibleFrame::GetChild( const SwRect& rVisArea,
2002-05-22 10:48:43 +00:00
const SwFrm *pFrm,
sal_Int32& rPos,
sal_Bool bInPagePreview )
2002-02-04 13:10:18 +00:00
{
2002-04-05 11:18:25 +00:00
SwFrmOrObj aRet;
2002-02-05 14:52:06 +00:00
if( rPos >= 0 )
2002-02-04 13:10:18 +00:00
{
2002-04-05 11:18:25 +00:00
if( SwFrmOrObjMap::IsSortingRequired( pFrm ) )
2002-02-04 13:10:18 +00:00
{
2002-04-05 11:18:25 +00:00
// We need a sorted list here
const SwFrmOrObjMap aVisMap( rVisArea, pFrm );
SwFrmOrObjMap::const_iterator aIter( aVisMap.begin() );
while( aIter != aVisMap.end() && !aRet.IsValid() )
2002-02-04 13:10:18 +00:00
{
2002-04-05 11:18:25 +00:00
const SwFrmOrObj& rLower = (*aIter).second;
2002-05-22 10:48:43 +00:00
if( rLower.IsAccessible( bInPagePreview ) )
2002-02-05 14:52:06 +00:00
{
if( 0 == rPos )
2002-04-05 11:18:25 +00:00
aRet = rLower;
2002-02-05 14:52:06 +00:00
else
rPos--;
}
2002-04-05 11:18:25 +00:00
else if( rLower.GetSwFrm() )
2002-02-05 14:52:06 +00:00
{
2002-04-05 11:18:25 +00:00
// There are no unaccessible SdrObjects that count
2002-05-22 10:48:43 +00:00
aRet = GetChild( rVisArea, rLower.GetSwFrm(), rPos,
bInPagePreview );
2002-02-05 14:52:06 +00:00
}
2002-04-05 11:18:25 +00:00
++aIter;
}
}
else
{
// The unsorted list is sorted enough, because it return lower
// frames in the correct order.
const SwFrmOrObjSList aVisList( rVisArea, pFrm );
SwFrmOrObjSList::const_iterator aIter( aVisList.begin() );
while( aIter != aVisList.end() && !aRet.IsValid() )
{
const SwFrmOrObj& rLower = *aIter;
2002-05-22 10:48:43 +00:00
if( rLower.IsAccessible( bInPagePreview ) )
2002-04-05 11:18:25 +00:00
{
if( 0 == rPos )
aRet = rLower;
else
rPos--;
}
else if( rLower.GetSwFrm() )
{
// There are no unaccessible SdrObjects that count
2002-05-22 10:48:43 +00:00
aRet = GetChild( rVisArea, rLower.GetSwFrm(), rPos,
bInPagePreview );
2002-04-05 11:18:25 +00:00
}
++aIter;
2002-02-04 13:10:18 +00:00
}
}
}
2002-04-05 11:18:25 +00:00
return aRet;
2002-02-04 13:10:18 +00:00
}
2002-04-11 13:04:40 +00:00
sal_Bool SwAccessibleFrame::GetChildIndex( const SwRect& rVisArea,
2002-04-05 11:18:25 +00:00
const SwFrm *pFrm,
const SwFrmOrObj& rChild,
2002-05-22 10:48:43 +00:00
sal_Int32& rPos,
sal_Bool bInPagePreview )
2002-02-04 13:10:18 +00:00
{
sal_Bool bFound = sal_False;
2002-04-05 11:18:25 +00:00
if( SwFrmOrObjMap::IsSortingRequired( pFrm ) )
2002-02-04 13:10:18 +00:00
{
2002-04-05 11:18:25 +00:00
// We need a sorted list here
const SwFrmOrObjMap aVisMap( rVisArea, pFrm );
SwFrmOrObjMap::const_iterator aIter( aVisMap.begin() );
while( aIter != aVisMap.end() && !bFound )
2002-02-04 13:10:18 +00:00
{
2002-04-05 11:18:25 +00:00
const SwFrmOrObj& rLower = (*aIter).second;
2002-05-22 10:48:43 +00:00
if( rLower.IsAccessible( bInPagePreview ) )
2002-02-04 13:10:18 +00:00
{
2002-04-05 11:18:25 +00:00
if( rChild == rLower )
2002-02-04 13:10:18 +00:00
bFound = sal_True;
else
rPos++;
}
2002-04-05 11:18:25 +00:00
else if( rLower.GetSwFrm() )
2002-02-04 13:10:18 +00:00
{
2002-04-05 11:18:25 +00:00
// There are no unaccessible SdrObjects that count
2002-05-22 10:48:43 +00:00
bFound = GetChildIndex( rVisArea, rLower.GetSwFrm(), rChild,
rPos, bInPagePreview );
2002-02-04 13:10:18 +00:00
}
2002-04-05 11:18:25 +00:00
++aIter;
}
}
else
{
// The unsorted list is sorted enough, because it return lower
// frames in the correct order.
const SwFrmOrObjSList aVisList( rVisArea, pFrm );
SwFrmOrObjSList::const_iterator aIter( aVisList.begin() );
while( aIter != aVisList.end() && !bFound )
{
const SwFrmOrObj& rLower = *aIter;
2002-05-22 10:48:43 +00:00
if( rLower.IsAccessible( bInPagePreview ) )
2002-04-05 11:18:25 +00:00
{
if( rChild == rLower )
bFound = sal_True;
else
rPos++;
}
else if( rLower.GetSwFrm() )
{
// There are no unaccessible SdrObjects that count
2002-05-22 10:48:43 +00:00
bFound = GetChildIndex( rVisArea, rLower.GetSwFrm(), rChild,
rPos, bInPagePreview );
2002-04-05 11:18:25 +00:00
}
++aIter;
2002-02-04 13:10:18 +00:00
}
}
return bFound;
}
SwFrmOrObj SwAccessibleFrame::GetChildAtPixel( const SwRect& rVisArea,
2002-05-22 10:48:43 +00:00
const SwFrm *pFrm,
const Point& rPixPos,
sal_Bool bInPagePreview,
const SwAccessibleMap *pMap )
2002-02-04 13:10:18 +00:00
{
2002-04-05 11:18:25 +00:00
SwFrmOrObj aRet;
if( SwFrmOrObjMap::IsSortingRequired( pFrm ) )
2002-02-04 13:10:18 +00:00
{
2002-04-05 11:18:25 +00:00
// We need a sorted list here, and we have to reverse iterate,
// because objects in front should be returned.
const SwFrmOrObjMap aVisMap( rVisArea, pFrm );
SwFrmOrObjMap::const_reverse_iterator aRIter( aVisMap.rbegin() );
while( aRIter != aVisMap.rend() && !aRet.IsValid() )
2002-02-04 13:10:18 +00:00
{
2002-04-05 11:18:25 +00:00
const SwFrmOrObj& rLower = (*aRIter).second;
// A frame is returned if it's frame size is inside the visarea
// and the positiion is inside the frame's paint area.
2002-05-22 10:48:43 +00:00
if( rLower.IsAccessible( bInPagePreview ) )
2002-02-04 13:10:18 +00:00
{
SwRect aLogBounds( rLower.GetBounds( ) );
if( !aLogBounds.IsEmpty() )
{
Rectangle aPixBounds( pMap->CoreToPixel( aLogBounds.SVRect() ) );
if( aPixBounds.IsInside( rPixPos ) )
aRet = rLower;
}
2002-02-04 13:10:18 +00:00
}
2002-04-05 11:18:25 +00:00
else if( rLower.GetSwFrm() )
2002-02-04 13:10:18 +00:00
{
2002-04-05 11:18:25 +00:00
// There are no unaccessible SdrObjects that count
aRet = GetChildAtPixel( rVisArea, rLower.GetSwFrm(), rPixPos,
bInPagePreview, pMap );
2002-02-04 13:10:18 +00:00
}
2002-04-05 11:18:25 +00:00
aRIter++;
}
}
else
{
// The unsorted list is sorted enough, because it returns lower
// frames in the correct order. Morover, we can iterate forward,
// because the lowers don't overlap!
const SwFrmOrObjSList aVisList( rVisArea, pFrm );
SwFrmOrObjSList::const_iterator aIter( aVisList.begin() );
while( aIter != aVisList.end() && !aRet.IsValid() )
{
const SwFrmOrObj& rLower = *aIter;
// A frame is returned if it's frame size is inside the visarea
// and the positiion is inside the frame's paint area.
2002-05-22 10:48:43 +00:00
if( rLower.IsAccessible( bInPagePreview ) )
2002-04-05 11:18:25 +00:00
{
SwRect aLogBounds( rLower.GetBounds( ) );
if( !aLogBounds.IsEmpty() )
{
Rectangle aPixBounds( pMap->CoreToPixel( aLogBounds.SVRect() ) );
if( aPixBounds.IsInside( rPixPos ) )
aRet = rLower;
}
2002-04-05 11:18:25 +00:00
}
else if( rLower.GetSwFrm() )
{
// There are no unaccessible SdrObjects that count
aRet = GetChildAtPixel( rVisArea, rLower.GetSwFrm(), rPixPos,
bInPagePreview, pMap );
2002-04-05 11:18:25 +00:00
}
++aIter;
2002-02-04 13:10:18 +00:00
}
}
2002-04-05 11:18:25 +00:00
return aRet;
2002-02-04 13:10:18 +00:00
}
2002-05-15 12:22:47 +00:00
void SwAccessibleFrame::GetChildren( const SwRect& rVisArea, const SwFrm *pFrm,
2002-05-22 10:48:43 +00:00
::std::list< SwFrmOrObj >& rChildren,
sal_Bool bInPagePreview )
2002-05-15 12:22:47 +00:00
{
if( SwFrmOrObjMap::IsSortingRequired( pFrm ) )
{
// We need a sorted list here
const SwFrmOrObjMap aVisMap( rVisArea, pFrm );
SwFrmOrObjMap::const_iterator aIter( aVisMap.begin() );
while( aIter != aVisMap.end() )
{
const SwFrmOrObj& rLower = (*aIter).second;
2002-05-22 10:48:43 +00:00
if( rLower.IsAccessible( bInPagePreview ) )
2002-05-15 12:22:47 +00:00
{
rChildren.push_back( rLower );
}
else if( rLower.GetSwFrm() )
{
// There are no unaccessible SdrObjects that count
2002-05-22 10:48:43 +00:00
GetChildren( rVisArea, rLower.GetSwFrm(), rChildren,
bInPagePreview );
2002-05-15 12:22:47 +00:00
}
++aIter;
}
}
else
{
// The unsorted list is sorted enough, because it return lower
// frames in the correct order.
const SwFrmOrObjSList aVisList( rVisArea, pFrm );
SwFrmOrObjSList::const_iterator aIter( aVisList.begin() );
while( aIter != aVisList.end() )
{
const SwFrmOrObj& rLower = *aIter;
2002-05-22 10:48:43 +00:00
if( rLower.IsAccessible( bInPagePreview ) )
2002-05-15 12:22:47 +00:00
{
rChildren.push_back( rLower );
}
else if( rLower.GetSwFrm() )
{
// There are no unaccessible SdrObjects that count
2002-05-22 10:48:43 +00:00
GetChildren( rVisArea, rLower.GetSwFrm(), rChildren,
bInPagePreview );
2002-05-15 12:22:47 +00:00
}
++aIter;
}
}
}
2002-04-11 13:04:40 +00:00
SwRect SwAccessibleFrame::GetBounds( const SwFrm *pFrm )
2002-02-04 13:10:18 +00:00
{
if( !pFrm )
pFrm = GetFrm();
2002-02-27 08:32:33 +00:00
2002-04-11 13:04:40 +00:00
SwFrmOrObj aFrm( pFrm );
2002-05-22 10:48:43 +00:00
SwRect aBounds( aFrm.GetBounds().Intersection( maVisArea ) );
2002-02-04 13:10:18 +00:00
return aBounds;
}
sal_Bool SwAccessibleFrame::IsEditable( ViewShell *pVSh ) const
2002-02-05 14:52:06 +00:00
{
const SwFrm *pFrm = GetFrm();
if( !pFrm )
return sal_False;
ASSERT( pVSh, "no view shell" );
2002-07-10 15:53:35 +00:00
if( pVSh && (pVSh->GetViewOptions()->IsReadonly() ||
pVSh->IsPreView()) )
2002-02-05 14:52:06 +00:00
return sal_False;
if( !pFrm->IsRootFrm() && pFrm->IsProtected() )
return sal_False;
2002-02-05 14:52:06 +00:00
return sal_True;
2002-02-05 14:52:06 +00:00
}
sal_Bool SwAccessibleFrame::IsOpaque( ViewShell *pVSh ) const
2002-02-05 14:52:06 +00:00
{
2002-04-11 13:04:40 +00:00
SwFrmOrObj aFrm( GetFrm() );
if( !aFrm.GetSwFrm() )
2002-02-05 14:52:06 +00:00
return sal_False;
ASSERT( pVSh, "no view shell" );
if( !pVSh )
return sal_False;
const SwViewOption *pVOpt = pVSh->GetViewOptions();
do
{
2002-04-11 13:04:40 +00:00
const SwFrm *pFrm = aFrm.GetSwFrm();
2002-02-05 14:52:06 +00:00
if( pFrm->IsRootFrm() )
return sal_True;
if( pFrm->IsPageFrm() && !pVOpt->IsPageBack() )
return sal_False;
const SvxBrushItem &rBack = pFrm->GetAttrSet()->GetBackground();
if( !rBack.GetColor().GetTransparency() ||
rBack.GetGraphicPos() != GPOS_NONE )
return sal_True;
/// OD 20.08.2002 #99657#
/// If a fly frame has a transparent background color, we have
/// to consider the background.
/// But a background color "no fill"/"auto fill" has *not* to be considered.
if( pFrm->IsFlyFrm() &&
(rBack.GetColor().GetTransparency() != 0) &&
(rBack.GetColor() != COL_TRANSPARENT)
)
return sal_True;
2002-02-05 14:52:06 +00:00
if( pFrm->IsSctFrm() )
{
const SwSection* pSection = ((SwSectionFrm*)pFrm)->GetSection();
if( pSection && ( TOX_HEADER_SECTION == pSection->GetType() ||
TOX_CONTENT_SECTION == pSection->GetType() ) &&
!pVOpt->IsReadonly() &&
SwViewOption::IsIndexShadings() )
2002-02-05 14:52:06 +00:00
return sal_True;
}
2002-04-11 13:04:40 +00:00
if( pFrm->IsFlyFrm() )
aFrm = static_cast<const SwFlyFrm*>(pFrm)->GetAnchorFrm();
2002-02-05 14:52:06 +00:00
else
2002-04-11 13:04:40 +00:00
aFrm = pFrm->GetUpper();
2002-05-22 10:48:43 +00:00
} while( aFrm.GetSwFrm() && !aFrm.IsAccessible( IsInPagePreview() ) );
2002-02-05 14:52:06 +00:00
return sal_False;
}
2002-04-11 13:04:40 +00:00
SwAccessibleFrame::SwAccessibleFrame( const SwRect& rVisArea,
2002-05-22 10:48:43 +00:00
const SwFrm *pF,
sal_Bool bIsPagePreview ) :
maVisArea( rVisArea ),
mpFrm( pF ),
mbIsInPagePreview( bIsPagePreview )
2002-02-04 13:10:18 +00:00
{
}
SwAccessibleFrame::~SwAccessibleFrame()
{
}
2002-05-22 10:48:43 +00:00
const SwFrm *SwAccessibleFrame::GetParent( const SwFrmOrObj& rFrmOrObj,
sal_Bool bInPagePreview )
2002-02-04 13:10:18 +00:00
{
2002-04-11 13:04:40 +00:00
SwFrmOrObj aParent;
2002-05-15 12:22:47 +00:00
const SwFrm *pFrm = rFrmOrObj.GetSwFrm();
if( pFrm )
2002-04-05 11:18:25 +00:00
{
2002-05-15 12:22:47 +00:00
if( pFrm->IsFlyFrm() )
2002-04-05 11:18:25 +00:00
{
2002-05-15 12:22:47 +00:00
const SwFlyFrm *pFly = static_cast< const SwFlyFrm *>( pFrm );
if( pFly->IsFlyInCntFrm() )
{
// For FLY_IN_CNTNT the parent is the anchor
aParent = pFly->GetAnchorFrm();
2002-05-22 10:48:43 +00:00
ASSERT( aParent.IsAccessible( bInPagePreview ),
2002-05-15 12:22:47 +00:00
"parent is not accessible" );
}
else
{
// In any other case the parent is the root frm
2002-05-22 10:48:43 +00:00
// (in page preview, the page frame)
if( bInPagePreview )
aParent = pFly->FindPageFrm();
else
aParent = pFly->FindRootFrm();
2002-05-15 12:22:47 +00:00
}
2002-04-05 11:18:25 +00:00
}
else
{
2002-05-15 12:22:47 +00:00
SwFrmOrObj aUpper( pFrm->GetUpper() );
2002-05-22 10:48:43 +00:00
while( aUpper.GetSwFrm() && !aUpper.IsAccessible(bInPagePreview) )
2002-05-15 12:22:47 +00:00
aUpper = aUpper.GetSwFrm()->GetUpper();
aParent = aUpper;
2002-04-05 11:18:25 +00:00
}
}
2002-05-15 12:22:47 +00:00
else if( rFrmOrObj.GetSdrObject() )
2002-04-05 11:18:25 +00:00
{
2002-05-15 12:22:47 +00:00
const SwDrawContact *pContact =
static_cast< const SwDrawContact* >(
GetUserCall( rFrmOrObj.GetSdrObject() ) );
ASSERT( pContact, "sdr contact is missing" );
if( pContact )
{
const SwFrmFmt *pFrmFmt = pContact->GetFmt();
ASSERT( pFrmFmt, "frame format is missing" );
if( pFrmFmt && FLY_IN_CNTNT == pFrmFmt->GetAnchor().GetAnchorId() )
{
// For FLY_IN_CNTNT the parent is the anchor
aParent = pContact->GetAnchorFrm();
2002-05-22 10:48:43 +00:00
ASSERT( aParent.IsAccessible( bInPagePreview ),
2002-05-15 12:22:47 +00:00
"parent is not accessible" );
}
else
{
// In any other case the parent is the root frm
if( bInPagePreview )
aParent = pContact->GetAnchorFrm()->FindPageFrm();
else
aParent = pContact->GetAnchorFrm()->FindRootFrm();
2002-05-15 12:22:47 +00:00
}
}
2002-04-05 11:18:25 +00:00
}
2002-02-04 13:10:18 +00:00
2002-04-11 13:04:40 +00:00
return aParent.GetSwFrm();
2002-02-04 13:10:18 +00:00
}
2002-04-11 13:04:40 +00:00
String SwAccessibleFrame::GetFormattedPageNumber() const
{
2002-04-11 13:04:40 +00:00
sal_uInt16 nPageNum = GetFrm()->GetVirtPageNum();
sal_uInt32 nFmt = GetFrm()->FindPageFrm()->GetPageDesc()
->GetNumType().GetNumberingType();
if( SVX_NUM_NUMBER_NONE == nFmt )
nFmt = SVX_NUM_ARABIC;
String sRet( FormatNumber( nPageNum, nFmt ) );
return sRet;
}