LibreOffice Module sw (master) 1
layhelp.hxx
Go to the documentation of this file.
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
20#ifndef INCLUDED_SW_SOURCE_CORE_LAYOUT_LAYHELP_HXX
21#define INCLUDED_SW_SOURCE_CORE_LAYOUT_LAYHELP_HXX
22
23#include <swrect.hxx>
24#include <nodeoffset.hxx>
25
26#include <tools/solar.h>
27
28#include <memory>
29#include <vector>
30#include <deque>
31
32class SwDoc;
33class SwFrame;
34class SwLayoutFrame;
35class SwPageFrame;
36class SwSectionFrame;
37class SwSectionNode;
38class SvStream;
39
40/*
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.
51 */
52
53class SwFlyCache;
54typedef std::vector<SwFlyCache> SwPageFlyCache;
55
57{
58 std::vector<SwNodeOffset> mIndices;
60 std::deque<sal_Int32> m_aOffset;
61 std::vector<sal_uInt16> m_aType;
64 void Insert( sal_uInt16 nType, SwNodeOffset nIndex, sal_Int32 nOffset );
65
66public:
67 inline SwLayCacheImpl();
68
69 size_t size() const { return mIndices.size(); }
70
71 bool Read( SvStream& rStream );
72
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 ]; }
76
77 inline size_t GetFlyCount() const;
78 inline SwFlyCache& GetFlyCache( size_t nIdx );
79
80 bool IsUseFlyCache() const { return m_bUseFlyCache; }
81};
82
83// Helps to create the sectionframes during the InsertCnt_-function
84// by controlling nested sections.
86{
89 SwFrame* m_pLastPos = nullptr; // Split it *after* this child frame
91public:
93 SwSectionFrame *pSect,
94 SwSectionNode *pNd );
95
102 SwFrame* GetLastPos() const { return m_pLastPos; }
103};
104
108{
113 std::unique_ptr<SwActualSection> &mrpActualSection;
120 size_t mnIndex;
121 size_t mnFlyIdx;
122 bool mbFirst : 1;
123 void CheckFlyCache_( SwPageFrame* pPage );
124public:
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();
130 bool CheckInsert( SwNodeOffset nNodeIndex );
131
132 bool CheckInsertPage();
133
137 { if( mpImpl && mnFlyIdx < mpImpl->GetFlyCount() ) CheckFlyCache_( pPage ); }
138};
139
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'
145
146#define SW_LAYCACHE_IO_VERSION_MAJOR 1
147#define SW_LAYCACHE_IO_VERSION_MINOR 1
148
150{
151private:
152 struct RecTypeSize {
155 RecTypeSize(sal_uInt8 typ, sal_uLong siz) : type(typ), size(siz) {}
156 };
157 std::vector<RecTypeSize> m_aRecords;
158
160
162
163 sal_uInt16 m_nMajorVersion;
164 sal_uInt16 m_nMinorVersion;
165
166 bool m_bWriteMode : 1;
167 bool m_bError : 1;
168
169public:
170 SwLayCacheIoImpl( SvStream& rStrm, bool bWrtMd );
171
173 SvStream& GetStream() const { return *m_pStream; }
174
176 void OpenRec( sal_uInt8 nType );
177
180 void CloseRec();
181
184 sal_uInt32 BytesLeft();
185
187 sal_uInt8 Peek();
188
190 void SkipRec();
191
196
198 void OpenFlagRec( sal_uInt8 nFlags, sal_uInt8 nLen );
199
201 void CloseFlagRec();
202
203 bool HasError() const { return m_bError; }
204
205 sal_uInt16 GetMajorVersion() const { return m_nMajorVersion; }
206 sal_uInt16 GetMinorVersion() const { return m_nMinorVersion; }
207};
208
209// Stored information about text frames:
210class SwFlyCache : public SwRect // position and size
211{
212public:
214 sal_uInt16 nPageNum;
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 ){}
217};
218
219SwLayCacheImpl::SwLayCacheImpl() : m_bUseFlyCache(false) {}
220
221size_t SwLayCacheImpl::GetFlyCount() const { return m_FlyCache.size(); }
222
223SwFlyCache& SwLayCacheImpl::GetFlyCache( size_t nIdx ) { return m_FlyCache[ nIdx ]; }
224
225#endif
226
227/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetLastPos(SwFrame *p)
Definition: layhelp.hxx:101
SwSectionFrame * m_pSectFrame
Definition: layhelp.hxx:88
void SetSectionFrame(SwSectionFrame *p)
Definition: layhelp.hxx:97
SwSectionNode * m_pSectNode
Definition: layhelp.hxx:90
SwFrame * m_pLastPos
Definition: layhelp.hxx:89
SwSectionFrame * GetSectionFrame()
Definition: layhelp.hxx:96
SwActualSection * GetUpper()
Definition: layhelp.hxx:100
SwSectionNode * GetSectionNode()
Definition: layhelp.hxx:98
void SetUpper(SwActualSection *p)
Definition: layhelp.hxx:99
SwFrame * GetLastPos() const
Definition: layhelp.hxx:102
SwActualSection(SwActualSection *pUpper, SwSectionFrame *pSect, SwSectionNode *pNd)
helper class to create not nested section frames for nested sections.
Definition: laycache.cxx:454
SwActualSection * m_pUpper
Definition: layhelp.hxx:87
Definition: doc.hxx:197
sal_uInt16 nPageNum
page number
Definition: layhelp.hxx:214
sal_uLong nOrdNum
Id to recognize text frames.
Definition: layhelp.hxx:213
SwFlyCache(sal_uInt16 nP, sal_uLong nO, tools::Long nXL, tools::Long nYL, tools::Long nWL, tools::Long nHL)
Definition: layhelp.hxx:215
Base class of the Writer layout elements.
Definition: frame.hxx:315
sal_Int32 GetBreakOfst(size_t nIdx) const
Definition: layhelp.hxx:74
bool m_bUseFlyCache
Definition: layhelp.hxx:63
sal_uInt16 GetBreakType(size_t nIdx) const
Definition: layhelp.hxx:75
std::vector< sal_uInt16 > m_aType
Definition: layhelp.hxx:61
size_t GetFlyCount() const
Definition: layhelp.hxx:221
SwPageFlyCache m_FlyCache
Definition: layhelp.hxx:62
std::vector< SwNodeOffset > mIndices
Definition: layhelp.hxx:58
bool IsUseFlyCache() const
Definition: layhelp.hxx:80
std::deque< sal_Int32 > m_aOffset
either a textframe character offset, or a row index inside a table
Definition: layhelp.hxx:60
SwFlyCache & GetFlyCache(size_t nIdx)
Definition: layhelp.hxx:223
bool Read(SvStream &rStream)
Definition: laycache.cxx:87
void Insert(sal_uInt16 nType, SwNodeOffset nIndex, sal_Int32 nOffset)
Definition: laycache.cxx:80
SwNodeOffset GetBreakIndex(size_t nIdx) const
Definition: layhelp.hxx:73
size_t size() const
Definition: layhelp.hxx:69
sal_uInt16 GetMajorVersion() const
Definition: layhelp.hxx:205
void CloseRec()
Close a record.
Definition: laycache.cxx:1091
std::vector< RecTypeSize > m_aRecords
Definition: layhelp.hxx:157
sal_uInt16 GetMinorVersion() const
Definition: layhelp.hxx:206
sal_uInt8 OpenFlagRec()
Open a flag record for reading.
Definition: laycache.cxx:1167
sal_uInt32 BytesLeft()
Return the number of bytes contained in the current record that haven't been read by now.
Definition: laycache.cxx:1129
SvStream & GetStream() const
Get input or output stream.
Definition: layhelp.hxx:173
sal_uLong m_nFlagRecEnd
Definition: layhelp.hxx:161
sal_uInt16 m_nMajorVersion
Definition: layhelp.hxx:163
void OpenRec(sal_uInt8 nType)
Open a record of type "nType".
Definition: laycache.cxx:1062
void CloseFlagRec()
Close a flag record. Any bytes left are skipped.
Definition: laycache.cxx:1186
SvStream * m_pStream
Definition: layhelp.hxx:159
sal_uInt8 Peek()
Return the current record's type.
Definition: laycache.cxx:1142
void SkipRec()
Skip the current record.
Definition: laycache.cxx:1159
sal_uInt16 m_nMinorVersion
Definition: layhelp.hxx:164
bool HasError() const
Definition: layhelp.hxx:203
SwLayCacheIoImpl(SvStream &rStrm, bool bWrtMd)
Definition: laycache.cxx:1045
Helps during the InsertCnt_ function to create new pages.
Definition: layhelp.hxx:108
sal_uLong CalcPageCount()
Does NOT really calculate the page count, it returns the page count value from the layout cache,...
Definition: laycache.cxx:572
bool mbFirst
Definition: layhelp.hxx:122
sal_uLong mnParagraphCnt
Definition: layhelp.hxx:118
SwPageFrame *& mrpPage
Definition: layhelp.hxx:111
size_t mnFlyIdx
the index in the fly cache array
Definition: layhelp.hxx:121
SwFrame *& mrpFrame
Definition: layhelp.hxx:109
SwLayCacheImpl * mpImpl
Definition: layhelp.hxx:116
SwNodeOffset mnStartOfContent
Definition: layhelp.hxx:119
bool CheckInsert(SwNodeOffset nNodeIndex)
entry point for the InsertCnt_-function.
Definition: laycache.cxx:713
SwLayHelper(SwDoc *pD, SwFrame *&rpF, SwFrame *&rpP, SwPageFrame *&rpPg, SwLayoutFrame *&rpL, std::unique_ptr< SwActualSection > &rpA, SwNodeOffset nNodeIndex, bool bCache)
helper class, which utilizes the layout cache information to distribute the document content to the r...
Definition: laycache.cxx:519
SwLayoutFrame *& mrpLay
Definition: layhelp.hxx:112
void CheckFlyCache_(SwPageFrame *pPage)
If a new page is inserted, the last page is analysed.
Definition: laycache.cxx:968
bool mbBreakAfter
Definition: layhelp.hxx:114
size_t mnIndex
the index in the page break array
Definition: layhelp.hxx:120
sal_uLong mnMaxParaPerPage
Definition: layhelp.hxx:117
std::unique_ptr< SwActualSection > & mrpActualSection
Definition: layhelp.hxx:113
void CheckFlyCache(SwPageFrame *pPage)
Look for fresh text frames at this (new) page and set them to the right position, if they are in the ...
Definition: layhelp.hxx:136
SwFrame *& mrpPrv
Definition: layhelp.hxx:110
bool CheckInsertPage()
inserts a page and return true, if
Definition: laycache.cxx:636
SwDoc * mpDoc
Definition: layhelp.hxx:115
A layout frame is a frame that contains other frames (m_pLower), e.g. SwPageFrame or SwTabFrame.
Definition: layfrm.hxx:36
A page of the document layout.
Definition: pagefrm.hxx:60
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
A section node represents the start of a section on the UI, i.e.
Definition: node.hxx:575
void * p
std::vector< SwFlyCache > SwPageFlyCache
Definition: layhelp.hxx:53
long Long
sal_uIntPtr sal_uLong
RecTypeSize(sal_uInt8 typ, sal_uLong siz)
Definition: layhelp.hxx:155
unsigned char sal_uInt8