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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #ifndef _ENVIRONMENTOFANCHOREDOBJECT
27 #include <environmentofanchoredobject.hxx>
28 #endif
29 #include <frame.hxx>
30 #include <pagefrm.hxx>
31 #include <flyfrm.hxx>
32 
33 using namespace objectpositioning;
34 
SwEnvironmentOfAnchoredObject(const bool _bFollowTextFlow)35 SwEnvironmentOfAnchoredObject::SwEnvironmentOfAnchoredObject(
36                                                 const bool   _bFollowTextFlow )
37     : mbFollowTextFlow( _bFollowTextFlow )
38 {}
39 
~SwEnvironmentOfAnchoredObject()40 SwEnvironmentOfAnchoredObject::~SwEnvironmentOfAnchoredObject()
41 {}
42 
43 /** determine environment layout frame for possible horizontal object positions
44 
45     OD 05.11.2003
46 
47     @author OD
48 */
GetHoriEnvironmentLayoutFrm(const SwFrm & _rHoriOrientFrm) const49 const SwLayoutFrm& SwEnvironmentOfAnchoredObject::GetHoriEnvironmentLayoutFrm(
50                                             const SwFrm& _rHoriOrientFrm ) const
51 {
52     const SwFrm* pHoriEnvironmentLayFrm = &_rHoriOrientFrm;
53 
54     if ( !mbFollowTextFlow )
55     {
56         // --> OD 2005-01-20 #118546# - no exception any more for page alignment.
57         // the page frame determines the horizontal layout environment.
58         pHoriEnvironmentLayFrm = _rHoriOrientFrm.FindPageFrm();
59         // <--
60     }
61     else
62     {
63         while ( !pHoriEnvironmentLayFrm->IsCellFrm() &&
64                 !pHoriEnvironmentLayFrm->IsFlyFrm() &&
65                 !pHoriEnvironmentLayFrm->IsPageFrm() )
66         {
67             pHoriEnvironmentLayFrm = pHoriEnvironmentLayFrm->GetUpper();
68             ASSERT( pHoriEnvironmentLayFrm,
69                     "SwEnvironmentOfAnchoredObject::GetHoriEnvironmentLayoutFrm(..) - no page|fly|cell frame found" );
70         }
71     }
72 
73     ASSERT( pHoriEnvironmentLayFrm->ISA(SwLayoutFrm),
74                 "SwEnvironmentOfAnchoredObject::GetHoriEnvironmentLayoutFrm(..) - found frame isn't a layout frame" );
75 
76     return static_cast<const SwLayoutFrm&>(*pHoriEnvironmentLayFrm);
77 }
78 
79 /** determine environment layout frame for possible vertical object positions
80 
81     OD 05.11.2003
82 
83     @author OD
84 */
GetVertEnvironmentLayoutFrm(const SwFrm & _rVertOrientFrm) const85 const SwLayoutFrm& SwEnvironmentOfAnchoredObject::GetVertEnvironmentLayoutFrm(
86                                             const SwFrm& _rVertOrientFrm ) const
87 {
88     const SwFrm* pVertEnvironmentLayFrm = &_rVertOrientFrm;
89 
90     if ( !mbFollowTextFlow )
91     {
92         // --> OD 2005-01-20 #118546# - no exception any more for page alignment.
93         // the page frame determines the vertical layout environment.
94         pVertEnvironmentLayFrm = _rVertOrientFrm.FindPageFrm();
95         // <--
96     }
97     else
98     {
99         while ( !pVertEnvironmentLayFrm->IsCellFrm() &&
100                 !pVertEnvironmentLayFrm->IsFlyFrm() &&
101                 !pVertEnvironmentLayFrm->IsHeaderFrm() &&
102                 !pVertEnvironmentLayFrm->IsFooterFrm() &&
103                 !pVertEnvironmentLayFrm->IsFtnFrm() &&
104                 !pVertEnvironmentLayFrm->IsPageBodyFrm() &&
105                 !pVertEnvironmentLayFrm->IsPageFrm() )
106         {
107             pVertEnvironmentLayFrm = pVertEnvironmentLayFrm->GetUpper();
108             ASSERT( pVertEnvironmentLayFrm,
109                     "SwEnvironmentOfAnchoredObject::GetVertEnvironmentLayoutFrm(..) - proposed frame not found" );
110         }
111     }
112 
113     ASSERT( pVertEnvironmentLayFrm->ISA(SwLayoutFrm),
114                 "SwEnvironmentOfAnchoredObject::GetVertEnvironmentLayoutFrm(..) - found frame isn't a layout frame" );
115 
116     return static_cast<const SwLayoutFrm&>(*pVertEnvironmentLayFrm);
117 }
118