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 <fmtornt.hxx>
24 #include <swtypes.hxx>
26 #include <nodeoffset.hxx>
35 class SwFormatHoriOrient
;
36 class SwAnchoredObject
;
38 namespace objectpositioning
40 class SwEnvironmentOfAnchoredObject
;
42 class SwAnchoredObjectPosition
45 // object to be positioned
47 // #i26791# - anchored object the object belongs to;
48 SwAnchoredObject
* mpAnchoredObj
;
49 // frame the object is anchored at
50 SwFrame
* mpAnchorFrame
;
54 const SwFrameFormat
* mpFrameFormat
;
55 // does the object represents a Writer fly frame
58 bool mbFollowTextFlow
;
60 // for compatibility option <DoNotCaptureDrawObjsOnPage>
61 bool mbDoNotCaptureAnchoredObj
;
63 /** determine information about object
65 member <mbIsObjFly>, <mpAnchoredObj>, <mpAnchorFrame>, <mpContact>
66 and <mpFrameFormat> are set
68 void GetInfoAboutObj();
71 // --> OD 2009-09-01 #mongolianlayout# - add parameter <bVertL2R>
72 SwTwips
ImplAdjustVertRelPos( const SwTwips nTopOfAnch
,
75 const SwFrame
& rPageAlignLayFrame
,
76 const SwFormatVertOrient
& rVertOrient
,
77 const SwTwips nProposedRelPosY
,
78 const bool bFollowTextFlow
,
79 const bool bCheckBottom
) const;
80 SwTwips
ImplAdjustHoriRelPos( const SwFrame
& _rPageAlignLayFrame
,
81 const SwTwips _nProposedRelPosX
) const;
84 SwAnchoredObjectPosition( SdrObject
& _rDrawObj
);
85 virtual ~SwAnchoredObjectPosition();
87 // accessors for object and its corresponding data/information
88 SdrObject
& GetObject() const
96 SwAnchoredObject
& GetAnchoredObj() const
98 return *mpAnchoredObj
;
100 SwFrame
& GetAnchorFrame() const
102 return *mpAnchorFrame
;
104 const SwFrameFormat
& GetFrameFormat() const
106 return *mpFrameFormat
;
109 bool DoesObjFollowsTextFlow() const
111 return mbFollowTextFlow
;
114 // virtual methods providing data for to character anchored objects.
115 virtual bool IsAnchoredToChar() const;
116 virtual const SwFrame
* ToCharOrientFrame() const;
117 virtual const SwRect
* ToCharRect() const;
119 virtual SwTwips
ToCharTopOfLine() const;
121 /** helper method to determine top of a frame for the vertical object
126 SwTwips
GetTopForObjPos( const SwFrame
& _rFrame
,
127 const SwRectFn
& _fnRect
,
128 const bool _bVert
) const;
130 void GetVertAlignmentValues( const SwFrame
& _rVertOrientFrame
,
131 const SwFrame
& _rPageAlignLayFrame
,
132 const sal_Int16 _eRelOrient
,
133 SwTwips
& _orAlignAreaHeight
,
134 SwTwips
& _orAlignAreaOffset
) const;
136 // #i26791# - add output parameter <_roVertOffsetToFrameAnchorPos>
137 SwTwips
GetVertRelPos( const SwFrame
& _rVertOrientFrame
,
138 const SwFrame
& _rPageAlignLayFrame
,
139 const sal_Int16 _eVertOrient
,
140 const sal_Int16 _eRelOrient
,
141 const SwTwips _nVertPos
,
142 const SvxLRSpaceItem
& _rLRSpacing
,
143 const SvxULSpaceItem
& _rULSpacing
,
144 SwTwips
& _roVertOffsetToFrameAnchorPos
) const;
146 /** adjust calculated vertical in order to keep object inside
147 'page' alignment layout frame.
149 #i31805# - add parameter <_bCheckBottom>
150 #i26945# - add parameter <_bFollowTextFlow>
151 #i62875# - made inline, intrinsic actions moved
152 to private method <ImplAdjustVertRelPos>, which is only
153 called, if <mbDoNotCaptureAnchoredObj> not set.
154 OD 2009-09-01 #mongolianlayout# - add parameter <bVertL2R>
157 input parameter - 'vertical' position, at which the relative
158 position of the object is calculated from.
161 input parameter - boolean, indicating, if object is in vertical
165 input parameter - boolean, indicating, if object is in mongolian
166 layout (vertical left-to-right layout).
168 @param rPageAlignLayFrame
169 input parameter - layout frame, which determines the 'page area'
170 the object has to be vertical positioned in.
172 @param nProposedRelPosY
173 input parameter - proposed relative vertical position, which
176 @param bFollowTextFlow
177 input parameter - value of attribute 'Follow text flow' of the
181 input parameter - boolean indicating, if bottom of anchored
182 object has to be checked and thus, (if needed) the proposed
183 relative position has to be adjusted. default value <true>
185 SwTwips
AdjustVertRelPos( const SwTwips nTopOfAnch
,
188 const SwFrame
& rPageAlignLayFrame
,
189 const SwFormatVertOrient
& rVertOrient
,
190 const SwTwips nProposedRelPosY
,
191 const bool bFollowTextFlow
,
192 const bool bCheckBottom
= true ) const
194 return !mbDoNotCaptureAnchoredObj
195 ? ImplAdjustVertRelPos( nTopOfAnch
, bVert
, bVertL2R
,
204 /** calculate relative horizontal position
206 #i26791# - add output parameter
207 <_roHoriOffsetToFrameAnchorPos>
209 @param _rHoriOrientFrame
210 input parameter - frame the horizontal position of the object
214 input parameter - object instance to retrieve environment
215 information about the object
218 input parameter - horizontal positioning and alignment, for which
219 the relative position is calculated.
222 input parameter - left and right spacing of the object to the text
225 input parameter - upper and lower spacing of the object to the text
227 @param _bObjWrapThrough
228 input parameter - boolean indicating, if object has wrap mode
232 input parameter - relative vertical position
234 @param _roHoriOffsetToFrameAnchorPos
235 output parameter - 'horizontal' offset to frame anchor position
236 according to the alignment
238 @return relative horizontal position in SwTwips
240 SwTwips
CalcRelPosX( const SwFrame
& _rHoriOrientFrame
,
241 const SwEnvironmentOfAnchoredObject
& _rEnvOfObj
,
242 const SwFormatHoriOrient
& _rHoriOrient
,
243 const SvxLRSpaceItem
& _rLRSpacing
,
244 const SvxULSpaceItem
& _rULSpacing
,
245 const bool _bObjWrapThrough
,
246 const SwTwips _nRelPosY
,
247 SwTwips
& _roHoriOffsetToFrameAnchorPos
250 /** adjust calculated horizontal in order to keep object inside
251 'page' alignment layout frame for object type position TO_CNTNT
253 #i62875# - made inline, intrinsic actions moved
254 to private method <ImplAdjustHoriRelPos>, which is only
255 called, if <mbDoNotCaptureAnchoredObj> not set.
257 @param _rPageAlignLayFrame
258 input parameter - layout frame, which determines the 'page area'
259 the object has to be horizontal positioned in.
261 @param _nProposedRelPosX
262 input parameter - proposed relative horizontal position, which
265 @return adjusted relative horizontal position in SwTwips.
267 SwTwips
AdjustHoriRelPos( const SwFrame
& _rPageAlignLayFrame
,
268 const SwTwips _nProposedRelPosX
) const
270 return !mbDoNotCaptureAnchoredObj
271 ? ImplAdjustHoriRelPos( _rPageAlignLayFrame
, _nProposedRelPosX
)
275 /** toggle given horizontal orientation and relative alignment
277 @param _bToggleLeftRight
278 input parameter - boolean indicating, if horizontal orientation
279 and relative alignment has to be toggled.
281 @param _ioeHoriOrient
282 input/output parameter - horizontal orientation, that is toggled,
285 @param _iopeRelOrient
286 optional input/output parameter (default value NULL)
287 - if set, relative alignment, that is toggled, if needed.
289 static void ToggleHoriOrientAndAlign( const bool _bToggleLeftRight
,
290 sal_Int16
& _ioeHoriOrient
,
291 sal_Int16
& _iopeRelOrient
294 /** determine alignment values for horizontal position of object
296 @param _rHoriOrientFrame
297 input parameter - frame the horizontal position of the object
300 @param _rPageAlignLayFrame
301 input parameter - layout frame, which determines the 'page area'
302 the object has to be horizontal positioned in.
305 input parameter - horizontal relative alignment, for which
306 the relative position is calculated.
308 @param _bToggleLeftRight
309 input parameter - boolean indicating, if left/right alignments
312 @param _bObjWrapThrough
313 input parameter - boolean indicating, if object has wrap mode
315 important note: value is only relevant, if _rHoriOrientFrame is
318 @param _orAlignAreaWidth
319 output parameter - width in SwTwips of the area the horizontal
320 position is aligned to.
322 @param _orAlignAreaOffset
323 output parameter - offset in SwTwips of the area the horizontal
324 position is aligned to. offset is given to the 'left' of the
327 @param _obAlignedRelToPage
328 output parameter - boolean indicating, that object is aligned
331 void GetHoriAlignmentValues( const SwFrame
& _rHoriOrientFrame
,
332 const SwFrame
& _rPageAlignLayFrame
,
333 const sal_Int16 _eRelOrient
,
334 const bool _bObjWrapThrough
,
335 SwTwips
& _orAlignAreaWidth
,
336 SwTwips
& _orAlignAreaOffset
,
337 bool& _obAlignedRelToPage
) const;
339 /** adjust calculated horizontal position in order to draw object
340 aside other objects with same positioning
342 @param _rHoriOrientFrame
343 input parameter - frame the horizontal position of the object
346 @param _nProposedRelPosX
347 input parameter - proposed relative horizontal position, which
351 input parameter - relative vertical position
354 input parameter - horizontal position of object
357 input parameter - alignment of object
360 input parameter - left and right spacing of the object to the text
363 input parameter - upper and lower spacing of the object to the text
366 input parameter - boolean indicating, if object is on an even page.
368 @return adjusted relative horizontal position in SwTwips
370 SwTwips
AdjustHoriRelPosForDrawAside( const SwFrame
& _rHoriOrientFrame
,
371 const SwTwips _nProposedRelPosX
,
372 const SwTwips _nRelPosY
,
373 const sal_Int16 _eHoriOrient
,
374 const sal_Int16 _eRelOrient
,
375 const SvxLRSpaceItem
& _rLRSpacing
,
376 const SvxULSpaceItem
& _rULSpacing
,
377 const bool _bEvenPage
380 /** determine, if object has to draw aside given fly frame
382 method used by <AdjustHoriRelPosForDrawAside(..)>
385 input parameter - fly frame the draw aside check is done for.
388 input parameter - proposed object rectangle
391 input parameter - context of the object
394 input parameter - index of the anchor frame of the object
397 input parameter - boolean indicating, if object is on an even page.
400 input parameter - horizontal position of object
403 input parameter - alignment of object
405 @return boolean indicating, if object has to be drawn aside
408 bool DrawAsideFly( const SwFlyFrame
* _pFly
,
409 const SwRect
& _rObjRect
,
410 const SwFrame
* _pObjContext
,
411 const SwNodeOffset _nObjIndex
,
412 const bool _bEvenPage
,
413 const sal_Int16 _eHoriOrient
,
414 const sal_Int16 _eRelOrient
417 /** determine, if object has to draw aside another object
419 the different alignments of the objects determines, if one has
420 to draw aside another one. Thus, the given alignment are checked
421 against each other, which one has to be drawn aside the other one.
422 depending on parameter _bLeft check is done for left or right
424 method used by <DrawAsideFly(..)>
427 input parameter - alignment 1
430 input parameter - alignment 2
433 input parameter - boolean indicating, if check is done for left
434 or for right positioning.
436 @return boolean indicating, if an object with an alignment
437 <_eRelOrient1> has to be drawn aside an object with an
438 alignment <_eRelOrient2>
440 static bool Minor_( sal_Int16 _eRelOrient1
,
441 sal_Int16 _eRelOrient2
,
445 virtual void CalcPosition() = 0;
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */