LibreOffice Module sw (master) 1
tolayoutanchoredobjectposition.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
21#include <anchoredobject.hxx>
22#include <frame.hxx>
23#include <pagefrm.hxx>
24#include <svx/svdobj.hxx>
25#include <frmfmt.hxx>
26#include <fmtanchr.hxx>
27#include <fmtornt.hxx>
28#include <fmtsrnd.hxx>
29#include <frmatr.hxx>
30#include <viewsh.hxx>
31#include <viewopt.hxx>
32#include <rootfrm.hxx>
33#include <editeng/lrspitem.hxx>
34#include <editeng/ulspitem.hxx>
35
36using namespace ::com::sun::star;
37
38namespace objectpositioning
39{
41 : SwAnchoredObjectPosition( _rDrawObj )
42{}
43
45{}
46
49{
50 const SwRect aObjBoundRect( GetAnchoredObj().GetObjRect() );
51
52 SwRectFnSet aRectFnSet(&GetAnchorFrame());
53
54 const SwFrameFormat& rFrameFormat = GetFrameFormat();
55 const SvxLRSpaceItem &rLR = rFrameFormat.GetLRSpace();
56 const SvxULSpaceItem &rUL = rFrameFormat.GetULSpace();
57
58 const bool bFlyAtFly = RndStdIds::FLY_AT_FLY == rFrameFormat.GetAnchor().GetAnchorId();
59
60 // determine position.
61 // 'vertical' and 'horizontal' position are calculated separately
62 Point aRelPos;
63
64 // calculate 'vertical' position
65 SwFormatVertOrient aVert( rFrameFormat.GetVertOrient() );
66 {
67 // to-frame anchored objects are *only* vertical positioned centered or
68 // bottom, if its wrap mode is 'through' and its anchor frame has fixed
69 // size. Otherwise, it's positioned top.
70 sal_Int16 eVertOrient = aVert.GetVertOrient();
71 if ( bFlyAtFly &&
72 ( eVertOrient == text::VertOrientation::CENTER ||
73 eVertOrient == text::VertOrientation::BOTTOM ) &&
74 css::text::WrapTextMode_THROUGH != rFrameFormat.GetSurround().GetSurround() &&
75 !GetAnchorFrame().HasFixSize() )
76 {
77 eVertOrient = text::VertOrientation::TOP;
78 }
79 // #i26791# - get vertical offset to frame anchor position.
80 SwTwips nVertOffsetToFrameAnchorPos( 0 );
81 SwTwips nRelPosY =
83 aVert.GetRelationOrient(), aVert.GetPos(),
84 rLR, rUL, nVertOffsetToFrameAnchorPos );
85
86 // keep the calculated relative vertical position - needed for filters
87 // (including the xml-filter)
88 {
89 SwTwips nAttrRelPosY = nRelPosY - nVertOffsetToFrameAnchorPos;
91 aVert.GetPos() != nAttrRelPosY )
92 {
93 aVert.SetPos( nAttrRelPosY );
94 const_cast<SwFrameFormat&>(rFrameFormat).LockModify();
95 const_cast<SwFrameFormat&>(rFrameFormat).SetFormatAttr( aVert );
96 const_cast<SwFrameFormat&>(rFrameFormat).UnlockModify();
97 }
98 }
99
100 // determine absolute 'vertical' position, depending on layout-direction
101 // #i26791# - determine offset to 'vertical' frame
102 // anchor position, depending on layout-direction
103 if( aRectFnSet.IsVert() )
104 {
105 if ( aRectFnSet.IsVertL2R() )
106 aRelPos.setX( nRelPosY );
107 else
108 aRelPos.setX( -nRelPosY - aObjBoundRect.Width() );
109 maOffsetToFrameAnchorPos.setX( nVertOffsetToFrameAnchorPos );
110 }
111 else
112 {
113 aRelPos.setY( nRelPosY );
114 maOffsetToFrameAnchorPos.setY( nVertOffsetToFrameAnchorPos );
115 }
116
117 // if in online-layout the bottom of to-page anchored object is beyond
118 // the page bottom, the page frame has to grow by growing its body frame.
120 if ( !bFlyAtFly && GetAnchorFrame().IsPageFrame() &&
121 pSh && pSh->GetViewOptions()->getBrowseMode() )
122 {
123 const tools::Long nAnchorBottom = GetAnchorFrame().getFrameArea().Bottom();
124 const tools::Long nBottom = GetAnchorFrame().getFrameArea().Top() +
125 aRelPos.Y() + aObjBoundRect.Height();
126 if ( nAnchorBottom < nBottom )
127 {
128 static_cast<SwPageFrame&>(GetAnchorFrame()).
129 FindBodyCont()->Grow( nBottom - nAnchorBottom );
130 }
131 }
132 } // end of determination of vertical position
133
134 // calculate 'horizontal' position
135 SwFormatHoriOrient aHori( rFrameFormat.GetHoriOrient() );
136 {
137 // consider toggle of horizontal position for even pages.
138 const bool bToggle = aHori.IsPosToggle() &&
140 sal_Int16 eHoriOrient = aHori.GetHoriOrient();
141 sal_Int16 eRelOrient = aHori.GetRelationOrient();
142 // toggle orientation
143 ToggleHoriOrientAndAlign( bToggle, eHoriOrient, eRelOrient );
144
145 // determine alignment values:
146 // <nWidth>: 'width' of the alignment area
147 // <nOffset>: offset of alignment area, relative to 'left' of
148 // frame anchor position
149 SwTwips nWidth, nOffset;
150 {
151 bool bDummy; // in this context irrelevant output parameter
153 eRelOrient, false,
154 nWidth, nOffset, bDummy );
155 }
156
157 SwTwips nObjWidth = aRectFnSet.GetWidth(aObjBoundRect);
158
159 // determine relative horizontal position
160 SwTwips nRelPosX;
161 if ( text::HoriOrientation::NONE == eHoriOrient )
162 {
163 if( bToggle ||
164 ( !aHori.IsPosToggle() && GetAnchorFrame().IsRightToLeft() ) )
165 {
166 nRelPosX = nWidth - nObjWidth - aHori.GetPos();
167 }
168 else
169 {
170 nRelPosX = aHori.GetPos();
171 }
172 }
173 else if ( text::HoriOrientation::CENTER == eHoriOrient )
174 nRelPosX = (nWidth / 2) - (nObjWidth / 2);
175 else if ( text::HoriOrientation::RIGHT == eHoriOrient )
176 nRelPosX = nWidth - ( nObjWidth +
177 ( aRectFnSet.IsVert() ? rUL.GetLower() : rLR.GetRight() ) );
178 else
179 nRelPosX = aRectFnSet.IsVert() ? rUL.GetUpper() : rLR.GetLeft();
180 nRelPosX += nOffset;
181
182 // no 'negative' relative horizontal position
183 // OD 06.11.2003 #FollowTextFlowAtFrame# - negative positions allow for
184 // to frame anchored objects.
185 if ( !bFlyAtFly && nRelPosX < 0 )
186 {
187 nRelPosX = 0;
188 }
189
190 // determine absolute 'horizontal' position, depending on layout-direction
191 // #i26791# - determine offset to 'horizontal' frame
192 // anchor position, depending on layout-direction
193 if( aRectFnSet.IsVert() || aRectFnSet.IsVertL2R() )
194 {
195
196 aRelPos.setY( nRelPosX );
197 maOffsetToFrameAnchorPos.setY( nOffset );
198 }
199 else
200 {
201 aRelPos.setX( nRelPosX );
202 maOffsetToFrameAnchorPos.setX( nOffset );
203 }
204
205 // keep the calculated relative horizontal position - needed for filters
206 // (including the xml-filter)
207 {
208 SwTwips nAttrRelPosX = nRelPosX - nOffset;
210 aHori.GetPos() != nAttrRelPosX )
211 {
212 aHori.SetPos( nAttrRelPosX );
213 const_cast<SwFrameFormat&>(rFrameFormat).LockModify();
214 const_cast<SwFrameFormat&>(rFrameFormat).SetFormatAttr( aHori );
215 const_cast<SwFrameFormat&>(rFrameFormat).UnlockModify();
216 }
217 }
218 } // end of determination of horizontal position
219
220 // keep calculate relative position
221 maRelPos = aRelPos;
222}
223
224}
225
226/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Long GetRight() const
tools::Long GetLeft() const
sal_uInt16 GetUpper() const
sal_uInt16 GetLower() const
RndStdIds GetAnchorId() const
Definition: fmtanchr.hxx:67
Defines the horizontal position of a fly frame.
Definition: fmtornt.hxx:73
void SetPos(SwTwips nNew)
Definition: fmtornt.hxx:100
sal_Int16 GetHoriOrient() const
Definition: fmtornt.hxx:94
SwTwips GetPos() const
Definition: fmtornt.hxx:99
bool IsPosToggle() const
Definition: fmtornt.hxx:102
sal_Int16 GetRelationOrient() const
Definition: fmtornt.hxx:95
css::text::WrapTextMode GetSurround() const
Definition: fmtsrnd.hxx:51
Defines the vertical position of a fly frame.
Definition: fmtornt.hxx:37
sal_Int16 GetRelationOrient() const
Definition: fmtornt.hxx:58
SwTwips GetPos() const
Definition: fmtornt.hxx:62
void SetPos(SwTwips nNew)
Definition: fmtornt.hxx:63
sal_Int16 GetVertOrient() const
Definition: fmtornt.hxx:57
const SvxLRSpaceItem & GetLRSpace(bool=true) const
Definition: frmatr.hxx:74
const SwFormatVertOrient & GetVertOrient(bool=true) const
Definition: fmtornt.hxx:113
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:83
const SwFormatSurround & GetSurround(bool=true) const
Definition: fmtsrnd.hxx:66
const SwFormatHoriOrient & GetHoriOrient(bool=true) const
Definition: fmtornt.hxx:115
const SvxULSpaceItem & GetULSpace(bool=true) const
Definition: frmatr.hxx:76
const SwRect & getFrameArea() const
Definition: frame.hxx:179
Style of a layout element.
Definition: frmfmt.hxx:62
bool OnRightPage() const
Definition: frame.hxx:733
SwTwips Grow(SwTwips, bool bTst=false, bool bInfo=false)
Definition: wsfrm.cxx:1510
SwRootFrame * getRootFrame()
Definition: frame.hxx:679
SwPageFrame * FindPageFrame()
Definition: frame.hxx:680
A page of the document layout.
Definition: pagefrm.hxx:58
bool IsVert() const
Definition: frame.hxx:1366
tools::Long GetWidth(const SwRect &rRect) const
Definition: frame.hxx:1380
bool IsVertL2R() const
Definition: frame.hxx:1367
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Height(tools::Long nNew)
Definition: swrect.hxx:193
void Top(const tools::Long nTop)
Definition: swrect.hxx:206
void Bottom(const tools::Long nBottom)
Definition: swrect.hxx:211
void Width(tools::Long nNew)
Definition: swrect.hxx:189
SwViewShell * GetCurrShell() const
Definition: rootfrm.hxx:206
bool getBrowseMode() const
Definition: viewopt.hxx:580
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:433
static void ToggleHoriOrientAndAlign(const bool _bToggleLeftRight, sal_Int16 &_ioeHoriOrient, sal_Int16 &_iopeRelOrient)
toggle given horizontal orientation and relative alignment
void GetHoriAlignmentValues(const SwFrame &_rHoriOrientFrame, const SwFrame &_rPageAlignLayFrame, const sal_Int16 _eRelOrient, const bool _bObjWrapThrough, SwTwips &_orAlignAreaWidth, SwTwips &_orAlignAreaOffset, bool &_obAlignedRelToPage) const
determine alignment values for horizontal position of object
SwTwips GetVertRelPos(const SwFrame &_rVertOrientFrame, const SwFrame &_rPageAlignLayFrame, const sal_Int16 _eVertOrient, const sal_Int16 _eRelOrient, const SwTwips _nVertPos, const SvxLRSpaceItem &_rLRSpacing, const SvxULSpaceItem &_rULSpacing, SwTwips &_roVertOffsetToFrameAnchorPos) const
virtual void CalcPosition() override
calculate position for object
long Long
tools::Long SwTwips
Definition: swtypes.hxx:51