xref: /AOO41X/main/sw/source/core/inc/anchoredobjectposition.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1  /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _ANCHOREDOBJECTPOSITION_HXX
28 #define _ANCHOREDOBJECTPOSITION_HXX
29 
30 #include <swtypes.hxx>
31 // OD 2004-03-16 #i11860#
32 #include <frame.hxx>
33 
34 class SdrObject;
35 class SwFrm;
36 class SwFlyFrm;
37 class SwContact;
38 class SwFrmFmt;
39 class SwRect;
40 class SvxLRSpaceItem;
41 class SvxULSpaceItem;
42 class SwFmtHoriOrient;
43 // OD 2004-03-23 #i26701#
44 class SwAnchoredObject;
45 
46 namespace objectpositioning
47 {
48     class SwEnvironmentOfAnchoredObject;
49 
50     class SwAnchoredObjectPosition
51     {
52         private:
53             // object to be positioned
54             SdrObject& mrDrawObj;
55 
56          // information about object
57             // does the object represents a Writer fly frame
58             bool mbIsObjFly;
59             // OD 2004-03-23 #i26791# - anchored object the object belongs to;
60             SwAnchoredObject* mpAnchoredObj;
61             // frame the object is anchored at
62             SwFrm* mpAnchorFrm;
63             // contact object
64             SwContact* mpContact;
65             // frame format
66             const SwFrmFmt* mpFrmFmt;
67             // --> OD 2006-03-15 #i62875#
68             bool mbFollowTextFlow;
69             // <--
70             // --> OD 2006-03-15 #i62875#
71             // for compatibility option <DoNotCaptureDrawObjsOnPage>
72             bool mbDoNotCaptureAnchoredObj;
73             // <--
74 
75             /** determine information about object
76 
77                 OD 30.07.2003 #110978#
78                 member <mbIsObjFly>, <mpAnchoredObj>, <mpAnchorFrm>, <mpContact>
79                 and <mpFrmFmt> are set
80 
81                 @author OD
82             */
83             void _GetInfoAboutObj();
84 
85             // --> OD 2006-03-15 #i62875#
86             // --> OD 2009-09-01 #mongolianlayout# - add parameter <bVertL2R>
87             SwTwips _ImplAdjustVertRelPos( const SwTwips nTopOfAnch,
88                                            const bool bVert,
89                                            const bool bVertL2R,
90                                            const SwFrm&  rPageAlignLayFrm,
91                                            const SwTwips nProposedRelPosY,
92                                            const bool bFollowTextFlow,
93                                            const bool bCheckBottom = true ) const;
94             SwTwips _ImplAdjustHoriRelPos( const SwFrm&  _rPageAlignLayFrm,
95                                            const SwTwips _nProposedRelPosX ) const;
96             // <--
97 
98         protected:
99             SwAnchoredObjectPosition( SdrObject& _rDrawObj );
100             virtual ~SwAnchoredObjectPosition();
101 
102          // accessors for object and its corresponding data/information
103             inline SdrObject& GetObject() const
104             {
105                 return mrDrawObj;
106             }
107             inline bool IsObjFly() const
108             {
109                 return mbIsObjFly;
110             }
111             inline SwAnchoredObject& GetAnchoredObj() const
112             {
113                 return *mpAnchoredObj;
114             }
115             inline SwFrm& GetAnchorFrm() const
116             {
117                 return *mpAnchorFrm;
118             }
119             inline SwContact& GetContact() const
120             {
121                 return *mpContact;
122             }
123             inline const SwFrmFmt& GetFrmFmt() const
124             {
125                 return *mpFrmFmt;
126             }
127             // --> OD 2006-03-15 #i62875#
128             inline bool DoesObjFollowsTextFlow() const
129             {
130                 return mbFollowTextFlow;
131             }
132             // <--
133 
134          // virtual methods providing data for to character anchored objects.
135             virtual bool IsAnchoredToChar() const;
136             virtual const SwFrm* ToCharOrientFrm() const;
137             virtual const SwRect* ToCharRect() const;
138             // OD 12.11.2003 #i22341#
139             virtual SwTwips ToCharTopOfLine() const;
140 
141         // *********************************************************************
142             /** helper method to determine top of a frame for the vertical
143                 object positioning
144 
145                 OD 2004-03-11 #i11860#
146 
147                 @author OD
148             */
149             SwTwips _GetTopForObjPos( const SwFrm& _rFrm,
150                                       const SwRectFn& _fnRect,
151                                       const bool _bVert ) const;
152 
153         // *********************************************************************
154             void _GetVertAlignmentValues( const SwFrm& _rVertOrientFrm,
155                                           const SwFrm& _rPageAlignLayFrm,
156                                           const sal_Int16 _eRelOrient,
157                                           SwTwips&      _orAlignAreaHeight,
158                                           SwTwips&      _orAlignAreaOffset ) const;
159 
160         // *********************************************************************
161         // --> OD 2004-06-17 #i26791# - add output parameter <_roVertOffsetToFrmAnchorPos>
162             SwTwips _GetVertRelPos( const SwFrm& _rVertOrientFrm,
163                                     const SwFrm& _rPageAlignLayFrm,
164                                     const sal_Int16 _eVertOrient,
165                                     const sal_Int16 _eRelOrient,
166                                     const SwTwips          _nVertPos,
167                                     const SvxLRSpaceItem& _rLRSpacing,
168                                     const SvxULSpaceItem& _rULSpacing,
169                                     SwTwips& _roVertOffsetToFrmAnchorPos ) const;
170 
171         // *********************************************************************
172             /** adjust calculated vertical in order to keep object inside
173                 'page' alignment layout frame.
174 
175                 OD 2004-07-22 #i31805# - add parameter <bCheckBottom>
176                 OD 2004-10-08 #i26945# - add parameter <bFollowTextFlow>
177                 OD 2006-03-15 #i62875# - made inline, intrinsic actions moved
178                 to private method <_ImplAdjustVertRelPos>, which is only
179                 called, if <mbDoNotCaptureAnchoredObj> not set.
180                 OD 2009-09-01 #mongolianlayout# - add parameter <bVertL2R>
181 
182                 @param nTopOfAnch
183                 input parameter - 'vertical' position, at which the relative
184                 position of the object is calculated from.
185 
186                 @param bVert
187                 input parameter - boolean, indicating, if object is in vertical
188                 layout.
189 
190                 @param bVertL2R
191                 input parameter - boolean, indicating, if object is in mongolian
192                 layout (vertical left-to-right layout).
193 
194                 @param rPageAlignLayFrm
195                 input parameter - layout frame, which determines the 'page area'
196                 the object has to be vertical positioned in.
197 
198                 @param nProposedRelPosY
199                 input parameter - proposed relative vertical position, which
200                 will be adjusted.
201 
202                 @param bFollowTextFlow
203                 input parameter - value of attribute 'Follow text flow' of the
204                 anchored object.
205 
206                 @param bCheckBottom
207                 input parameter - boolean indicating, if bottom of anchored
208                 object has to be checked and thus, (if needed) the proposed
209                 relative position has to be adjusted. default value <true>
210 
211                 @author OD
212             */
213             inline SwTwips _AdjustVertRelPos( const SwTwips nTopOfAnch,
214                                               const bool bVert,
215                                               const bool bVertL2R,
216                                               const SwFrm& rPageAlignLayFrm,
217                                               const SwTwips nProposedRelPosY,
218                                               const bool bFollowTextFlow,
219                                               const bool bCheckBottom = true ) const
220             {
221                 return !mbDoNotCaptureAnchoredObj
222                        ? _ImplAdjustVertRelPos( nTopOfAnch, bVert, bVertL2R,
223                                                 rPageAlignLayFrm,
224                                                 nProposedRelPosY,
225                                                 bFollowTextFlow,
226                                                 bCheckBottom )
227                        : nProposedRelPosY;
228             }
229 
230         // *********************************************************************
231             /** calculate relative horizontal position
232 
233                 --> OD 2004-06-17 #i26791# - add output parameter
234                 <_roHoriOffsetToFrmAnchorPos>
235 
236                 @author OD
237 
238                 @param _rHoriOrientFrm
239                 input parameter - frame the horizontal position of the object
240                 is oriented at.
241 
242                 @param _rEnvOfObj
243                 input parameter - object instance to retrieve environment
244                 information about the object
245 
246                 @param _rHoriOrient
247                 input parameter - horizontal positioning and alignment, for which
248                 the relative position is calculated.
249 
250                 @param _rLRSpacing
251                 input parameter - left and right spacing of the object to the text
252 
253                 @param _rULSpacing
254                 input parameter - upper and lower spacing of the object to the text
255 
256                 @param _bObjWrapThrough
257                 input parameter - boolean indicating, if object has wrap mode
258                 'wrap through'.
259 
260                 @param _nRelPosY
261                 input parameter - relative vertical position
262 
263                 @param _roHoriOffsetToFrmAnchorPos
264                 output parameter - 'horizontal' offset to frame anchor position
265                 according to the alignment
266 
267                 @return relative horizontal position in SwTwips
268             */
269             SwTwips _CalcRelPosX( const SwFrm& _rHoriOrientFrm,
270                                   const SwEnvironmentOfAnchoredObject& _rEnvOfObj,
271                                   const SwFmtHoriOrient& _rHoriOrient,
272                                   const SvxLRSpaceItem& _rLRSpacing,
273                                   const SvxULSpaceItem& _rULSpacing,
274                                   const bool _bObjWrapThrough,
275                                   const SwTwips _nRelPosY,
276                                   SwTwips& _roHoriOffsetToFrmAnchorPos
277                                 ) const;
278 
279         // *********************************************************************
280             /** adjust calculated horizontal in order to keep object inside
281                 'page' alignment layout frame for object type position TO_CNTNT
282 
283                 OD 2006-03-15 #i62875# - made inline, intrinsic actions moved
284                 to private method <_ImplAdjustHoriRelPos>, which is only
285                 called, if <mbDoNotCaptureAnchoredObj> not set.
286 
287                 @author OD
288 
289                 @param _rPageAlignLayFrm
290                 input paramter - layout frame, which determines the 'page area'
291                 the object has to be horizontal positioned in.
292 
293                 @param _nProposedRelPosX
294                 input parameter - proposed relative horizontal position, which
295                 will be adjusted.
296 
297                 @return adjusted relative horizontal position in SwTwips.
298             */
299             inline SwTwips _AdjustHoriRelPos( const SwFrm&  _rPageAlignLayFrm,
300                                               const SwTwips _nProposedRelPosX ) const
301             {
302                 return !mbDoNotCaptureAnchoredObj
303                        ? _ImplAdjustHoriRelPos( _rPageAlignLayFrm, _nProposedRelPosX )
304                        : _nProposedRelPosX;
305             }
306 
307         // *********************************************************************
308             /** toggle given horizontal orientation and relative alignment
309 
310                 @author OD
311 
312                 @param _bToggleLeftRight
313                 input parameter - boolean indicating, if horizontal orientation
314                 and relative alignment has to be toggled.
315 
316                 @param _ioeHoriOrient
317                 input/output parameter - horizontal orientation, that is toggled,
318                 if needed.
319 
320                 @param _iopeRelOrient
321                 optional input/output parameter (default value NULL)
322                 - if set, relative alignment, that is toggled, if needed.
323             */
324             void _ToggleHoriOrientAndAlign( const bool _bToggleLeftRight,
325                                             sal_Int16& _ioeHoriOrient,
326                                             sal_Int16& _iopeRelOrient
327                                           ) const;
328 
329         // *********************************************************************
330             /** determine alignment values for horizontal position of object
331 
332                 @author OD
333 
334                 @param _rHoriOrientFrm
335                 input parameter - frame the horizontal position of the object
336                 is oriented at.
337 
338                 @param _rPageAlignLayFrm
339                 input paramter - layout frame, which determines the 'page area'
340                 the object has to be horizontal positioned in.
341 
342                 @param _eRelOrient
343                 input parameter - horizontal relative alignment, for which
344                 the relative position is calculated.
345 
346                 @param _bToggleLeftRight
347                 input parameter - boolean indicating, if left/right alignments
348                 have to be toggled.
349 
350                 @param _bObjWrapThrough
351                 input parameter - boolean indicating, if object has wrap mode
352                 'wrap through'.
353                 important note: value is only relevant, if _rHoriOrientFrm is
354                                 a text frame.
355 
356                 @param _orAlignAreaWidth
357                 output parameter - width in SwTwips of the area the horizontal
358                 position is aligned to.
359 
360                 @param _orAlignAreaOffset
361                 output parameter - offset in SwTwips of the area the horizontal
362                 position is aligned to. offset is given to the 'left' of the
363                 anchor position.
364 
365                 @param _obAlignedRelToPage
366                 output parameter - boolean indicating, that object is aligned
367                 to 'page area'.
368             */
369             void _GetHoriAlignmentValues( const SwFrm&  _rHoriOrientFrm,
370                                           const SwFrm&  _rPageAlignLayFrm,
371                                           const sal_Int16 _eRelOrient,
372                                           const bool    _bObjWrapThrough,
373                                           SwTwips&      _orAlignAreaWidth,
374                                           SwTwips&      _orAlignAreaOffset,
375                                           bool&         _obAlignedRelToPage ) const;
376 
377         // *********************************************************************
378             /** adjust calculated horizontal position in order to draw object
379                 aside other objects with same positioning
380 
381                 @author OD
382 
383                 @param _rHoriOrientFrm
384                 input parameter - frame the horizontal position of the object
385                 is oriented at.
386 
387                 @param _nProposedRelPosX
388                 input parameter - proposed relative horizontal position, which
389                 will be adjusted.
390 
391                 @param _nRelPosY
392                 input parameter - relative vertical position
393 
394                 @param _eHoriOrient
395                 input parameter - horizontal position of object
396 
397                 @param _eRelOrient
398                 inpt parameter - alignment of object
399 
400                 @param _rLRSpacing
401                 input parameter - left and right spacing of the object to the text
402 
403                 @param _rULSpacing
404                 input parameter - upper and lower spacing of the object to the text
405 
406                 @param _bEvenPage
407                 input parameter - boolean indicating, if object is on an even page.
408 
409                 @return adjusted relative horizontal position in SwTwips
410             */
411             SwTwips _AdjustHoriRelPosForDrawAside( const SwFrm&  _rHoriOrientFrm,
412                                                    const SwTwips _nProposedRelPosX,
413                                                    const SwTwips _nRelPosY,
414                                                    const sal_Int16 _eHoriOrient,
415                                                    const sal_Int16 _eRelOrient,
416                                                    const SvxLRSpaceItem& _rLRSpacing,
417                                                    const SvxULSpaceItem& _rULSpacing,
418                                                    const bool _bEvenPage
419                                                  ) const;
420 
421         // *********************************************************************
422             /** detemine, if object has to draw aside given fly frame
423 
424                 method used by <_AdjustHoriRelPosForDrawAside(..)>
425 
426                 @author OD
427 
428                 @param _pFly
429                 input parameter - fly frame the draw aside check is done for.
430 
431                 @param _rObjRect
432                 input parameter - proposed object rectangle
433 
434                 @param _pObjContext
435                 input parameter - context of the object
436 
437                 @param _nObjIndex
438                 input parameter - index of the anchor frame of the object
439 
440                 @param _bEvenPage
441                 input parameter - boolean indicating, if object is on an even page.
442 
443                 @param _eHoriOrient
444                 input parameter - horizontal position of object
445 
446                 @param _eRelOrient
447                 inpt parameter - alignment of object
448 
449                 @return boolean indicating, if object has to be drawn aside
450                 given fly frame.
451             */
452             bool _DrawAsideFly( const SwFlyFrm* _pFly,
453                                 const SwRect&   _rObjRect,
454                                 const SwFrm*    _pObjContext,
455                                 const sal_uLong     _nObjIndex,
456                                 const bool      _bEvenPage,
457                                 const sal_Int16 _eHoriOrient,
458                                 const sal_Int16 _eRelOrient
459                               ) const;
460 
461         // *********************************************************************
462             /** determine, if object has to draw aside another object
463 
464                 the different alignments of the objects determines, if one has
465                 to draw aside another one. Thus, the given alignment are checked
466                 against each other, which one has to be drawn aside the other one.
467                 depending on parameter _bLeft check is done for left or right
468                 positioning.
469                 method used by <_DrawAsideFly(..)>
470 
471                 @author OD
472 
473                 @param _eRelOrient1
474                 input parameter - alignment 1
475 
476                 @param _eRelOrient2
477                 input parameter - alignment 2
478 
479                 @param _bLeft
480                 input parameter - boolean indicating, if check is done for left
481                 or for right positioning.
482 
483                 @return boolean indicating, if an object with an alignment
484                 <_eRelOrient1> has to be drawn aside an object with an
485                 alignment <_eRelOrient2>
486             */
487             bool _Minor( sal_Int16 _eRelOrient1,
488                          sal_Int16 _eRelOrient2,
489                          bool             _bLeft ) const;
490 
491         public:
492             virtual void CalcPosition() = 0;
493     };
494 } // namespace objectpositioning
495 
496 #endif
497