Add a comment to clarify what kind of inputs the class handles
[LibreOffice.git] / sw / source / core / inc / anchoredobjectposition.hxx
blob2d87b5bde9bdaf23e8cb1331398cceb921acc363
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include "frame.hxx"
26 #include <nodeoffset.hxx>
28 class SdrObject;
29 class SwFlyFrame;
30 class SwContact;
31 class SwFrameFormat;
32 class SwRect;
33 class SvxLRSpaceItem;
34 class SvxULSpaceItem;
35 class SwFormatHoriOrient;
36 class SwAnchoredObject;
38 namespace objectpositioning
40 class SwEnvironmentOfAnchoredObject;
42 class SwAnchoredObjectPosition
44 private:
45 // object to be positioned
46 SdrObject& mrDrawObj;
47 // #i26791# - anchored object the object belongs to;
48 SwAnchoredObject* mpAnchoredObj;
49 // frame the object is anchored at
50 SwFrame* mpAnchorFrame;
51 // contact object
52 SwContact* mpContact;
53 // frame format
54 const SwFrameFormat* mpFrameFormat;
55 // does the object represents a Writer fly frame
56 bool mbIsObjFly;
57 // #i62875#
58 bool mbFollowTextFlow;
59 // #i62875#
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();
70 // #i62875#
71 // --> OD 2009-09-01 #mongolianlayout# - add parameter <bVertL2R>
72 SwTwips ImplAdjustVertRelPos( const SwTwips nTopOfAnch,
73 const bool bVert,
74 const bool bVertL2R,
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;
83 protected:
84 SwAnchoredObjectPosition( SdrObject& _rDrawObj );
85 virtual ~SwAnchoredObjectPosition();
87 // accessors for object and its corresponding data/information
88 SdrObject& GetObject() const
90 return mrDrawObj;
92 bool IsObjFly() const
94 return mbIsObjFly;
96 SwAnchoredObject& GetAnchoredObj() const
98 return *mpAnchoredObj;
100 SwFrame& GetAnchorFrame() const
102 return *mpAnchorFrame;
104 const SwFrameFormat& GetFrameFormat() const
106 return *mpFrameFormat;
108 // #i62875#
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;
118 // #i22341#
119 virtual SwTwips ToCharTopOfLine() const;
121 /** helper method to determine top of a frame for the vertical object
122 positioning
124 #i11860#
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>
156 @param nTopOfAnch
157 input parameter - 'vertical' position, at which the relative
158 position of the object is calculated from.
160 @param bVert
161 input parameter - boolean, indicating, if object is in vertical
162 layout.
164 @param bVertL2R
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
174 will be adjusted.
176 @param bFollowTextFlow
177 input parameter - value of attribute 'Follow text flow' of the
178 anchored object.
180 @param bCheckBottom
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,
186 const bool bVert,
187 const bool bVertL2R,
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,
196 rPageAlignLayFrame,
197 rVertOrient,
198 nProposedRelPosY,
199 bFollowTextFlow,
200 bCheckBottom )
201 : nProposedRelPosY;
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
211 is oriented at.
213 @param _rEnvOfObj
214 input parameter - object instance to retrieve environment
215 information about the object
217 @param _rHoriOrient
218 input parameter - horizontal positioning and alignment, for which
219 the relative position is calculated.
221 @param _rLRSpacing
222 input parameter - left and right spacing of the object to the text
224 @param _rULSpacing
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
229 'wrap through'.
231 @param _nRelPosY
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
248 ) const;
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
263 will be adjusted.
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 )
272 : _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,
283 if needed.
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
298 is oriented at.
300 @param _rPageAlignLayFrame
301 input parameter - layout frame, which determines the 'page area'
302 the object has to be horizontal positioned in.
304 @param _eRelOrient
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
310 have to be toggled.
312 @param _bObjWrapThrough
313 input parameter - boolean indicating, if object has wrap mode
314 'wrap through'.
315 important note: value is only relevant, if _rHoriOrientFrame is
316 a text frame.
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
325 anchor position.
327 @param _obAlignedRelToPage
328 output parameter - boolean indicating, that object is aligned
329 to 'page area'.
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
344 is oriented at.
346 @param _nProposedRelPosX
347 input parameter - proposed relative horizontal position, which
348 will be adjusted.
350 @param _nRelPosY
351 input parameter - relative vertical position
353 @param _eHoriOrient
354 input parameter - horizontal position of object
356 @param _eRelOrient
357 input parameter - alignment of object
359 @param _rLRSpacing
360 input parameter - left and right spacing of the object to the text
362 @param _rULSpacing
363 input parameter - upper and lower spacing of the object to the text
365 @param _bEvenPage
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
378 ) const;
380 /** determine, if object has to draw aside given fly frame
382 method used by <AdjustHoriRelPosForDrawAside(..)>
384 @param _pFly
385 input parameter - fly frame the draw aside check is done for.
387 @param _rObjRect
388 input parameter - proposed object rectangle
390 @param _pObjContext
391 input parameter - context of the object
393 @param _nObjIndex
394 input parameter - index of the anchor frame of the object
396 @param _bEvenPage
397 input parameter - boolean indicating, if object is on an even page.
399 @param _eHoriOrient
400 input parameter - horizontal position of object
402 @param _eRelOrient
403 input parameter - alignment of object
405 @return boolean indicating, if object has to be drawn aside
406 given fly frame.
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
415 ) const;
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
423 positioning.
424 method used by <DrawAsideFly(..)>
426 @param _eRelOrient1
427 input parameter - alignment 1
429 @param _eRelOrient2
430 input parameter - alignment 2
432 @param _bLeft
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,
442 bool _bLeft );
444 public:
445 virtual void CalcPosition() = 0;
449 #endif
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */