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{
90public:
92 SwSectionFrame *pSect,
93 SwSectionNode *pNd );
94
100};
101
105{
110 std::unique_ptr<SwActualSection> &mrpActualSection;
117 size_t mnIndex;
118 size_t mnFlyIdx;
119 bool mbFirst : 1;
120 void CheckFlyCache_( SwPageFrame* pPage );
121public:
122 SwLayHelper( SwDoc *pD, SwFrame* &rpF, SwFrame* &rpP, SwPageFrame* &rpPg,
123 SwLayoutFrame* &rpL, std::unique_ptr<SwActualSection> &rpA,
124 SwNodeOffset nNodeIndex, bool bCache );
125 ~SwLayHelper();
127 bool CheckInsert( SwNodeOffset nNodeIndex );
128
129 bool CheckInsertPage();
130
134 { if( mpImpl && mnFlyIdx < mpImpl->GetFlyCount() ) CheckFlyCache_( pPage ); }
135};
136
137// Contains the data structures that are required to read and write a layout cache.
138#define SW_LAYCACHE_IO_REC_PAGES 'p'
139#define SW_LAYCACHE_IO_REC_PARA 'P'
140#define SW_LAYCACHE_IO_REC_TABLE 'T'
141#define SW_LAYCACHE_IO_REC_FLY 'F'
142
143#define SW_LAYCACHE_IO_VERSION_MAJOR 1
144#define SW_LAYCACHE_IO_VERSION_MINOR 1
145
147{
148private:
149 struct RecTypeSize {
152 RecTypeSize(sal_uInt8 typ, sal_uLong siz) : type(typ), size(siz) {}
153 };
154 std::vector<RecTypeSize> m_aRecords;
155
157
159
160 sal_uInt16 m_nMajorVersion;
161 sal_uInt16 m_nMinorVersion;
162
163 bool m_bWriteMode : 1;
164 bool m_bError : 1;
165
166public:
167 SwLayCacheIoImpl( SvStream& rStrm, bool bWrtMd );
168
170 SvStream& GetStream() const { return *m_pStream; }
171
173 void OpenRec( sal_uInt8 nType );
174
177 void CloseRec();
178
181 sal_uInt32 BytesLeft();
182
184 sal_uInt8 Peek();
185
187 void SkipRec();
188
193
195 void OpenFlagRec( sal_uInt8 nFlags, sal_uInt8 nLen );
196
198 void CloseFlagRec();
199
200 bool HasError() const { return m_bError; }
201
202 sal_uInt16 GetMajorVersion() const { return m_nMajorVersion; }
203 sal_uInt16 GetMinorVersion() const { return m_nMinorVersion; }
204};
205
206// Stored information about text frames:
207class SwFlyCache : public SwRect // position and size
208{
209public:
211 sal_uInt16 nPageNum;
212 SwFlyCache( sal_uInt16 nP, sal_uLong nO, tools::Long nXL, tools::Long nYL, tools::Long nWL, tools::Long nHL ) :
213 SwRect( nXL, nYL, nWL, nHL ), nOrdNum( nO ), nPageNum( nP ){}
214};
215
216SwLayCacheImpl::SwLayCacheImpl() : m_bUseFlyCache(false) {}
217
218size_t SwLayCacheImpl::GetFlyCount() const { return m_FlyCache.size(); }
219
220SwFlyCache& SwLayCacheImpl::GetFlyCache( size_t nIdx ) { return m_FlyCache[ nIdx ]; }
221
222#endif
223
224/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwSectionFrame * m_pSectFrame
Definition: layhelp.hxx:88
void SetSectionFrame(SwSectionFrame *p)
Definition: layhelp.hxx:96
SwSectionNode * m_pSectNode
Definition: layhelp.hxx:89
SwSectionFrame * GetSectionFrame()
Definition: layhelp.hxx:95
SwActualSection * GetUpper()
Definition: layhelp.hxx:99
SwSectionNode * GetSectionNode()
Definition: layhelp.hxx:97
void SetUpper(SwActualSection *p)
Definition: layhelp.hxx:98
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:195
sal_uInt16 nPageNum
page number
Definition: layhelp.hxx:211
sal_uLong nOrdNum
Id to recognize text frames.
Definition: layhelp.hxx:210
SwFlyCache(sal_uInt16 nP, sal_uLong nO, tools::Long nXL, tools::Long nYL, tools::Long nWL, tools::Long nHL)
Definition: layhelp.hxx:212
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:218
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:220
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:202
void CloseRec()
Close a record.
Definition: laycache.cxx:1091
std::vector< RecTypeSize > m_aRecords
Definition: layhelp.hxx:154
sal_uInt16 GetMinorVersion() const
Definition: layhelp.hxx:203
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:170
sal_uLong m_nFlagRecEnd
Definition: layhelp.hxx:158
sal_uInt16 m_nMajorVersion
Definition: layhelp.hxx:160
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:156
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:161
bool HasError() const
Definition: layhelp.hxx:200
SwLayCacheIoImpl(SvStream &rStrm, bool bWrtMd)
Definition: laycache.cxx:1045
Helps during the InsertCnt_ function to create new pages.
Definition: layhelp.hxx:105
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:119
sal_uLong mnParagraphCnt
Definition: layhelp.hxx:115
SwPageFrame *& mrpPage
Definition: layhelp.hxx:108
size_t mnFlyIdx
the index in the fly cache array
Definition: layhelp.hxx:118
SwFrame *& mrpFrame
Definition: layhelp.hxx:106
SwLayCacheImpl * mpImpl
Definition: layhelp.hxx:113
SwNodeOffset mnStartOfContent
Definition: layhelp.hxx:116
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:109
void CheckFlyCache_(SwPageFrame *pPage)
If a new page is inserted, the last page is analysed.
Definition: laycache.cxx:968
bool mbBreakAfter
Definition: layhelp.hxx:111
size_t mnIndex
the index in the page break array
Definition: layhelp.hxx:117
sal_uLong mnMaxParaPerPage
Definition: layhelp.hxx:114
std::unique_ptr< SwActualSection > & mrpActualSection
Definition: layhelp.hxx:110
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:133
SwFrame *& mrpPrv
Definition: layhelp.hxx:107
bool CheckInsertPage()
inserts a page and return true, if
Definition: laycache.cxx:636
SwDoc * mpDoc
Definition: layhelp.hxx:112
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:58
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:152
unsigned char sal_uInt8