summaryrefslogtreecommitdiff
path: root/sw/source/core/inc/sectfrm.hxx
blob: b5ddcd9480d424b3c7a6f1feb1dbb870919eb54c (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
176
177
178
179
180
/* -*- 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 <tools/mempool.hxx>

#include "layfrm.hxx"
#include "flowfrm.hxx"
#include <set>

class SwSection;
class SwSectionFormat;
class SwAttrSetChg;
class SwFootnoteContFrm;
class SwLayouter;

#define FINDMODE_ENDNOTE 1
#define FINDMODE_LASTCNT 2
#define FINDMODE_MYLAST  4

class SwSectionFrm: public SwLayoutFrm, public SwFlowFrm
{
    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 ~SwSectionFrm();

protected:
    virtual void MakeAll(vcl::RenderContext* pRenderContext) override;
    virtual bool ShouldBwdMoved( SwLayoutFrm *pNewUpper, bool bHead, 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:
    SwSectionFrm( SwSection &, SwFrm* ); // Content is not created!
    SwSectionFrm( SwSectionFrm &, bool bMaster ); // _ONLY_ for creating Master/Follows!

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

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

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

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

                 SwContentFrm *FindLastContent( sal_uInt8 nMode = 0 );
    inline const SwContentFrm *FindLastContent( sal_uInt8 nMode = 0 ) const;
    inline SwSection* GetSection() { return m_pSection; }
    inline const SwSection* GetSection() const { return m_pSection; }
    inline void ColLock()       { mbColLocked = true; }
    inline void ColUnlock()     { mbColLocked = false; }

    void CalcFootnoteContent();
    void SimpleFormat();
    bool IsDescendantFrom( const SwSectionFormat* pSect ) const;
    bool HasToBreak( const SwFrm* pFrm ) const;
    void MergeNext( SwSectionFrm* pNxt );

    /**
     * Splits the SectionFrm surrounding the pFrm up in two parts:
     * pFrm and the start of the 2nd part
     */
    bool SplitSect( SwFrm* pFrm, bool bApres );
    void DelEmpty( bool bRemove ); // Like Cut(), except for that Follow chaining is maintained
    SwFootnoteContFrm* ContainsFootnoteCont( const SwFootnoteContFrm* 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;
    inline bool _ToMaximize() const
        { if( !m_pSection ) return false; return ToMaximize( false ); }
    bool MoveAllowed( const SwFrm* ) const;
    bool CalcMinDiff( SwTwips& rMinDiff ) const;

    /**
     * Returns the size delta that the section would like to be
     * greater if it has undersized TextFrms in it.
     *
     * If we don't pass a @param bOverSize or false, the return value
     * is > 0 for undersized Frames, or 0 otherwise.
     * If @param bOverSize == true, we can also get a negative return value,
     * if the SectionFrm is not completely filled, which happens often for
     * e.g. SectionFrms with Follows.
     *
     * If necessary the undersized-flag is corrected.
     * We need this in the FormatWidthCols to "deflate" columns there.
     */
    SwTwips Undersize(bool bOverSize = false);
    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( SwSectionFrm* 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; }

    DECL_FIXEDMEMPOOL_NEWDEL(SwSectionFrm)
};

class SwDestroyList : public std::set<SwSectionFrm*> {};

inline const SwSectionFrm *SwSectionFrm::GetFollow() const
{
    return static_cast<const SwSectionFrm*>(SwFlowFrm::GetFollow());
}
inline SwSectionFrm *SwSectionFrm::GetFollow()
{
    return static_cast<SwSectionFrm*>(SwFlowFrm::GetFollow());
}
inline const SwContentFrm *SwSectionFrm::FindLastContent( sal_uInt8 nMode ) const
{
    return const_cast<SwSectionFrm*>(this)->FindLastContent( nMode );
}

#endif // INCLUDED_SW_SOURCE_CORE_INC_SECTFRM_HXX

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