1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <environmentofanchoredobject.hxx>
22 #include <pagefrm.hxx>
24 using namespace objectpositioning
;
26 SwEnvironmentOfAnchoredObject::SwEnvironmentOfAnchoredObject(
27 const bool _bFollowTextFlow
)
28 : mbFollowTextFlow( _bFollowTextFlow
)
31 SwEnvironmentOfAnchoredObject::~SwEnvironmentOfAnchoredObject()
34 /** determine environment layout frame for possible horizontal object positions */
35 const SwLayoutFrame
& SwEnvironmentOfAnchoredObject::GetHoriEnvironmentLayoutFrame(
36 const SwFrame
& _rHoriOrientFrame
) const
38 const SwFrame
* pHoriEnvironmentLayFrame
= &_rHoriOrientFrame
;
40 if ( !mbFollowTextFlow
)
42 // No exception any more for page alignment.
43 // the page frame determines the horizontal layout environment.
44 pHoriEnvironmentLayFrame
= _rHoriOrientFrame
.FindPageFrame();
48 while ( !pHoriEnvironmentLayFrame
->IsCellFrame() &&
49 !pHoriEnvironmentLayFrame
->IsFlyFrame() &&
50 !pHoriEnvironmentLayFrame
->IsPageFrame() )
52 pHoriEnvironmentLayFrame
= pHoriEnvironmentLayFrame
->GetUpper();
53 OSL_ENSURE( pHoriEnvironmentLayFrame
,
54 "SwEnvironmentOfAnchoredObject::GetHoriEnvironmentLayoutFrame(..) - no page|fly|cell frame found" );
58 OSL_ENSURE( dynamic_cast< const SwLayoutFrame
*>( pHoriEnvironmentLayFrame
) != nullptr,
59 "SwEnvironmentOfAnchoredObject::GetHoriEnvironmentLayoutFrame(..) - found frame isn't a layout frame" );
61 return static_cast<const SwLayoutFrame
&>(*pHoriEnvironmentLayFrame
);
64 /** determine environment layout frame for possible vertical object positions */
65 const SwLayoutFrame
& SwEnvironmentOfAnchoredObject::GetVertEnvironmentLayoutFrame(
66 const SwFrame
& _rVertOrientFrame
) const
68 const SwFrame
* pVertEnvironmentLayFrame
= &_rVertOrientFrame
;
70 if ( !mbFollowTextFlow
)
72 // No exception any more for page alignment.
73 // the page frame determines the vertical layout environment.
74 pVertEnvironmentLayFrame
= _rVertOrientFrame
.FindPageFrame();
78 while ( !pVertEnvironmentLayFrame
->IsCellFrame() &&
79 !pVertEnvironmentLayFrame
->IsFlyFrame() &&
80 !pVertEnvironmentLayFrame
->IsHeaderFrame() &&
81 !pVertEnvironmentLayFrame
->IsFooterFrame() &&
82 !pVertEnvironmentLayFrame
->IsFootnoteFrame() &&
83 !pVertEnvironmentLayFrame
->IsPageBodyFrame() &&
84 !pVertEnvironmentLayFrame
->IsPageFrame() )
86 pVertEnvironmentLayFrame
= pVertEnvironmentLayFrame
->GetUpper();
87 OSL_ENSURE( pVertEnvironmentLayFrame
,
88 "SwEnvironmentOfAnchoredObject::GetVertEnvironmentLayoutFrame(..) - proposed frame not found" );
92 OSL_ENSURE( dynamic_cast< const SwLayoutFrame
*>( pVertEnvironmentLayFrame
) != nullptr,
93 "SwEnvironmentOfAnchoredObject::GetVertEnvironmentLayoutFrame(..) - found frame isn't a layout frame" );
95 return static_cast<const SwLayoutFrame
&>(*pVertEnvironmentLayFrame
);
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */