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>
23 #include <osl/diagnose.h>
25 namespace objectpositioning
28 SwEnvironmentOfAnchoredObject::SwEnvironmentOfAnchoredObject(
29 const bool _bFollowTextFlow
)
30 : mbFollowTextFlow( _bFollowTextFlow
)
33 /** determine environment layout frame for possible horizontal object positions */
34 const SwLayoutFrame
& SwEnvironmentOfAnchoredObject::GetHoriEnvironmentLayoutFrame(
35 const SwFrame
& _rHoriOrientFrame
) const
37 const SwFrame
* pHoriEnvironmentLayFrame
= &_rHoriOrientFrame
;
39 if ( !mbFollowTextFlow
)
41 // No exception any more for page alignment.
42 // the page frame determines the horizontal layout environment.
43 pHoriEnvironmentLayFrame
= _rHoriOrientFrame
.FindPageFrame();
47 while ( !pHoriEnvironmentLayFrame
->IsCellFrame() &&
48 !pHoriEnvironmentLayFrame
->IsFlyFrame() &&
49 !pHoriEnvironmentLayFrame
->IsPageFrame() )
51 pHoriEnvironmentLayFrame
= pHoriEnvironmentLayFrame
->GetUpper();
52 OSL_ENSURE( pHoriEnvironmentLayFrame
,
53 "SwEnvironmentOfAnchoredObject::GetHoriEnvironmentLayoutFrame(..) - no page|fly|cell frame found" );
57 assert( dynamic_cast< const SwLayoutFrame
*>( pHoriEnvironmentLayFrame
) &&
58 "SwEnvironmentOfAnchoredObject::GetHoriEnvironmentLayoutFrame(..) - found frame isn't a layout frame" );
60 return static_cast<const SwLayoutFrame
&>(*pHoriEnvironmentLayFrame
);
63 /** determine environment layout frame for possible vertical object positions */
64 const SwLayoutFrame
& SwEnvironmentOfAnchoredObject::GetVertEnvironmentLayoutFrame(
65 const SwFrame
& _rVertOrientFrame
) const
67 const SwFrame
* pVertEnvironmentLayFrame
= &_rVertOrientFrame
;
69 if ( !mbFollowTextFlow
)
71 // No exception any more for page alignment.
72 // the page frame determines the vertical layout environment.
73 pVertEnvironmentLayFrame
= _rVertOrientFrame
.FindPageFrame();
77 while ( !pVertEnvironmentLayFrame
->IsCellFrame() &&
78 !pVertEnvironmentLayFrame
->IsFlyFrame() &&
79 !pVertEnvironmentLayFrame
->IsHeaderFrame() &&
80 !pVertEnvironmentLayFrame
->IsFooterFrame() &&
81 !pVertEnvironmentLayFrame
->IsFootnoteFrame() &&
82 !pVertEnvironmentLayFrame
->IsPageBodyFrame() &&
83 !pVertEnvironmentLayFrame
->IsPageFrame() )
85 pVertEnvironmentLayFrame
= pVertEnvironmentLayFrame
->GetUpper();
86 OSL_ENSURE( pVertEnvironmentLayFrame
,
87 "SwEnvironmentOfAnchoredObject::GetVertEnvironmentLayoutFrame(..) - proposed frame not found" );
91 assert( dynamic_cast< const SwLayoutFrame
*>( pVertEnvironmentLayFrame
) &&
92 "SwEnvironmentOfAnchoredObject::GetVertEnvironmentLayoutFrame(..) - found frame isn't a layout frame" );
94 return static_cast<const SwLayoutFrame
&>(*pVertEnvironmentLayFrame
);
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */