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 #ifndef INCLUDED_SW_SOURCE_CORE_INC_SECTFRM_HXX
20 #define INCLUDED_SW_SOURCE_CORE_INC_SECTFRM_HXX
21 
22 #include "layfrm.hxx"
23 #include "flowfrm.hxx"
24 
25 #include <svl/listener.hxx>
26 
27 class SwSection;
28 class SwSectionFormat;
29 class SwAttrSetChg;
30 class SwFootnoteContFrame;
31 class SwLayouter;
32 
33 enum class SwFindMode
34 {
35     None = 0, EndNote = 1, LastCnt = 2, MyLast = 4
36 };
37 
38 enum class SwSectionFrameInvFlags : sal_uInt8
39 {
40     NONE = 0x00,
41     InvalidateSize = 0x01,
42     SetCompletePaint = 0x10,
43 };
44 
45 namespace o3tl {
46     template<> struct typed_flags<SwSectionFrameInvFlags> : is_typed_flags<SwSectionFrameInvFlags, 0x0011> {};
47 }
48 
49 class SwSectionFrame final: public SwLayoutFrame, public SwFlowFrame
50     , public SvtListener // TODO?
51 {
52     SwSection* m_pSection;
53     bool m_bFootnoteAtEnd; // footnotes at the end of section
54     bool m_bEndnAtEnd; // endnotes at the end of section
55     bool m_bContentLock; // content locked
56     bool m_bOwnFootnoteNum; // special numbering of footnotes
57     bool m_bFootnoteLock; // ftn, don't leave this section bwd
58 
59     void UpdateAttr_( const SfxPoolItem*, const SfxPoolItem*, SwSectionFrameInvFlags &,
60                       SwAttrSetChg *pa = nullptr, SwAttrSetChg *pb = nullptr );
61     void Cut_( bool bRemove );
62     // Is there a FootnoteContainer?
63     // An empty sectionfrm without FootnoteCont is superfluous
IsSuperfluous() const64     bool IsSuperfluous() const { return !ContainsAny() && !ContainsFootnoteCont(); }
65     void CalcFootnoteAtEndFlag();
66     void CalcEndAtEndFlag();
67     const SwSectionFormat* GetEndSectFormat_() const;
68     bool IsEndnoteAtMyEnd() const;
69 
70     virtual void DestroyImpl() override;
71     virtual ~SwSectionFrame() override;
72 
73     virtual void MakeAll(vcl::RenderContext* pRenderContext) override;
74     virtual bool ShouldBwdMoved( SwLayoutFrame *pNewUpper, bool &rReformat ) override;
75     virtual void Format( vcl::RenderContext* pRenderContext, const SwBorderAttrs *pAttrs = nullptr ) override;
76     virtual void Notify(SfxHint const& rHint) override;
77     virtual void SwClientNotify( const SwModify&, const SfxHint& ) override;
78 
79 public:
80     SwSectionFrame( SwSection &, SwFrame* ); // Content is not created!
81     SwSectionFrame( SwSectionFrame &, bool bMaster ); // _ONLY_ for creating Master/Follows!
82 
83     void Init();
84     virtual void CheckDirection( bool bVert ) override;
85 
86     virtual void PaintSubsidiaryLines( const SwPageFrame*, const SwRect& ) const override;
87 
88     virtual void Cut() override;
89     virtual void Paste( SwFrame* pParent, SwFrame* pSibling = nullptr ) override;
90 
91     inline const SwSectionFrame *GetFollow() const;
92     inline       SwSectionFrame *GetFollow();
93     SwSectionFrame* FindMaster() const;
94 
95                  SwContentFrame *FindLastContent( SwFindMode nMode = SwFindMode::None );
96     inline const SwContentFrame *FindLastContent() const;
GetSection()97     SwSection* GetSection() { return m_pSection; }
GetSection() const98     const SwSection* GetSection() const { return m_pSection; }
ColLock()99     void ColLock()       { mbColLocked = true; }
ColUnlock()100     void ColUnlock()     { mbColLocked = false; }
101 
102     void CalcFootnoteContent();
103     void SimpleFormat();
104     bool IsDescendantFrom( const SwSectionFormat* pSect ) const;
105     bool HasToBreak( const SwFrame* pFrame ) const;
106     void MergeNext( SwSectionFrame* pNxt );
107 
108     /**
109      * Splits the SectionFrame surrounding the pFrame up in two parts:
110      * pFrame and the start of the 2nd part
111      */
112     bool SplitSect( SwFrame* pFrame, bool bApres );
113     void DelEmpty( bool bRemove ); // Like Cut(), except for that Follow chaining is maintained
114     SwFootnoteContFrame* ContainsFootnoteCont( const SwFootnoteContFrame* pCont = nullptr ) const;
115     bool Growable() const;
116     SwTwips Shrink_( SwTwips, bool bTst );
117     SwTwips Grow_  ( SwTwips, bool bTst );
118 
119     /**
120      * A sectionfrm has to maximize, if he has a follow or a ftncontainer at
121      * the end of the page. A superfluous follow will be ignored,
122      * if bCheckFollow is set.
123      */
124     bool ToMaximize( bool bCheckFollow ) const;
ToMaximize_() const125     bool ToMaximize_() const {
126         if( !m_pSection ) return false;
127         return ToMaximize( false );
128     }
129     bool MoveAllowed( const SwFrame* ) const;
130     bool CalcMinDiff( SwTwips& rMinDiff ) const;
131 
132     /**
133      * Returns the size delta that the section would like to be
134      * greater if it has undersized TextFrames in it.
135      *
136      * The return value is > 0 for undersized Frames, or 0 otherwise.
137      *
138      * If necessary the undersized-flag is corrected.
139      * We need this in the FormatWidthCols to "deflate" columns there.
140      */
141     SwTwips Undersize();
142     SwTwips CalcUndersize() const;
143 
144     /// Adapt size to surroundings
145     void CheckClipping( bool bGrow, bool bMaximize );
146 
147     void InvalidateFootnotePos();
148     void CollectEndnotes( SwLayouter* pLayouter );
GetEndSectFormat() const149     const SwSectionFormat* GetEndSectFormat() const {
150         if( IsEndnAtEnd() ) return GetEndSectFormat_();
151         return nullptr;
152     }
153 
154     static void MoveContentAndDelete( SwSectionFrame* pDel, bool bSave );
155 
156     bool IsBalancedSection() const;
157 
158     virtual void dumpAsXmlAttributes(xmlTextWriterPtr writer) const override;
159 
IsFootnoteAtEnd() const160     bool IsFootnoteAtEnd() const { return m_bFootnoteAtEnd; }
IsEndnAtEnd() const161     bool IsEndnAtEnd() const { return m_bEndnAtEnd;   }
IsAnyNoteAtEnd() const162     bool IsAnyNoteAtEnd() const { return m_bFootnoteAtEnd || m_bEndnAtEnd; }
163 
SetContentLock(bool bNew)164     void SetContentLock( bool bNew ) { m_bContentLock = bNew; }
IsContentLocked() const165     bool IsContentLocked() const { return m_bContentLock; }
166 
IsOwnFootnoteNum() const167     bool IsOwnFootnoteNum() const { return m_bOwnFootnoteNum; }
168 
SetFootnoteLock(bool bNew)169     void SetFootnoteLock( bool bNew ) { m_bFootnoteLock = bNew; }
IsFootnoteLock() const170     bool IsFootnoteLock() const { return m_bFootnoteLock; }
171 };
172 
GetFollow() const173 inline const SwSectionFrame *SwSectionFrame::GetFollow() const
174 {
175     return static_cast<const SwSectionFrame*>(SwFlowFrame::GetFollow());
176 }
GetFollow()177 inline SwSectionFrame *SwSectionFrame::GetFollow()
178 {
179     return static_cast<SwSectionFrame*>(SwFlowFrame::GetFollow());
180 }
FindLastContent() const181 inline const SwContentFrame *SwSectionFrame::FindLastContent() const
182 {
183     return const_cast<SwSectionFrame*>(this)->FindLastContent();
184 }
185 
186 #endif // INCLUDED_SW_SOURCE_CORE_INC_SECTFRM_HXX
187 
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
189