1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: anchoredobjectposition.hxx,v $
10 * $Revision: 1.12.214.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _ANCHOREDOBJECTPOSITION_HXX
31 #define _ANCHOREDOBJECTPOSITION_HXX
33 #include <swtypes.hxx>
34 // OD 2004-03-16 #i11860#
45 class SwFmtHoriOrient
;
46 // OD 2004-03-23 #i26701#
47 class SwAnchoredObject
;
49 namespace objectpositioning
51 class SwEnvironmentOfAnchoredObject
;
53 class SwAnchoredObjectPosition
56 // object to be positioned
59 // information about object
60 // does the object represents a Writer fly frame
62 // OD 2004-03-23 #i26791# - anchored object the object belongs to;
63 SwAnchoredObject
* mpAnchoredObj
;
64 // frame the object is anchored at
69 const SwFrmFmt
* mpFrmFmt
;
70 // --> OD 2006-03-15 #i62875#
71 bool mbFollowTextFlow
;
73 // --> OD 2006-03-15 #i62875#
74 // for compatibility option <DoNotCaptureDrawObjsOnPage>
75 bool mbDoNotCaptureAnchoredObj
;
78 /** determine information about object
80 OD 30.07.2003 #110978#
81 member <mbIsObjFly>, <mpAnchoredObj>, <mpAnchorFrm>, <mpContact>
82 and <mpFrmFmt> are set
86 void _GetInfoAboutObj();
88 // --> OD 2006-03-15 #i62875#
89 SwTwips
_ImplAdjustVertRelPos( const SwTwips _nTopOfAnch
,
91 const SwFrm
& _rPageAlignLayFrm
,
92 const SwTwips _nProposedRelPosY
,
93 const bool _bFollowTextFlow
,
94 const bool _bCheckBottom
= true ) const;
95 SwTwips
_ImplAdjustHoriRelPos( const SwFrm
& _rPageAlignLayFrm
,
96 const SwTwips _nProposedRelPosX
) const;
100 SwAnchoredObjectPosition( SdrObject
& _rDrawObj
);
101 virtual ~SwAnchoredObjectPosition();
103 // accessors for object and its corresponding data/information
104 inline SdrObject
& GetObject() const
108 inline bool IsObjFly() const
112 inline SwAnchoredObject
& GetAnchoredObj() const
114 return *mpAnchoredObj
;
116 inline SwFrm
& GetAnchorFrm() const
120 inline SwContact
& GetContact() const
124 inline const SwFrmFmt
& GetFrmFmt() const
128 // --> OD 2006-03-15 #i62875#
129 inline bool DoesObjFollowsTextFlow() const
131 return mbFollowTextFlow
;
135 // virtual methods providing data for to character anchored objects.
136 virtual bool IsAnchoredToChar() const;
137 virtual const SwFrm
* ToCharOrientFrm() const;
138 virtual const SwRect
* ToCharRect() const;
139 // OD 12.11.2003 #i22341#
140 virtual SwTwips
ToCharTopOfLine() const;
142 // *********************************************************************
143 /** helper method to determine top of a frame for the vertical
146 OD 2004-03-11 #i11860#
150 SwTwips
_GetTopForObjPos( const SwFrm
& _rFrm
,
151 const SwRectFn
& _fnRect
,
152 const bool _bVert
) const;
154 // *********************************************************************
155 void _GetVertAlignmentValues( const SwFrm
& _rVertOrientFrm
,
156 const SwFrm
& _rPageAlignLayFrm
,
157 const sal_Int16 _eRelOrient
,
158 SwTwips
& _orAlignAreaHeight
,
159 SwTwips
& _orAlignAreaOffset
) const;
161 // *********************************************************************
162 // --> OD 2004-06-17 #i26791# - add output parameter <_roVertOffsetToFrmAnchorPos>
163 SwTwips
_GetVertRelPos( const SwFrm
& _rVertOrientFrm
,
164 const SwFrm
& _rPageAlignLayFrm
,
165 const sal_Int16 _eVertOrient
,
166 const sal_Int16 _eRelOrient
,
167 const SwTwips _nVertPos
,
168 const SvxLRSpaceItem
& _rLRSpacing
,
169 const SvxULSpaceItem
& _rULSpacing
,
170 SwTwips
& _roVertOffsetToFrmAnchorPos
) const;
172 // *********************************************************************
173 /** adjust calculated vertical in order to keep object inside
174 'page' alignment layout frame.
176 OD 2004-07-22 #i31805# - add parameter <_bCheckBottom>
177 OD 2004-10-08 #i26945# - add parameter <_bFollowTextFlow>
178 OD 2006-03-15 #i62875# - made inline, intrinsic actions moved
179 to private method <_ImplAdjustVertRelPos>, which is only
180 called, if <mbDoNotCaptureAnchoredObj> not set.
183 input parameter - 'vertical' position, at which the relative
184 position of the object is calculated from.
187 input parameter - boolean, indicating, if object is in vertical
190 @param _rPageAlignLayFrm
191 input parameter - layout frame, which determines the 'page area'
192 the object has to be vertical positioned in.
194 @param _nProposedRelPosY
195 input parameter - proposed relative vertical position, which
198 @param _bFollowTextFlow
199 input parameter - value of attribute 'Follow text flow' of the
203 input parameter - boolean indicating, if bottom of anchored
204 object has to be checked and thus, (if needed) the proposed
205 relative position has to be adjusted. default value <true>
209 inline SwTwips
_AdjustVertRelPos( const SwTwips _nTopOfAnch
,
211 const SwFrm
& _rPageAlignLayFrm
,
212 const SwTwips _nProposedRelPosY
,
213 const bool _bFollowTextFlow
,
214 const bool _bCheckBottom
= true ) const
216 return !mbDoNotCaptureAnchoredObj
217 ? _ImplAdjustVertRelPos( _nTopOfAnch
, _bVert
,
225 // *********************************************************************
226 /** calculate relative horizontal position
228 --> OD 2004-06-17 #i26791# - add output parameter
229 <_roHoriOffsetToFrmAnchorPos>
233 @param _rHoriOrientFrm
234 input parameter - frame the horizontal position of the object
238 input parameter - object instance to retrieve environment
239 information about the object
242 input parameter - horizontal positioning and alignment, for which
243 the relative position is calculated.
246 input parameter - left and right spacing of the object to the text
249 input parameter - upper and lower spacing of the object to the text
251 @param _bObjWrapThrough
252 input parameter - boolean indicating, if object has wrap mode
256 input parameter - relative vertical position
258 @param _roHoriOffsetToFrmAnchorPos
259 output parameter - 'horizontal' offset to frame anchor position
260 according to the alignment
262 @return relative horizontal position in SwTwips
264 SwTwips
_CalcRelPosX( const SwFrm
& _rHoriOrientFrm
,
265 const SwEnvironmentOfAnchoredObject
& _rEnvOfObj
,
266 const SwFmtHoriOrient
& _rHoriOrient
,
267 const SvxLRSpaceItem
& _rLRSpacing
,
268 const SvxULSpaceItem
& _rULSpacing
,
269 const bool _bObjWrapThrough
,
270 const SwTwips _nRelPosY
,
271 SwTwips
& _roHoriOffsetToFrmAnchorPos
274 // *********************************************************************
275 /** adjust calculated horizontal in order to keep object inside
276 'page' alignment layout frame for object type position TO_CNTNT
278 OD 2006-03-15 #i62875# - made inline, intrinsic actions moved
279 to private method <_ImplAdjustHoriRelPos>, which is only
280 called, if <mbDoNotCaptureAnchoredObj> not set.
284 @param _rPageAlignLayFrm
285 input paramter - layout frame, which determines the 'page area'
286 the object has to be horizontal positioned in.
288 @param _nProposedRelPosX
289 input parameter - proposed relative horizontal position, which
292 @return adjusted relative horizontal position in SwTwips.
294 inline SwTwips
_AdjustHoriRelPos( const SwFrm
& _rPageAlignLayFrm
,
295 const SwTwips _nProposedRelPosX
) const
297 return !mbDoNotCaptureAnchoredObj
298 ? _ImplAdjustHoriRelPos( _rPageAlignLayFrm
, _nProposedRelPosX
)
302 // *********************************************************************
303 /** toggle given horizontal orientation and relative alignment
307 @param _bToggleLeftRight
308 input parameter - boolean indicating, if horizontal orientation
309 and relative alignment has to be toggled.
311 @param _ioeHoriOrient
312 input/output parameter - horizontal orientation, that is toggled,
315 @param _iopeRelOrient
316 optional input/output parameter (default value NULL)
317 - if set, relative alignment, that is toggled, if needed.
319 void _ToggleHoriOrientAndAlign( const bool _bToggleLeftRight
,
320 sal_Int16
& _ioeHoriOrient
,
321 sal_Int16
& _iopeRelOrient
324 // *********************************************************************
325 /** determine alignment values for horizontal position of object
329 @param _rHoriOrientFrm
330 input parameter - frame the horizontal position of the object
333 @param _rPageAlignLayFrm
334 input paramter - layout frame, which determines the 'page area'
335 the object has to be horizontal positioned in.
338 input parameter - horizontal relative alignment, for which
339 the relative position is calculated.
341 @param _bToggleLeftRight
342 input parameter - boolean indicating, if left/right alignments
345 @param _bObjWrapThrough
346 input parameter - boolean indicating, if object has wrap mode
348 important note: value is only relevant, if _rHoriOrientFrm is
351 @param _orAlignAreaWidth
352 output parameter - width in SwTwips of the area the horizontal
353 position is aligned to.
355 @param _orAlignAreaOffset
356 output parameter - offset in SwTwips of the area the horizontal
357 position is aligned to. offset is given to the 'left' of the
360 @param _obAlignedRelToPage
361 output parameter - boolean indicating, that object is aligned
364 void _GetHoriAlignmentValues( const SwFrm
& _rHoriOrientFrm
,
365 const SwFrm
& _rPageAlignLayFrm
,
366 const sal_Int16 _eRelOrient
,
367 const bool _bObjWrapThrough
,
368 SwTwips
& _orAlignAreaWidth
,
369 SwTwips
& _orAlignAreaOffset
,
370 bool& _obAlignedRelToPage
) const;
372 // *********************************************************************
373 /** adjust calculated horizontal position in order to draw object
374 aside other objects with same positioning
378 @param _rHoriOrientFrm
379 input parameter - frame the horizontal position of the object
382 @param _nProposedRelPosX
383 input parameter - proposed relative horizontal position, which
387 input parameter - relative vertical position
390 input parameter - horizontal position of object
393 inpt parameter - alignment of object
396 input parameter - left and right spacing of the object to the text
399 input parameter - upper and lower spacing of the object to the text
402 input parameter - boolean indicating, if object is on an even page.
404 @return adjusted relative horizontal position in SwTwips
406 SwTwips
_AdjustHoriRelPosForDrawAside( const SwFrm
& _rHoriOrientFrm
,
407 const SwTwips _nProposedRelPosX
,
408 const SwTwips _nRelPosY
,
409 const sal_Int16 _eHoriOrient
,
410 const sal_Int16 _eRelOrient
,
411 const SvxLRSpaceItem
& _rLRSpacing
,
412 const SvxULSpaceItem
& _rULSpacing
,
413 const bool _bEvenPage
416 // *********************************************************************
417 /** detemine, if object has to draw aside given fly frame
419 method used by <_AdjustHoriRelPosForDrawAside(..)>
424 input parameter - fly frame the draw aside check is done for.
427 input parameter - proposed object rectangle
430 input parameter - context of the object
433 input parameter - index of the anchor frame of the object
436 input parameter - boolean indicating, if object is on an even page.
439 input parameter - horizontal position of object
442 inpt parameter - alignment of object
444 @return boolean indicating, if object has to be drawn aside
447 bool _DrawAsideFly( const SwFlyFrm
* _pFly
,
448 const SwRect
& _rObjRect
,
449 const SwFrm
* _pObjContext
,
450 const ULONG _nObjIndex
,
451 const bool _bEvenPage
,
452 const sal_Int16 _eHoriOrient
,
453 const sal_Int16 _eRelOrient
456 // *********************************************************************
457 /** determine, if object has to draw aside another object
459 the different alignments of the objects determines, if one has
460 to draw aside another one. Thus, the given alignment are checked
461 against each other, which one has to be drawn aside the other one.
462 depending on parameter _bLeft check is done for left or right
464 method used by <_DrawAsideFly(..)>
469 input parameter - alignment 1
472 input parameter - alignment 2
475 input parameter - boolean indicating, if check is done for left
476 or for right positioning.
478 @return boolean indicating, if an object with an alignment
479 <_eRelOrient1> has to be drawn aside an object with an
480 alignment <_eRelOrient2>
482 bool _Minor( sal_Int16 _eRelOrient1
,
483 sal_Int16 _eRelOrient2
,
487 virtual void CalcPosition() = 0;
489 } // namespace objectpositioning