1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <swselectionlist.hxx>
21 #include <flyfrm.hxx>
22 #include <ftnfrm.hxx>
23 
24 /** This class is used as parameter for functions to create a rectangular text selection
25 */
26 
27 namespace {
28 
29     /** Find the context of a given frame
30 
31         A context is the environment where text is allowed to flow.
32         The context is represented by
33         - the SwRootFrame if the frame is part of a page body
34         - the SwHeaderFrame if the frame is part of a page header
35         - the SwFooterFrame if the frame is part of a page footer
36         - the (master) SwFootnoteFrame if the frame is part of footnote
37         - the (first) SwFlyFrame if the frame is part of a (linked) fly frame
38 
39         @param pFrame
40         the given frame
41 
42         @return the context of the frame, represented by a SwFrame*
43     */
getContext(const SwFrame * pFrame)44     const SwFrame* getContext( const SwFrame* pFrame )
45     {
46         while( pFrame )
47         {
48             if( pFrame->IsRootFrame() || pFrame->IsHeaderFrame() || pFrame->IsFooterFrame() )
49                 break;
50             if( pFrame->IsFlyFrame() )
51             {
52                 const SwFlyFrame* pFly = static_cast<const SwFlyFrame*>( pFrame );
53                 while( pFly->GetPrevLink() )
54                     pFly = pFly->GetPrevLink();
55                 break;
56             }
57             if( pFrame->IsFootnoteFrame() )
58             {
59                 const SwFootnoteFrame* pFootnote = static_cast<const SwFootnoteFrame*>( pFrame );
60                 while( pFootnote->GetMaster() )
61                     pFootnote = pFootnote->GetMaster();
62                 break;
63             }
64             pFrame = pFrame->GetUpper();
65         }
66         return pFrame;
67     }
68 }
69 
SwSelectionList(const SwFrame * pInitCxt)70 SwSelectionList::SwSelectionList( const SwFrame* pInitCxt ) :
71     m_pContext( getContext( pInitCxt ) )
72 {
73 }
74 
checkContext(const SwFrame * pCheck)75 bool SwSelectionList::checkContext( const SwFrame* pCheck )
76 {
77     pCheck = getContext( pCheck );
78     if( !m_pContext )
79         m_pContext = pCheck;
80     return m_pContext == pCheck;
81 }
82 
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
84