1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_SW_SOURCE_CORE_INC_ANCHOREDOBJECTPOSITION_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_ANCHOREDOBJECTPOSITION_HXX
23 #include <swtypes.hxx>
25 #include <nodeoffset.hxx>
34 class SwFormatHoriOrient
;
35 class SwAnchoredObject
;
37 namespace objectpositioning
39 class SwEnvironmentOfAnchoredObject
;
41 class SwAnchoredObjectPosition
44 // object to be positioned
46 // #i26791# - anchored object the object belongs to;
47 SwAnchoredObject
* mpAnchoredObj
;
48 // frame the object is anchored at
49 SwFrame
* mpAnchorFrame
;
53 const SwFrameFormat
* mpFrameFormat
;
54 // does the object represents a Writer fly frame
57 bool mbFollowTextFlow
;
59 // for compatibility option <DoNotCaptureDrawObjsOnPage>
60 bool mbDoNotCaptureAnchoredObj
;
62 /** determine information about object
64 member <mbIsObjFly>, <mpAnchoredObj>, <mpAnchorFrame>, <mpContact>
65 and <mpFrameFormat> are set
67 void GetInfoAboutObj();
70 // --> OD 2009-09-01 #mongolianlayout# - add parameter <bVertL2R>
71 SwTwips
ImplAdjustVertRelPos( const SwTwips nTopOfAnch
,
74 const SwFrame
& rPageAlignLayFrame
,
75 const SwTwips nProposedRelPosY
,
76 const bool bFollowTextFlow
,
77 const bool bCheckBottom
) const;
78 SwTwips
ImplAdjustHoriRelPos( const SwFrame
& _rPageAlignLayFrame
,
79 const SwTwips _nProposedRelPosX
) const;
82 SwAnchoredObjectPosition( SdrObject
& _rDrawObj
);
83 virtual ~SwAnchoredObjectPosition();
85 // accessors for object and its corresponding data/information
86 SdrObject
& GetObject() const
94 SwAnchoredObject
& GetAnchoredObj() const
96 return *mpAnchoredObj
;
98 SwFrame
& GetAnchorFrame() const
100 return *mpAnchorFrame
;
102 const SwFrameFormat
& GetFrameFormat() const
104 return *mpFrameFormat
;
107 bool DoesObjFollowsTextFlow() const
109 return mbFollowTextFlow
;
112 // virtual methods providing data for to character anchored objects.
113 virtual bool IsAnchoredToChar() const;
114 virtual const SwFrame
* ToCharOrientFrame() const;
115 virtual const SwRect
* ToCharRect() const;
117 virtual SwTwips
ToCharTopOfLine() const;
119 /** helper method to determine top of a frame for the vertical object
124 SwTwips
GetTopForObjPos( const SwFrame
& _rFrame
,
125 const SwRectFn
& _fnRect
,
126 const bool _bVert
) const;
128 void GetVertAlignmentValues( const SwFrame
& _rVertOrientFrame
,
129 const SwFrame
& _rPageAlignLayFrame
,
130 const sal_Int16 _eRelOrient
,
131 SwTwips
& _orAlignAreaHeight
,
132 SwTwips
& _orAlignAreaOffset
) const;
134 // #i26791# - add output parameter <_roVertOffsetToFrameAnchorPos>
135 SwTwips
GetVertRelPos( const SwFrame
& _rVertOrientFrame
,
136 const SwFrame
& _rPageAlignLayFrame
,
137 const sal_Int16 _eVertOrient
,
138 const sal_Int16 _eRelOrient
,
139 const SwTwips _nVertPos
,
140 const SvxLRSpaceItem
& _rLRSpacing
,
141 const SvxULSpaceItem
& _rULSpacing
,
142 SwTwips
& _roVertOffsetToFrameAnchorPos
) const;
144 /** adjust calculated vertical in order to keep object inside
145 'page' alignment layout frame.
147 #i31805# - add parameter <_bCheckBottom>
148 #i26945# - add parameter <_bFollowTextFlow>
149 #i62875# - made inline, intrinsic actions moved
150 to private method <ImplAdjustVertRelPos>, which is only
151 called, if <mbDoNotCaptureAnchoredObj> not set.
152 OD 2009-09-01 #mongolianlayout# - add parameter <bVertL2R>
155 input parameter - 'vertical' position, at which the relative
156 position of the object is calculated from.
159 input parameter - boolean, indicating, if object is in vertical
163 input parameter - boolean, indicating, if object is in mongolian
164 layout (vertical left-to-right layout).
166 @param rPageAlignLayFrame
167 input parameter - layout frame, which determines the 'page area'
168 the object has to be vertical positioned in.
170 @param nProposedRelPosY
171 input parameter - proposed relative vertical position, which
174 @param bFollowTextFlow
175 input parameter - value of attribute 'Follow text flow' of the
179 input parameter - boolean indicating, if bottom of anchored
180 object has to be checked and thus, (if needed) the proposed
181 relative position has to be adjusted. default value <true>
183 SwTwips
AdjustVertRelPos( const SwTwips nTopOfAnch
,
186 const SwFrame
& rPageAlignLayFrame
,
187 const SwTwips nProposedRelPosY
,
188 const bool bFollowTextFlow
,
189 const bool bCheckBottom
= true ) const
191 return !mbDoNotCaptureAnchoredObj
192 ? ImplAdjustVertRelPos( nTopOfAnch
, bVert
, bVertL2R
,
200 /** calculate relative horizontal position
202 #i26791# - add output parameter
203 <_roHoriOffsetToFrameAnchorPos>
205 @param _rHoriOrientFrame
206 input parameter - frame the horizontal position of the object
210 input parameter - object instance to retrieve environment
211 information about the object
214 input parameter - horizontal positioning and alignment, for which
215 the relative position is calculated.
218 input parameter - left and right spacing of the object to the text
221 input parameter - upper and lower spacing of the object to the text
223 @param _bObjWrapThrough
224 input parameter - boolean indicating, if object has wrap mode
228 input parameter - relative vertical position
230 @param _roHoriOffsetToFrameAnchorPos
231 output parameter - 'horizontal' offset to frame anchor position
232 according to the alignment
234 @return relative horizontal position in SwTwips
236 SwTwips
CalcRelPosX( const SwFrame
& _rHoriOrientFrame
,
237 const SwEnvironmentOfAnchoredObject
& _rEnvOfObj
,
238 const SwFormatHoriOrient
& _rHoriOrient
,
239 const SvxLRSpaceItem
& _rLRSpacing
,
240 const SvxULSpaceItem
& _rULSpacing
,
241 const bool _bObjWrapThrough
,
242 const SwTwips _nRelPosY
,
243 SwTwips
& _roHoriOffsetToFrameAnchorPos
246 /** adjust calculated horizontal in order to keep object inside
247 'page' alignment layout frame for object type position TO_CNTNT
249 #i62875# - made inline, intrinsic actions moved
250 to private method <ImplAdjustHoriRelPos>, which is only
251 called, if <mbDoNotCaptureAnchoredObj> not set.
253 @param _rPageAlignLayFrame
254 input parameter - layout frame, which determines the 'page area'
255 the object has to be horizontal positioned in.
257 @param _nProposedRelPosX
258 input parameter - proposed relative horizontal position, which
261 @return adjusted relative horizontal position in SwTwips.
263 SwTwips
AdjustHoriRelPos( const SwFrame
& _rPageAlignLayFrame
,
264 const SwTwips _nProposedRelPosX
) const
266 return !mbDoNotCaptureAnchoredObj
267 ? ImplAdjustHoriRelPos( _rPageAlignLayFrame
, _nProposedRelPosX
)
271 /** toggle given horizontal orientation and relative alignment
273 @param _bToggleLeftRight
274 input parameter - boolean indicating, if horizontal orientation
275 and relative alignment has to be toggled.
277 @param _ioeHoriOrient
278 input/output parameter - horizontal orientation, that is toggled,
281 @param _iopeRelOrient
282 optional input/output parameter (default value NULL)
283 - if set, relative alignment, that is toggled, if needed.
285 static void ToggleHoriOrientAndAlign( const bool _bToggleLeftRight
,
286 sal_Int16
& _ioeHoriOrient
,
287 sal_Int16
& _iopeRelOrient
290 /** determine alignment values for horizontal position of object
292 @param _rHoriOrientFrame
293 input parameter - frame the horizontal position of the object
296 @param _rPageAlignLayFrame
297 input parameter - layout frame, which determines the 'page area'
298 the object has to be horizontal positioned in.
301 input parameter - horizontal relative alignment, for which
302 the relative position is calculated.
304 @param _bToggleLeftRight
305 input parameter - boolean indicating, if left/right alignments
308 @param _bObjWrapThrough
309 input parameter - boolean indicating, if object has wrap mode
311 important note: value is only relevant, if _rHoriOrientFrame is
314 @param _orAlignAreaWidth
315 output parameter - width in SwTwips of the area the horizontal
316 position is aligned to.
318 @param _orAlignAreaOffset
319 output parameter - offset in SwTwips of the area the horizontal
320 position is aligned to. offset is given to the 'left' of the
323 @param _obAlignedRelToPage
324 output parameter - boolean indicating, that object is aligned
327 void GetHoriAlignmentValues( const SwFrame
& _rHoriOrientFrame
,
328 const SwFrame
& _rPageAlignLayFrame
,
329 const sal_Int16 _eRelOrient
,
330 const bool _bObjWrapThrough
,
331 SwTwips
& _orAlignAreaWidth
,
332 SwTwips
& _orAlignAreaOffset
,
333 bool& _obAlignedRelToPage
) const;
335 /** adjust calculated horizontal position in order to draw object
336 aside other objects with same positioning
338 @param _rHoriOrientFrame
339 input parameter - frame the horizontal position of the object
342 @param _nProposedRelPosX
343 input parameter - proposed relative horizontal position, which
347 input parameter - relative vertical position
350 input parameter - horizontal position of object
353 input parameter - alignment of object
356 input parameter - left and right spacing of the object to the text
359 input parameter - upper and lower spacing of the object to the text
362 input parameter - boolean indicating, if object is on an even page.
364 @return adjusted relative horizontal position in SwTwips
366 SwTwips
AdjustHoriRelPosForDrawAside( const SwFrame
& _rHoriOrientFrame
,
367 const SwTwips _nProposedRelPosX
,
368 const SwTwips _nRelPosY
,
369 const sal_Int16 _eHoriOrient
,
370 const sal_Int16 _eRelOrient
,
371 const SvxLRSpaceItem
& _rLRSpacing
,
372 const SvxULSpaceItem
& _rULSpacing
,
373 const bool _bEvenPage
376 /** determine, if object has to draw aside given fly frame
378 method used by <AdjustHoriRelPosForDrawAside(..)>
381 input parameter - fly frame the draw aside check is done for.
384 input parameter - proposed object rectangle
387 input parameter - context of the object
390 input parameter - index of the anchor frame of the object
393 input parameter - boolean indicating, if object is on an even page.
396 input parameter - horizontal position of object
399 input parameter - alignment of object
401 @return boolean indicating, if object has to be drawn aside
404 bool DrawAsideFly( const SwFlyFrame
* _pFly
,
405 const SwRect
& _rObjRect
,
406 const SwFrame
* _pObjContext
,
407 const SwNodeOffset _nObjIndex
,
408 const bool _bEvenPage
,
409 const sal_Int16 _eHoriOrient
,
410 const sal_Int16 _eRelOrient
413 /** determine, if object has to draw aside another object
415 the different alignments of the objects determines, if one has
416 to draw aside another one. Thus, the given alignment are checked
417 against each other, which one has to be drawn aside the other one.
418 depending on parameter _bLeft check is done for left or right
420 method used by <DrawAsideFly(..)>
423 input parameter - alignment 1
426 input parameter - alignment 2
429 input parameter - boolean indicating, if check is done for left
430 or for right positioning.
432 @return boolean indicating, if an object with an alignment
433 <_eRelOrient1> has to be drawn aside an object with an
434 alignment <_eRelOrient2>
436 static bool Minor_( sal_Int16 _eRelOrient1
,
437 sal_Int16 _eRelOrient2
,
441 virtual void CalcPosition() = 0;
447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */