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