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