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
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.
51 typedef std::vector
<SwFlyCache
> SwPageFlyCache
;
55 std::vector
<sal_uLong
> mIndices
;
56 std::deque
<sal_Int32
> aOffset
;
57 std::vector
<sal_uInt16
> aType
;
58 SwPageFlyCache m_FlyCache
;
60 void Insert( sal_uInt16 nType
, sal_uLong nIndex
, sal_Int32 nOffset
);
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.
83 SwActualSection
*pUpper
;
84 SwSectionFrame
*pSectFrame
;
85 SwSectionNode
*pSectNode
;
87 SwActualSection( SwActualSection
*pUpper
,
88 SwSectionFrame
*pSect
,
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.
103 SwPageFrame
* &mrpPage
;
104 SwLayoutFrame
* &mrpLay
;
105 SwActualSection
* &mrpActualSection
;
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
115 void CheckFlyCache_( SwPageFrame
* pPage
);
117 SwLayHelper( SwDoc
*pD
, SwFrame
* &rpF
, SwFrame
* &rpP
, SwPageFrame
* &rpPg
,
118 SwLayoutFrame
* &rpL
, SwActualSection
* &rpA
,
119 sal_uLong nNodeIndex
, bool bCache
);
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
147 RecTypeSize(sal_uInt8 typ
, sal_uLong siz
) : type(typ
), size(siz
) {}
149 std::vector
<RecTypeSize
> aRecords
;
153 sal_uLong nFlagRecEnd
;
155 sal_uInt16 nMajorVersion
;
156 sal_uInt16 nMinorVersion
;
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.
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
181 /// Skip the current record
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
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.
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
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
){}
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */