Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / layout / layhelp.hxx
blob02ff3ca4f327bb14bbdbb027ed086a00e0a33cc5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #ifndef INCLUDED_SW_SOURCE_CORE_LAYOUT_LAYHELP_HXX
21 #define INCLUDED_SW_SOURCE_CORE_LAYOUT_LAYHELP_HXX
23 #include <swrect.hxx>
24 #include <nodeoffset.hxx>
26 #include <tools/solar.h>
28 #include <memory>
29 #include <vector>
30 #include <deque>
32 class SwDoc;
33 class SwFrame;
34 class SwLayoutFrame;
35 class SwPageFrame;
36 class SwSectionFrame;
37 class SwSectionNode;
38 class SvStream;
41 * Contains the page break information and the text frame positions
42 * of the document (after loading)
43 * and is used inside the constructor of the layout rootframe to
44 * insert content and text frames at the right pages.
45 * For every page of the main text (body content, no footnotes, text frames etc.)
46 * we have the nodeindex of the first content at the page,
47 * the type of content ( table or paragraph )
48 * and if it's not the first part of the table/paragraph,
49 * the row/character-offset inside the table/paragraph.
50 * The text frame positions are stored in the SwPageFlyCache array.
53 class SwFlyCache;
54 typedef std::vector<SwFlyCache> SwPageFlyCache;
56 class SwLayCacheImpl
58 std::vector<SwNodeOffset> mIndices;
59 /// either a textframe character offset, or a row index inside a table
60 std::deque<sal_Int32> m_aOffset;
61 std::vector<sal_uInt16> m_aType;
62 SwPageFlyCache m_FlyCache;
63 bool m_bUseFlyCache;
64 void Insert( sal_uInt16 nType, SwNodeOffset nIndex, sal_Int32 nOffset );
66 public:
67 inline SwLayCacheImpl();
69 size_t size() const { return mIndices.size(); }
71 bool Read( SvStream& rStream );
73 SwNodeOffset GetBreakIndex( size_t nIdx ) const { return mIndices[ nIdx ]; }
74 sal_Int32 GetBreakOfst( size_t nIdx ) const { return m_aOffset[ nIdx ]; }
75 sal_uInt16 GetBreakType( size_t nIdx ) const { return m_aType[ nIdx ]; }
77 inline size_t GetFlyCount() const;
78 inline SwFlyCache& GetFlyCache( size_t nIdx );
80 bool IsUseFlyCache() const { return m_bUseFlyCache; }
83 // Helps to create the sectionframes during the InsertCnt_-function
84 // by controlling nested sections.
85 class SwActualSection
87 SwActualSection *m_pUpper;
88 SwSectionFrame *m_pSectFrame;
89 SwFrame* m_pLastPos = nullptr; // Split it *after* this child frame
90 SwSectionNode *m_pSectNode;
91 public:
92 SwActualSection( SwActualSection *pUpper,
93 SwSectionFrame *pSect,
94 SwSectionNode *pNd );
96 SwSectionFrame *GetSectionFrame() { return m_pSectFrame; }
97 void SetSectionFrame( SwSectionFrame *p ) { m_pSectFrame = p; }
98 SwSectionNode *GetSectionNode() { return m_pSectNode;}
99 void SetUpper(SwActualSection *p) { m_pUpper = p; }
100 SwActualSection *GetUpper() { return m_pUpper; }
101 void SetLastPos(SwFrame* p) { m_pLastPos = p; }
102 SwFrame* GetLastPos() const { return m_pLastPos; }
105 /// Helps during the InsertCnt_ function to create new pages.
106 /// If there's a layout cache available, this information is used.
107 class SwLayHelper
109 SwFrame* &mrpFrame;
110 SwFrame* &mrpPrv;
111 SwPageFrame* &mrpPage;
112 SwLayoutFrame* &mrpLay;
113 std::unique_ptr<SwActualSection> &mrpActualSection;
114 bool mbBreakAfter;
115 SwDoc* mpDoc;
116 SwLayCacheImpl* mpImpl;
117 sal_uLong mnMaxParaPerPage;
118 sal_uLong mnParagraphCnt;
119 SwNodeOffset mnStartOfContent;
120 size_t mnIndex; ///< the index in the page break array
121 size_t mnFlyIdx; ///< the index in the fly cache array
122 bool mbFirst : 1;
123 void CheckFlyCache_( SwPageFrame* pPage );
124 public:
125 SwLayHelper( SwDoc *pD, SwFrame* &rpF, SwFrame* &rpP, SwPageFrame* &rpPg,
126 SwLayoutFrame* &rpL, std::unique_ptr<SwActualSection> &rpA,
127 SwNodeOffset nNodeIndex, bool bCache );
128 ~SwLayHelper();
129 sal_uLong CalcPageCount();
130 bool CheckInsert( SwNodeOffset nNodeIndex );
132 bool CheckInsertPage();
134 /// Look for fresh text frames at this (new) page and set them to the right
135 /// position, if they are in the fly cache.
136 void CheckFlyCache( SwPageFrame* pPage )
137 { if( mpImpl && mnFlyIdx < mpImpl->GetFlyCount() ) CheckFlyCache_( pPage ); }
140 // Contains the data structures that are required to read and write a layout cache.
141 #define SW_LAYCACHE_IO_REC_PAGES 'p'
142 #define SW_LAYCACHE_IO_REC_PARA 'P'
143 #define SW_LAYCACHE_IO_REC_TABLE 'T'
144 #define SW_LAYCACHE_IO_REC_FLY 'F'
146 #define SW_LAYCACHE_IO_VERSION_MAJOR 1
147 #define SW_LAYCACHE_IO_VERSION_MINOR 1
149 class SwLayCacheIoImpl
151 private:
152 struct RecTypeSize {
153 sal_uInt8 type;
154 sal_uLong size;
155 RecTypeSize(sal_uInt8 typ, sal_uLong siz) : type(typ), size(siz) {}
157 std::vector<RecTypeSize> m_aRecords;
159 SvStream *m_pStream;
161 sal_uLong m_nFlagRecEnd;
163 sal_uInt16 m_nMajorVersion;
164 sal_uInt16 m_nMinorVersion;
166 bool m_bWriteMode : 1;
167 bool m_bError : 1;
169 public:
170 SwLayCacheIoImpl( SvStream& rStrm, bool bWrtMd );
172 /// Get input or output stream
173 SvStream& GetStream() const { return *m_pStream; }
175 /// Open a record of type "nType"
176 void OpenRec( sal_uInt8 nType );
178 /// Close a record. This skips any unread data that
179 /// remains in the record.
180 void CloseRec();
182 /// Return the number of bytes contained in the current record that
183 /// haven't been read by now.
184 sal_uInt32 BytesLeft();
186 /// Return the current record's type
187 sal_uInt8 Peek();
189 /// Skip the current record
190 void SkipRec();
192 /// Open a flag record for reading. The uppermost four bits are flags,
193 /// while the lowermost are the flag record's size. Flag records cannot
194 /// be nested.
195 sal_uInt8 OpenFlagRec();
197 /// Open flag record for writing;
198 void OpenFlagRec( sal_uInt8 nFlags, sal_uInt8 nLen );
200 /// Close a flag record. Any bytes left are skipped.
201 void CloseFlagRec();
203 bool HasError() const { return m_bError; }
205 sal_uInt16 GetMajorVersion() const { return m_nMajorVersion; }
206 sal_uInt16 GetMinorVersion() const { return m_nMinorVersion; }
209 // Stored information about text frames:
210 class SwFlyCache : public SwRect // position and size
212 public:
213 sal_uLong nOrdNum; ///< Id to recognize text frames
214 sal_uInt16 nPageNum; ///< page number
215 SwFlyCache( sal_uInt16 nP, sal_uLong nO, tools::Long nXL, tools::Long nYL, tools::Long nWL, tools::Long nHL ) :
216 SwRect( nXL, nYL, nWL, nHL ), nOrdNum( nO ), nPageNum( nP ){}
219 SwLayCacheImpl::SwLayCacheImpl() : m_bUseFlyCache(false) {}
221 size_t SwLayCacheImpl::GetFlyCount() const { return m_FlyCache.size(); }
223 SwFlyCache& SwLayCacheImpl::GetFlyCache( size_t nIdx ) { return m_FlyCache[ nIdx ]; }
225 #endif
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */