summaryrefslogtreecommitdiffstats
path: root/sw/source/core/inc/sectfrm.hxx
blob: 3b890b385e2aff0bb75c93b2c0661c851463fa72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_SW_SOURCE_CORE_INC_SECTFRM_HXX
#define INCLUDED_SW_SOURCE_CORE_INC_SECTFRM_HXX

#include "layfrm.hxx"
#include "flowfrm.hxx"

class SwSection;
class SwSectionFormat;
class SwAttrSetChg;
class SwFootnoteContFrame;
class SwLayouter;

enum class SwFindMode
{
    None = 0, EndNote = 1, LastCnt = 2, MyLast = 4
};

class SwSectionFrame: public SwLayoutFrame, public SwFlowFrame
{
    SwSection* m_pSection;
    bool m_bFootnoteAtEnd; // footnotes at the end of section
    bool m_bEndnAtEnd; // endnotes at the end of section
    bool m_bContentLock; // content locked
    bool m_bOwnFootnoteNum; // special numbering of footnotes
    bool m_bFootnoteLock; // ftn, don't leave this section bwd

    void UpdateAttr_( const SfxPoolItem*, const SfxPoolItem*, sal_uInt8 &,
                      SwAttrSetChg *pa = nullptr, SwAttrSetChg *pb = nullptr );
    void Cut_( bool bRemove );
    // Is there a FootnoteContainer?
    // An empty sectionfrm without FootnoteCont is superfluous
    bool IsSuperfluous() const { return !ContainsAny() && !ContainsFootnoteCont(); }
    void CalcFootnoteAtEndFlag();
    void CalcEndAtEndFlag();
    const SwSectionFormat* GetEndSectFormat_() const;
    bool IsEndnoteAtMyEnd() const;

    virtual void DestroyImpl() override;
    virtual ~SwSectionFrame() override;

protected:
    virtual void MakeAll(vcl::RenderContext* pRenderContext) override;
    virtual bool ShouldBwdMoved( SwLayoutFrame *pNewUpper, bool &rReformat ) override;
    virtual void Format( vcl::RenderContext* pRenderContext, const SwBorderAttrs *pAttrs = nullptr ) override;
    virtual void Modify( const SfxPoolItem*, const SfxPoolItem* ) override;
    virtual void SwClientNotify( const SwModify&, const SfxHint& ) override;

public:
    SwSectionFrame( SwSection &, SwFrame* ); // Content is not created!
    SwSectionFrame( SwSectionFrame &, bool bMaster ); // _ONLY_ for creating Master/Follows!

    void Init();
    virtual void CheckDirection( bool bVert ) override;

    virtual void PaintSubsidiaryLines( const SwPageFrame*, const SwRect& ) const override;

    virtual void Cut() override;
    virtual void Paste( SwFrame* pParent, SwFrame* pSibling = nullptr ) override;

    inline const SwSectionFrame *GetFollow() const;
    inline       SwSectionFrame *GetFollow();
    SwSectionFrame* FindMaster() const;

                 SwContentFrame *FindLastContent( SwFindMode nMode = SwFindMode::None );
    inline const SwContentFrame *FindLastContent() const;
    SwSection* GetSection() { return m_pSection; }
    const SwSection* GetSection() const { return m_pSection; }
    void ColLock()       { mbColLocked = true; }
    void ColUnlock()     { mbColLocked = false; }

    void CalcFootnoteContent();
    void SimpleFormat();
    bool IsDescendantFrom( const SwSectionFormat* pSect ) const;
    bool HasToBreak( const SwFrame* pFrame ) const;
    void MergeNext( SwSectionFrame* pNxt );

    /**
     * Splits the SectionFrame surrounding the pFrame up in two parts:
     * pFrame and the start of the 2nd part
     */
    bool SplitSect( SwFrame* pFrame, bool bApres );
    void DelEmpty( bool bRemove ); // Like Cut(), except for that Follow chaining is maintained
    SwFootnoteContFrame* ContainsFootnoteCont( const SwFootnoteContFrame* pCont = nullptr ) const;
    bool Growable() const;
    SwTwips Shrink_( SwTwips, bool bTst );
    SwTwips Grow_  ( SwTwips, bool bTst );

    /**
     * A sectionfrm has to maximize, if he has a follow or a ftncontainer at
     * the end of the page. A superfluous follow will be ignored,
     * if bCheckFollow is set.
     */
    bool ToMaximize( bool bCheckFollow ) const;
    bool ToMaximize_() const {
        if( !m_pSection ) return false;
        return ToMaximize( false );
    }
    bool MoveAllowed( const SwFrame* ) const;
    bool CalcMinDiff( SwTwips& rMinDiff ) const;

    /**
     * Returns the size delta that the section would like to be
     * greater if it has undersized TextFrames in it.
     *
     * The return value is > 0 for undersized Frames, or 0 otherwise.
     *
     * If necessary the undersized-flag is corrected.
     * We need this in the FormatWidthCols to "deflate" columns there.
     */
    SwTwips Undersize();
    SwTwips CalcUndersize() const;

    /// Adapt size to surroundings
    void CheckClipping( bool bGrow, bool bMaximize );

    void InvalidateFootnotePos();
    void CollectEndnotes( SwLayouter* pLayouter );
    const SwSectionFormat* GetEndSectFormat() const {
        if( IsEndnAtEnd() ) return GetEndSectFormat_();
        return nullptr;
    }

    static void MoveContentAndDelete( SwSectionFrame* pDel, bool bSave );

    bool IsBalancedSection() const;

    virtual void dumpAsXmlAttributes(xmlTextWriterPtr writer) const override;

    bool IsFootnoteAtEnd() const { return m_bFootnoteAtEnd; }
    bool IsEndnAtEnd() const { return m_bEndnAtEnd;   }
    bool IsAnyNoteAtEnd() const { return m_bFootnoteAtEnd || m_bEndnAtEnd; }

    void SetContentLock( bool bNew ) { m_bContentLock = bNew; }
    bool IsContentLocked() const { return m_bContentLock; }

    bool IsOwnFootnoteNum() const { return m_bOwnFootnoteNum; }

    void SetFootnoteLock( bool bNew ) { m_bFootnoteLock = bNew; }
    bool IsFootnoteLock() const { return m_bFootnoteLock; }
};

inline const SwSectionFrame *SwSectionFrame::GetFollow() const
{
    return static_cast<const SwSectionFrame*>(SwFlowFrame::GetFollow());
}
inline SwSectionFrame *SwSectionFrame::GetFollow()
{
    return static_cast<SwSectionFrame*>(SwFlowFrame::GetFollow());
}
inline const SwContentFrame *SwSectionFrame::FindLastContent() const
{
    return const_cast<SwSectionFrame*>(this)->FindLastContent();
}

#endif // INCLUDED_SW_SOURCE_CORE_INC_SECTFRM_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */