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 
25 #include <tools/solar.h>
26 
27 #include <memory>
28 #include <vector>
29 #include <deque>
30 
31 class SwDoc;
32 class SwFrame;
33 class SwLayoutFrame;
34 class SwPageFrame;
35 class SwSectionFrame;
36 class SwSectionNode;
37 class SvStream;
38 
39 /*
40  * Contains the page break information and the text frame positions
41  * of the document (after loading)
42  * and is used inside the constructor of the layout rootframe to
43  * insert content and text frames at the right pages.
44  * For every page of the main text (body content, no footnotes, text frames etc.)
45  * we have the nodeindex of the first content at the page,
46  * the type of content ( table or paragraph )
47  * and if it's not the first part of the table/paragraph,
48  * the row/character-offset inside the table/paragraph.
49  * The text frame positions are stored in the SwPageFlyCache array.
50  */
51 
52 class SwFlyCache;
53 typedef std::vector<SwFlyCache> SwPageFlyCache;
54 
56 {
57  std::vector<sal_uLong> mIndices;
59  std::deque<sal_Int32> aOffset;
60  std::vector<sal_uInt16> aType;
63  void Insert( sal_uInt16 nType, sal_uLong nIndex, sal_Int32 nOffset );
64 
65 public:
66  SwLayCacheImpl() : bUseFlyCache(false) {}
67 
68  size_t size() const { return mIndices.size(); }
69 
70  bool Read( SvStream& rStream );
71 
72  sal_uLong GetBreakIndex( size_t nIdx ) const { return mIndices[ nIdx ]; }
73  sal_Int32 GetBreakOfst( size_t nIdx ) const { return aOffset[ nIdx ]; }
74  sal_uInt16 GetBreakType( size_t nIdx ) const { return aType[ nIdx ]; }
75 
76  size_t GetFlyCount() const { return m_FlyCache.size(); }
77  SwFlyCache& GetFlyCache( size_t nIdx ) { return m_FlyCache[ nIdx ]; }
78 
79  bool IsUseFlyCache() const { return bUseFlyCache; }
80 };
81 
82 // Helps to create the sectionframes during the InsertCnt_-function
83 // by controlling nested sections.
85 {
89 public:
91  SwSectionFrame *pSect,
92  SwSectionNode *pNd );
93 
95  void SetSectionFrame( SwSectionFrame *p ) { pSectFrame = p; }
98 };
99 
103 {
108  std::unique_ptr<SwActualSection> &mrpActualSection;
115  size_t mnIndex;
116  size_t mnFlyIdx;
117  bool mbFirst : 1;
118  void CheckFlyCache_( SwPageFrame* pPage );
119 public:
120  SwLayHelper( SwDoc *pD, SwFrame* &rpF, SwFrame* &rpP, SwPageFrame* &rpPg,
121  SwLayoutFrame* &rpL, std::unique_ptr<SwActualSection> &rpA,
122  sal_uLong nNodeIndex, bool bCache );
123  ~SwLayHelper();
125  bool CheckInsert( sal_uLong nNodeIndex );
126 
127  bool CheckInsertPage();
128 
131  void CheckFlyCache( SwPageFrame* pPage )
132  { if( mpImpl && mnFlyIdx < mpImpl->GetFlyCount() ) CheckFlyCache_( pPage ); }
133 };
134 
135 // Contains the data structures that are required to read and write a layout cache.
136 #define SW_LAYCACHE_IO_REC_PAGES 'p'
137 #define SW_LAYCACHE_IO_REC_PARA 'P'
138 #define SW_LAYCACHE_IO_REC_TABLE 'T'
139 #define SW_LAYCACHE_IO_REC_FLY 'F'
140 
141 #define SW_LAYCACHE_IO_VERSION_MAJOR 1
142 #define SW_LAYCACHE_IO_VERSION_MINOR 1
143 
145 {
146 private:
147  struct RecTypeSize {
150  RecTypeSize(sal_uInt8 typ, sal_uLong siz) : type(typ), size(siz) {}
151  };
152  std::vector<RecTypeSize> aRecords;
153 
155 
157 
158  sal_uInt16 nMajorVersion;
159  sal_uInt16 nMinorVersion;
160 
161  bool const bWriteMode : 1;
162  bool bError : 1;
163 
164 public:
165  SwLayCacheIoImpl( SvStream& rStrm, bool bWrtMd );
166 
168  SvStream& GetStream() const { return *pStream; }
169 
171  void OpenRec( sal_uInt8 nType );
172 
175  void CloseRec();
176 
179  sal_uInt32 BytesLeft();
180 
182  sal_uInt8 Peek();
183 
185  void SkipRec();
186 
191 
193  void OpenFlagRec( sal_uInt8 nFlags, sal_uInt8 nLen );
194 
196  void CloseFlagRec();
197 
198  bool HasError() const { return bError; }
199 
200  sal_uInt16 GetMajorVersion() const { return nMajorVersion; }
201  sal_uInt16 GetMinorVersion() const { return nMinorVersion; }
202 };
203 
204 // Stored information about text frames:
205 class SwFlyCache : public SwRect // position and size
206 {
207 public:
209  sal_uInt16 const nPageNum;
210  SwFlyCache( sal_uInt16 nP, sal_uLong nO, long nXL, long nYL, long nWL, long nHL ) :
211  SwRect( nXL, nYL, nWL, nHL ), nOrdNum( nO ), nPageNum( nP ){}
212 };
213 
214 #endif
215 
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwPageFlyCache m_FlyCache
Definition: layhelp.hxx:61
Base class of the Writer layout elements.
Definition: frame.hxx:295
RecTypeSize(sal_uInt8 typ, sal_uLong siz)
Definition: layhelp.hxx:150
SwSectionNode * pSectNode
Definition: layhelp.hxx:88
SwActualSection *const pUpper
Definition: layhelp.hxx:86
void CloseRec()
Close a record.
Definition: laycache.cxx:1092
bool IsUseFlyCache() const
Definition: layhelp.hxx:79
SwActualSection(SwActualSection *pUpper, SwSectionFrame *pSect, SwSectionNode *pNd)
helper class to create not nested section frames for nested sections.
Definition: laycache.cxx:454
sal_uIntPtr sal_uLong
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:131
bool const bWriteMode
Definition: layhelp.hxx:161
Definition: doc.hxx:185
bool CheckInsert(sal_uLong nNodeIndex)
entry point for the InsertCnt_-function.
Definition: laycache.cxx:714
sal_uLong nFlagRecEnd
Definition: layhelp.hxx:156
Helps during the InsertCnt_ function to create new pages.
Definition: layhelp.hxx:102
sal_uLong GetBreakIndex(size_t nIdx) const
Definition: layhelp.hxx:72
SwFrame *& mrpPrv
Definition: layhelp.hxx:105
void OpenRec(sal_uInt8 nType)
Open a record of type "nType".
Definition: laycache.cxx:1063
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
size_t size() const
Definition: layhelp.hxx:68
std::unique_ptr< SwActualSection > & mrpActualSection
Definition: layhelp.hxx:108
SwActualSection * GetUpper()
Definition: layhelp.hxx:97
size_t GetFlyCount() const
Definition: layhelp.hxx:76
size_t mnIndex
the index in the page break array
Definition: layhelp.hxx:115
sal_uInt16 GetMajorVersion() const
Definition: layhelp.hxx:200
sal_uInt16 nMinorVersion
Definition: layhelp.hxx:159
sal_uInt16 GetMinorVersion() const
Definition: layhelp.hxx:201
SwFlyCache & GetFlyCache(size_t nIdx)
Definition: layhelp.hxx:77
std::vector< RecTypeSize > aRecords
Definition: layhelp.hxx:152
sal_uInt8 OpenFlagRec()
Open a flag record for reading.
Definition: laycache.cxx:1168
std::vector< sal_uLong > mIndices
Definition: layhelp.hxx:57
void SkipRec()
Skip the current record.
Definition: laycache.cxx:1160
sal_uLong const nOrdNum
Id to recognize text frames.
Definition: layhelp.hxx:208
bool bUseFlyCache
Definition: layhelp.hxx:62
bool Read(SvStream &rStream)
Definition: laycache.cxx:87
bool HasError() const
Definition: layhelp.hxx:198
sal_uInt32 BytesLeft()
Return the number of bytes contained in the current record that haven't been read by now...
Definition: laycache.cxx:1130
SwSectionNode * GetSectionNode()
Definition: layhelp.hxx:96
SwLayCacheImpl * mpImpl
Definition: layhelp.hxx:111
sal_uInt16 GetBreakType(size_t nIdx) const
Definition: layhelp.hxx:74
void CloseFlagRec()
Close a flag record. Any bytes left are skipped.
Definition: laycache.cxx:1187
size_t mnFlyIdx
the index in the fly cache array
Definition: layhelp.hxx:116
void SetSectionFrame(SwSectionFrame *p)
Definition: layhelp.hxx:95
A page of the document layout.
Definition: pagefrm.hxx:40
sal_uInt16 const nPageNum
page number
Definition: layhelp.hxx:209
sal_uInt8 Peek()
Return the current record's type.
Definition: laycache.cxx:1143
sal_uLong mnMaxParaPerPage
Definition: layhelp.hxx:112
SwSectionFrame * GetSectionFrame()
Definition: layhelp.hxx:94
SwFlyCache(sal_uInt16 nP, sal_uLong nO, long nXL, long nYL, long nWL, long nHL)
Definition: layhelp.hxx:210
SwLayCacheIoImpl(SvStream &rStrm, bool bWrtMd)
Definition: laycache.cxx:1046
sal_uInt16 nMajorVersion
Definition: layhelp.hxx:158
SwLayoutFrame *& mrpLay
Definition: layhelp.hxx:107
unsigned char sal_uInt8
bool mbBreakAfter
Definition: layhelp.hxx:109
SwLayHelper(SwDoc *pD, SwFrame *&rpF, SwFrame *&rpP, SwPageFrame *&rpPg, SwLayoutFrame *&rpL, std::unique_ptr< SwActualSection > &rpA, sal_uLong nNodeIndex, bool bCache)
helper class, which utilizes the layout cache information to distribute the document content to the r...
Definition: laycache.cxx:519
std::vector< SwFlyCache > SwPageFlyCache
Definition: layhelp.hxx:52
SwFrame *& mrpFrame
Definition: layhelp.hxx:104
SvStream & GetStream() const
Get input or output stream.
Definition: layhelp.hxx:168
bool mbFirst
Definition: layhelp.hxx:117
sal_Int32 GetBreakOfst(size_t nIdx) const
Definition: layhelp.hxx:73
std::deque< sal_Int32 > aOffset
either a textframe character offset, or a row index inside a table
Definition: layhelp.hxx:59
bool CheckInsertPage()
inserts a page and return true, if
Definition: laycache.cxx:634
std::vector< sal_uInt16 > aType
Definition: layhelp.hxx:60
void Insert(sal_uInt16 nType, sal_uLong nIndex, sal_Int32 nOffset)
Definition: laycache.cxx:80
SwDoc * mpDoc
Definition: layhelp.hxx:110
void CheckFlyCache_(SwPageFrame *pPage)
If a new page is inserted, the last page is analysed.
Definition: laycache.cxx:968
SvStream * pStream
Definition: layhelp.hxx:154
SwSectionFrame * pSectFrame
Definition: layhelp.hxx:87
sal_uLong CalcPageCount()
Does NOT really calculate the page count, it returns the page count value from the layout cache...
Definition: laycache.cxx:572
sal_uLong mnParagraphCnt
Definition: layhelp.hxx:113
sal_uLong mnStartOfContent
Definition: layhelp.hxx:114
SwPageFrame *& mrpPage
Definition: layhelp.hxx:106