Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sw / source / core / layout / layhelp.hxx
blob162669798f366879c06655b07bed7e8714d02a2e
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>
25 #include <vector>
26 #include <deque>
28 class SwDoc;
29 class SwFrame;
30 class SwLayoutFrame;
31 class SwPageFrame;
32 class SwFlyFrame;
33 class SwSectionFrame;
34 class SwSectionNode;
35 class SvStream;
38 * Contains the page break information and the text frame positions
39 * of the document (after loading)
40 * and is used inside the constructor of the layout rootframe to
41 * insert content and text frames at the right pages.
42 * For every page of the main text (body content, no footnotes, text frames etc.)
43 * we have the nodeindex of the first content at the page,
44 * the type of content ( table or paragraph )
45 * and if it's not the first part of the table/paragraph,
46 * the row/character-offset inside the table/paragraph.
47 * The text frame positions are stored in the SwPageFlyCache array.
50 class SwFlyCache;
51 typedef std::vector<SwFlyCache> SwPageFlyCache;
53 class SwLayCacheImpl
55 std::vector<sal_uLong> mIndices;
56 std::deque<sal_Int32> aOffset;
57 std::vector<sal_uInt16> aType;
58 SwPageFlyCache m_FlyCache;
59 bool bUseFlyCache;
60 void Insert( sal_uInt16 nType, sal_uLong nIndex, sal_Int32 nOffset );
62 public:
63 SwLayCacheImpl() : bUseFlyCache(false) {}
65 size_t size() const { return mIndices.size(); }
67 bool Read( SvStream& rStream );
69 sal_uLong GetBreakIndex( size_t nIdx ) const { return mIndices[ nIdx ]; }
70 sal_Int32 GetBreakOfst( size_t nIdx ) const { return aOffset[ nIdx ]; }
71 sal_uInt16 GetBreakType( size_t nIdx ) const { return aType[ nIdx ]; }
73 size_t GetFlyCount() const { return m_FlyCache.size(); }
74 SwFlyCache& GetFlyCache( size_t nIdx ) { return m_FlyCache[ nIdx ]; }
76 bool IsUseFlyCache() const { return bUseFlyCache; }
79 // Helps to create the sectionframes during the InsertCnt_-function
80 // by controlling nested sections.
81 class SwActualSection
83 SwActualSection *pUpper;
84 SwSectionFrame *pSectFrame;
85 SwSectionNode *pSectNode;
86 public:
87 SwActualSection( SwActualSection *pUpper,
88 SwSectionFrame *pSect,
89 SwSectionNode *pNd );
91 SwSectionFrame *GetSectionFrame() { return pSectFrame; }
92 void SetSectionFrame( SwSectionFrame *p ) { pSectFrame = p; }
93 SwSectionNode *GetSectionNode() { return pSectNode;}
94 SwActualSection *GetUpper() { return pUpper; }
97 /// Helps during the InsertCnt_ function to create new pages.
98 /// If there's a layout cache available, this information is used.
99 class SwLayHelper
101 SwFrame* &mrpFrame;
102 SwFrame* &mrpPrv;
103 SwPageFrame* &mrpPage;
104 SwLayoutFrame* &mrpLay;
105 SwActualSection* &mrpActualSection;
106 bool mbBreakAfter;
107 SwDoc* mpDoc;
108 SwLayCacheImpl* mpImpl;
109 sal_uLong mnMaxParaPerPage;
110 sal_uLong mnParagraphCnt;
111 sal_uLong mnStartOfContent;
112 size_t mnIndex; ///< the index in the page break array
113 size_t mnFlyIdx; ///< the index in the fly cache array
114 bool mbFirst : 1;
115 void CheckFlyCache_( SwPageFrame* pPage );
116 public:
117 SwLayHelper( SwDoc *pD, SwFrame* &rpF, SwFrame* &rpP, SwPageFrame* &rpPg,
118 SwLayoutFrame* &rpL, SwActualSection* &rpA,
119 sal_uLong nNodeIndex, bool bCache );
120 ~SwLayHelper();
121 sal_uLong CalcPageCount();
122 bool CheckInsert( sal_uLong nNodeIndex );
124 bool CheckInsertPage();
126 /// Look for fresh text frames at this (new) page and set them to the right
127 /// position, if they are in the fly cache.
128 void CheckFlyCache( SwPageFrame* pPage )
129 { if( mpImpl && mnFlyIdx < mpImpl->GetFlyCount() ) CheckFlyCache_( pPage ); }
132 // Contains the data structures that are required to read and write a layout cache.
133 #define SW_LAYCACHE_IO_REC_PAGES 'p'
134 #define SW_LAYCACHE_IO_REC_PARA 'P'
135 #define SW_LAYCACHE_IO_REC_TABLE 'T'
136 #define SW_LAYCACHE_IO_REC_FLY 'F'
138 #define SW_LAYCACHE_IO_VERSION_MAJOR 1
139 #define SW_LAYCACHE_IO_VERSION_MINOR 1
141 class SwLayCacheIoImpl
143 private:
144 struct RecTypeSize {
145 sal_uInt8 type;
146 sal_uLong size;
147 RecTypeSize(sal_uInt8 typ, sal_uLong siz) : type(typ), size(siz) {}
149 std::vector<RecTypeSize> aRecords;
151 SvStream *pStream;
153 sal_uLong nFlagRecEnd;
155 sal_uInt16 nMajorVersion;
156 sal_uInt16 nMinorVersion;
158 bool bWriteMode : 1;
159 bool bError : 1;
161 public:
162 SwLayCacheIoImpl( SvStream& rStrm, bool bWrtMd );
164 /// Get input or output stream
165 SvStream& GetStream() const { return *pStream; }
167 /// Open a record of type "nType"
168 void OpenRec( sal_uInt8 nType );
170 /// Close a record. This skips any unread data that
171 /// remains in the record.
172 void CloseRec();
174 /// Return the number of bytes contained in the current record that
175 /// haven't been read by now.
176 sal_uInt32 BytesLeft();
178 /// Return the current record's type
179 sal_uInt8 Peek();
181 /// Skip the current record
182 void SkipRec();
184 /// Open a flag record for reading. The uppermost four bits are flags,
185 /// while the lowermost are the flag record's size. Flag records cannot
186 /// be nested.
187 sal_uInt8 OpenFlagRec();
189 /// Open flag record for writing;
190 void OpenFlagRec( sal_uInt8 nFlags, sal_uInt8 nLen );
192 /// Close a flag record. Any bytes left are skipped.
193 void CloseFlagRec();
195 bool HasError() const { return bError; }
197 sal_uInt16 GetMajorVersion() const { return nMajorVersion; }
198 sal_uInt16 GetMinorVersion() const { return nMinorVersion; }
201 // Stored information about text frames:
202 class SwFlyCache : public SwRect // position and size
204 public:
205 sal_uLong nOrdNum; ///< Id to recognize text frames
206 sal_uInt16 nPageNum; ///< page number
207 SwFlyCache( sal_uInt16 nP, sal_uLong nO, long nXL, long nYL, long nWL, long nHL ) :
208 SwRect( nXL, nYL, nWL, nHL ), nOrdNum( nO ), nPageNum( nP ){}
211 #endif
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */