Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / inc / anchoredobjectposition.hxx
bloba3668330006e8f15f3ac663afc2786d15dd12c65
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 <swtypes.hxx>
24 #include "frame.hxx"
25 #include <nodeoffset.hxx>
27 class SdrObject;
28 class SwFlyFrame;
29 class SwContact;
30 class SwFrameFormat;
31 class SwRect;
32 class SvxLRSpaceItem;
33 class SvxULSpaceItem;
34 class SwFormatHoriOrient;
35 class SwAnchoredObject;
37 namespace objectpositioning
39 class SwEnvironmentOfAnchoredObject;
41 class SwAnchoredObjectPosition
43 private:
44 // object to be positioned
45 SdrObject& mrDrawObj;
46 // #i26791# - anchored object the object belongs to;
47 SwAnchoredObject* mpAnchoredObj;
48 // frame the object is anchored at
49 SwFrame* mpAnchorFrame;
50 // contact object
51 SwContact* mpContact;
52 // frame format
53 const SwFrameFormat* mpFrameFormat;
54 // does the object represents a Writer fly frame
55 bool mbIsObjFly;
56 // #i62875#
57 bool mbFollowTextFlow;
58 // #i62875#
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();
69 // #i62875#
70 // --> OD 2009-09-01 #mongolianlayout# - add parameter <bVertL2R>
71 SwTwips ImplAdjustVertRelPos( const SwTwips nTopOfAnch,
72 const bool bVert,
73 const bool bVertL2R,
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;
81 protected:
82 SwAnchoredObjectPosition( SdrObject& _rDrawObj );
83 virtual ~SwAnchoredObjectPosition();
85 // accessors for object and its corresponding data/information
86 SdrObject& GetObject() const
88 return mrDrawObj;
90 bool IsObjFly() const
92 return mbIsObjFly;
94 SwAnchoredObject& GetAnchoredObj() const
96 return *mpAnchoredObj;
98 SwFrame& GetAnchorFrame() const
100 return *mpAnchorFrame;
102 const SwFrameFormat& GetFrameFormat() const
104 return *mpFrameFormat;
106 // #i62875#
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;
116 // #i22341#
117 virtual SwTwips ToCharTopOfLine() const;
119 /** helper method to determine top of a frame for the vertical object
120 positioning
122 #i11860#
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>
154 @param nTopOfAnch
155 input parameter - 'vertical' position, at which the relative
156 position of the object is calculated from.
158 @param bVert
159 input parameter - boolean, indicating, if object is in vertical
160 layout.
162 @param bVertL2R
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
172 will be adjusted.
174 @param bFollowTextFlow
175 input parameter - value of attribute 'Follow text flow' of the
176 anchored object.
178 @param bCheckBottom
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,
184 const bool bVert,
185 const bool bVertL2R,
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,
193 rPageAlignLayFrame,
194 nProposedRelPosY,
195 bFollowTextFlow,
196 bCheckBottom )
197 : nProposedRelPosY;
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
207 is oriented at.
209 @param _rEnvOfObj
210 input parameter - object instance to retrieve environment
211 information about the object
213 @param _rHoriOrient
214 input parameter - horizontal positioning and alignment, for which
215 the relative position is calculated.
217 @param _rLRSpacing
218 input parameter - left and right spacing of the object to the text
220 @param _rULSpacing
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
225 'wrap through'.
227 @param _nRelPosY
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
244 ) const;
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
259 will be adjusted.
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 )
268 : _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,
279 if needed.
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
294 is oriented at.
296 @param _rPageAlignLayFrame
297 input parameter - layout frame, which determines the 'page area'
298 the object has to be horizontal positioned in.
300 @param _eRelOrient
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
306 have to be toggled.
308 @param _bObjWrapThrough
309 input parameter - boolean indicating, if object has wrap mode
310 'wrap through'.
311 important note: value is only relevant, if _rHoriOrientFrame is
312 a text frame.
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
321 anchor position.
323 @param _obAlignedRelToPage
324 output parameter - boolean indicating, that object is aligned
325 to 'page area'.
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
340 is oriented at.
342 @param _nProposedRelPosX
343 input parameter - proposed relative horizontal position, which
344 will be adjusted.
346 @param _nRelPosY
347 input parameter - relative vertical position
349 @param _eHoriOrient
350 input parameter - horizontal position of object
352 @param _eRelOrient
353 input parameter - alignment of object
355 @param _rLRSpacing
356 input parameter - left and right spacing of the object to the text
358 @param _rULSpacing
359 input parameter - upper and lower spacing of the object to the text
361 @param _bEvenPage
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
374 ) const;
376 /** determine, if object has to draw aside given fly frame
378 method used by <AdjustHoriRelPosForDrawAside(..)>
380 @param _pFly
381 input parameter - fly frame the draw aside check is done for.
383 @param _rObjRect
384 input parameter - proposed object rectangle
386 @param _pObjContext
387 input parameter - context of the object
389 @param _nObjIndex
390 input parameter - index of the anchor frame of the object
392 @param _bEvenPage
393 input parameter - boolean indicating, if object is on an even page.
395 @param _eHoriOrient
396 input parameter - horizontal position of object
398 @param _eRelOrient
399 input parameter - alignment of object
401 @return boolean indicating, if object has to be drawn aside
402 given fly frame.
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
411 ) const;
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
419 positioning.
420 method used by <DrawAsideFly(..)>
422 @param _eRelOrient1
423 input parameter - alignment 1
425 @param _eRelOrient2
426 input parameter - alignment 2
428 @param _bLeft
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,
438 bool _bLeft );
440 public:
441 virtual void CalcPosition() = 0;
445 #endif
447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */