2004-03-08 13:02:28 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: tolayoutanchoredobjectposition.cxx,v $
|
|
|
|
*
|
2004-08-23 07:03:14 +00:00
|
|
|
* $Revision: 1.5 $
|
2004-03-08 13:02:28 +00:00
|
|
|
*
|
2004-08-23 07:03:14 +00:00
|
|
|
* last change: $Author: rt $ $Date: 2004-08-23 08:03:14 $
|
2004-03-08 13:02:28 +00:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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 for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (the "License"); You may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of the
|
|
|
|
* License at http://www.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
#ifndef _TOLAYOUTANCHOREDOBJECTPOSITION_HXX
|
|
|
|
#include <tolayoutanchoredobjectposition.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _FRAME_HXX
|
|
|
|
#include <frame.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _FLYFRMS_HXX
|
|
|
|
#include <flyfrms.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _PAGEFRM_HXX
|
|
|
|
#include <pagefrm.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _SVX_SVDOBJ_HXX
|
|
|
|
#include <svx/svdobj.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _FRMFMT_HXX
|
|
|
|
#include <frmfmt.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _FMTANCHR_HXX
|
|
|
|
#include <fmtanchr.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _FMTORNT_HXX
|
|
|
|
#include <fmtornt.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _FMTSRND_HXX
|
|
|
|
#include <fmtsrnd.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _DOC_HXX
|
|
|
|
#include <doc.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _FRMATR_HXX
|
|
|
|
#include <frmatr.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _SVX_LRSPITEM_HXX
|
|
|
|
#include <svx/lrspitem.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _SVX_ULSPITEM_HXX
|
|
|
|
#include <svx/ulspitem.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace objectpositioning;
|
|
|
|
|
|
|
|
SwToLayoutAnchoredObjectPosition::SwToLayoutAnchoredObjectPosition( SdrObject& _rDrawObj )
|
|
|
|
: SwAnchoredObjectPosition( _rDrawObj ),
|
2004-06-28 12:43:27 +00:00
|
|
|
maRelPos( Point() ),
|
|
|
|
// --> OD 2004-06-17 #i26791#
|
|
|
|
maOffsetToFrmAnchorPos( Point() )
|
2004-03-08 13:02:28 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
SwToLayoutAnchoredObjectPosition::~SwToLayoutAnchoredObjectPosition()
|
|
|
|
{}
|
|
|
|
|
|
|
|
/** calculate position for object position type TO_LAYOUT
|
|
|
|
|
|
|
|
@author OD
|
|
|
|
*/
|
|
|
|
void SwToLayoutAnchoredObjectPosition::CalcPosition()
|
|
|
|
{
|
2004-06-28 12:43:27 +00:00
|
|
|
const SwRect aObjBoundRect( GetAnchoredObj().GetObjRect() );
|
2004-03-08 13:02:28 +00:00
|
|
|
|
|
|
|
SWRECTFN( (&GetAnchorFrm()) );
|
|
|
|
|
|
|
|
const SwFrmFmt& rFrmFmt = GetFrmFmt();
|
|
|
|
const SvxLRSpaceItem &rLR = rFrmFmt.GetLRSpace();
|
|
|
|
const SvxULSpaceItem &rUL = rFrmFmt.GetULSpace();
|
|
|
|
|
|
|
|
const bool bFlyAtFly = FLY_AT_FLY == rFrmFmt.GetAnchor().GetAnchorId();
|
|
|
|
|
|
|
|
// determine position.
|
|
|
|
// 'vertical' and 'horizontal' position are calculated separately
|
|
|
|
Point aRelPos;
|
|
|
|
|
|
|
|
// calculate 'vertical' position
|
|
|
|
SwFmtVertOrient aVert( rFrmFmt.GetVertOrient() );
|
|
|
|
{
|
|
|
|
// to-frame anchored objects are *only* vertical positioned centered or
|
|
|
|
// bottom, if its wrap mode is 'throught' and its anchor frame has fixed
|
|
|
|
// size. Otherwise, it's positioned top.
|
|
|
|
SwVertOrient eVertOrient = aVert.GetVertOrient();
|
|
|
|
if ( ( bFlyAtFly &&
|
|
|
|
( eVertOrient == VERT_CENTER ||
|
|
|
|
eVertOrient == VERT_BOTTOM ) &&
|
|
|
|
SURROUND_THROUGHT != rFrmFmt.GetSurround().GetSurround() &&
|
|
|
|
!GetAnchorFrm().HasFixSize() ) )
|
|
|
|
{
|
|
|
|
eVertOrient = VERT_TOP;
|
|
|
|
}
|
2004-06-28 12:43:27 +00:00
|
|
|
// --> OD 2004-06-17 #i26791# - get vertical offset to frame anchor position.
|
|
|
|
SwTwips nVertOffsetToFrmAnchorPos( 0L );
|
2004-03-08 13:02:28 +00:00
|
|
|
SwTwips nRelPosY =
|
|
|
|
_GetVertRelPos( GetAnchorFrm(), GetAnchorFrm(), eVertOrient,
|
2004-06-28 12:43:27 +00:00
|
|
|
aVert.GetRelationOrient(), aVert.GetPos(),
|
|
|
|
rLR, rUL, nVertOffsetToFrmAnchorPos );
|
2004-03-08 13:02:28 +00:00
|
|
|
|
|
|
|
|
2004-08-23 07:03:14 +00:00
|
|
|
// keep the calculated relative vertical position - needed for filters
|
|
|
|
// (including the xml-filter)
|
2004-03-08 13:02:28 +00:00
|
|
|
{
|
2004-08-23 07:03:14 +00:00
|
|
|
SwTwips nAttrRelPosY = nRelPosY - nVertOffsetToFrmAnchorPos;
|
|
|
|
if ( aVert.GetVertOrient() != VERT_NONE &&
|
|
|
|
aVert.GetPos() != nAttrRelPosY )
|
|
|
|
{
|
|
|
|
aVert.SetPos( nAttrRelPosY );
|
|
|
|
const_cast<SwFrmFmt&>(rFrmFmt).LockModify();
|
|
|
|
const_cast<SwFrmFmt&>(rFrmFmt).SetAttr( aVert );
|
|
|
|
const_cast<SwFrmFmt&>(rFrmFmt).UnlockModify();
|
|
|
|
}
|
2004-03-08 13:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// determine absolute 'vertical' position, depending on layout-direction
|
2004-06-28 12:43:27 +00:00
|
|
|
// --> OD 2004-06-17 #i26791# - determine offset to 'vertical' frame
|
|
|
|
// anchor position, depending on layout-direction
|
2004-03-08 13:02:28 +00:00
|
|
|
if( bVert )
|
|
|
|
{
|
|
|
|
ASSERT( !bRev, "<SwToLayoutAnchoredObjectPosition::CalcPosition()> - reverse layout set." );
|
|
|
|
aRelPos.X() = -nRelPosY - aObjBoundRect.Width();
|
2004-06-28 12:43:27 +00:00
|
|
|
maOffsetToFrmAnchorPos.X() = nVertOffsetToFrmAnchorPos;
|
2004-03-08 13:02:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aRelPos.Y() = nRelPosY;
|
2004-06-28 12:43:27 +00:00
|
|
|
maOffsetToFrmAnchorPos.Y() = nVertOffsetToFrmAnchorPos;
|
2004-03-08 13:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if in online-layout the bottom of to-page anchored object is beyond
|
|
|
|
// the page bottom, the page frame has to grow by growing its body frame.
|
|
|
|
if ( !bFlyAtFly && GetAnchorFrm().IsPageFrm() &&
|
|
|
|
rFrmFmt.GetDoc()->IsBrowseMode() )
|
|
|
|
{
|
|
|
|
const long nAnchorBottom = GetAnchorFrm().Frm().Bottom();
|
|
|
|
const long nBottom = GetAnchorFrm().Frm().Top() +
|
|
|
|
aRelPos.Y() + aObjBoundRect.Height();
|
|
|
|
if ( nAnchorBottom < nBottom )
|
|
|
|
{
|
|
|
|
static_cast<SwPageFrm&>(GetAnchorFrm()).
|
|
|
|
FindBodyCont()->Grow( nBottom - nAnchorBottom );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // end of determination of vertical position
|
|
|
|
|
|
|
|
// calculate 'horizontal' position
|
|
|
|
SwFmtHoriOrient aHori( rFrmFmt.GetHoriOrient() );
|
|
|
|
bool bHoriChgd = false;
|
|
|
|
{
|
|
|
|
// consider toggle of horizontal position for even pages.
|
|
|
|
const bool bToggle = aHori.IsPosToggle() &&
|
|
|
|
!GetAnchorFrm().FindPageFrm()->OnRightPage();
|
|
|
|
SwHoriOrient eHoriOrient = aHori.GetHoriOrient();
|
|
|
|
SwRelationOrient eRelOrient = aHori.GetRelationOrient();
|
|
|
|
// toggle orientation
|
|
|
|
_ToggleHoriOrientAndAlign( bToggle, eHoriOrient, eRelOrient );
|
|
|
|
|
|
|
|
// determine alignment values:
|
|
|
|
// <nWidth>: 'width' of the alignment area
|
2004-06-28 12:43:27 +00:00
|
|
|
// <nOffset>: offset of alignment area, relative to 'left' of
|
|
|
|
// frame anchor position
|
2004-03-08 13:02:28 +00:00
|
|
|
SwTwips nWidth, nOffset;
|
|
|
|
{
|
|
|
|
bool bDummy; // in this context irrelevant output parameter
|
|
|
|
_GetHoriAlignmentValues( GetAnchorFrm(), GetAnchorFrm(),
|
|
|
|
eRelOrient, false,
|
|
|
|
nWidth, nOffset, bDummy );
|
|
|
|
}
|
|
|
|
|
|
|
|
SwTwips nObjWidth = (aObjBoundRect.*fnRect->fnGetWidth)();
|
|
|
|
|
|
|
|
// determine relative horizontal position
|
|
|
|
SwTwips nRelPosX;
|
|
|
|
if ( HORI_NONE == eHoriOrient )
|
|
|
|
{
|
|
|
|
if( bToggle ||
|
|
|
|
( !aHori.IsPosToggle() && GetAnchorFrm().IsRightToLeft() ) )
|
|
|
|
{
|
|
|
|
nRelPosX = nWidth - nObjWidth - aHori.GetPos();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nRelPosX = aHori.GetPos();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( HORI_CENTER == eHoriOrient )
|
|
|
|
nRelPosX = (nWidth / 2) - (nObjWidth / 2);
|
|
|
|
else if ( HORI_RIGHT == eHoriOrient )
|
|
|
|
nRelPosX = nWidth - ( nObjWidth +
|
|
|
|
( bVert ? rUL.GetLower() : rLR.GetRight() ) );
|
|
|
|
else
|
|
|
|
nRelPosX = bVert ? rUL.GetUpper() : rLR.GetLeft();
|
|
|
|
nRelPosX += nOffset;
|
|
|
|
|
|
|
|
// no 'negative' relative horizontal position
|
|
|
|
// OD 06.11.2003 #FollowTextFlowAtFrame# - negative positions allow for
|
|
|
|
// to frame anchored objects.
|
|
|
|
if ( !bFlyAtFly && nRelPosX < 0 )
|
|
|
|
{
|
|
|
|
nRelPosX = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine absolute 'horizontal' position, depending on layout-direction
|
2004-06-28 12:43:27 +00:00
|
|
|
// --> OD 2004-06-17 #i26791# - determine offset to 'horizontal' frame
|
|
|
|
// anchor position, depending on layout-direction
|
|
|
|
if ( bVert )
|
|
|
|
{
|
2004-03-08 13:02:28 +00:00
|
|
|
aRelPos.Y() = nRelPosX;
|
2004-06-28 12:43:27 +00:00
|
|
|
maOffsetToFrmAnchorPos.Y() = nOffset;
|
|
|
|
}
|
2004-03-08 13:02:28 +00:00
|
|
|
else
|
2004-06-28 12:43:27 +00:00
|
|
|
{
|
2004-03-08 13:02:28 +00:00
|
|
|
aRelPos.X() = nRelPosX;
|
2004-06-28 12:43:27 +00:00
|
|
|
maOffsetToFrmAnchorPos.X() = nOffset;
|
|
|
|
}
|
2004-03-08 13:02:28 +00:00
|
|
|
|
2004-08-23 07:03:14 +00:00
|
|
|
// keep the calculated relative horizontal position - needed for filters
|
|
|
|
// (including the xml-filter)
|
2004-03-08 13:02:28 +00:00
|
|
|
{
|
2004-08-23 07:03:14 +00:00
|
|
|
SwTwips nAttrRelPosX = nRelPosX - nOffset;
|
|
|
|
if ( HORI_NONE != aHori.GetHoriOrient() &&
|
|
|
|
aHori.GetPos() != nAttrRelPosX )
|
|
|
|
{
|
|
|
|
aHori.SetPos( nAttrRelPosX );
|
|
|
|
const_cast<SwFrmFmt&>(rFrmFmt).LockModify();
|
|
|
|
const_cast<SwFrmFmt&>(rFrmFmt).SetAttr( aHori );
|
|
|
|
const_cast<SwFrmFmt&>(rFrmFmt).UnlockModify();
|
|
|
|
}
|
2004-03-08 13:02:28 +00:00
|
|
|
}
|
|
|
|
} // end of determination of horizontal position
|
|
|
|
|
|
|
|
// keep calculate relative position
|
|
|
|
maRelPos = aRelPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** calculated relative position for object position
|
|
|
|
|
|
|
|
@author OD
|
|
|
|
*/
|
|
|
|
Point SwToLayoutAnchoredObjectPosition::GetRelPos() const
|
|
|
|
{
|
|
|
|
return maRelPos;
|
|
|
|
}
|
2004-06-28 12:43:27 +00:00
|
|
|
|
|
|
|
/** determined offset to frame anchor position
|
|
|
|
|
|
|
|
--> OD 2004-06-17 #i26791#
|
|
|
|
|
|
|
|
@author OD
|
|
|
|
*/
|
|
|
|
Point SwToLayoutAnchoredObjectPosition::GetOffsetToFrmAnchorPos() const
|
|
|
|
{
|
|
|
|
return maOffsetToFrmAnchorPos;
|
|
|
|
}
|