1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
24 #include <nodeoffset.hxx>
26 #include <tools/solar.h>
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.
54 typedef std::vector
<SwFlyCache
> SwPageFlyCache
;
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
;
64 void Insert( sal_uInt16 nType
, SwNodeOffset nIndex
, sal_Int32 nOffset
);
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.
87 SwActualSection
*m_pUpper
;
88 SwSectionFrame
*m_pSectFrame
;
89 SwFrame
* m_pLastPos
= nullptr; // Split it *after* this child frame
90 SwSectionNode
*m_pSectNode
;
92 SwActualSection( SwActualSection
*pUpper
,
93 SwSectionFrame
*pSect
,
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.
111 SwPageFrame
* &mrpPage
;
112 SwLayoutFrame
* &mrpLay
;
113 std::unique_ptr
<SwActualSection
> &mrpActualSection
;
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
123 void CheckFlyCache_( SwPageFrame
* pPage
);
125 SwLayHelper( SwDoc
*pD
, SwFrame
* &rpF
, SwFrame
* &rpP
, SwPageFrame
* &rpPg
,
126 SwLayoutFrame
* &rpL
, std::unique_ptr
<SwActualSection
> &rpA
,
127 SwNodeOffset nNodeIndex
, bool bCache
);
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
155 RecTypeSize(sal_uInt8 typ
, sal_uLong siz
) : type(typ
), size(siz
) {}
157 std::vector
<RecTypeSize
> m_aRecords
;
161 sal_uLong m_nFlagRecEnd
;
163 sal_uInt16 m_nMajorVersion
;
164 sal_uInt16 m_nMinorVersion
;
166 bool m_bWriteMode
: 1;
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.
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
189 /// Skip the current record
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
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.
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
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
]; }
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */