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> m_aOffset;
60  std::vector<sal_uInt16> m_aType;
63  void Insert( sal_uInt16 nType, sal_uLong nIndex, sal_Int32 nOffset );
64 
65 public:
66  SwLayCacheImpl() : m_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 m_aOffset[ nIdx ]; }
74  sal_uInt16 GetBreakType( size_t nIdx ) const { return m_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 m_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 ) { m_pSectFrame = p; }
97  void SetUpper(SwActualSection *p) { m_pUpper = p; }
99 };
100 
104 {
109  std::unique_ptr<SwActualSection> &mrpActualSection;
116  size_t mnIndex;
117  size_t mnFlyIdx;
118  bool mbFirst : 1;
119  void CheckFlyCache_( SwPageFrame* pPage );
120 public:
121  SwLayHelper( SwDoc *pD, SwFrame* &rpF, SwFrame* &rpP, SwPageFrame* &rpPg,
122  SwLayoutFrame* &rpL, std::unique_ptr<SwActualSection> &rpA,
123  sal_uLong nNodeIndex, bool bCache );
124  ~SwLayHelper();
126  bool CheckInsert( sal_uLong nNodeIndex );
127 
128  bool CheckInsertPage();
129 
132  void CheckFlyCache( SwPageFrame* pPage )
133  { if( mpImpl && mnFlyIdx < mpImpl->GetFlyCount() ) CheckFlyCache_( pPage ); }
134 };
135 
136 // Contains the data structures that are required to read and write a layout cache.
137 #define SW_LAYCACHE_IO_REC_PAGES 'p'
138 #define SW_LAYCACHE_IO_REC_PARA 'P'
139 #define SW_LAYCACHE_IO_REC_TABLE 'T'
140 #define SW_LAYCACHE_IO_REC_FLY 'F'
141 
142 #define SW_LAYCACHE_IO_VERSION_MAJOR 1
143 #define SW_LAYCACHE_IO_VERSION_MINOR 1
144 
146 {
147 private:
148  struct RecTypeSize {
151  RecTypeSize(sal_uInt8 typ, sal_uLong siz) : type(typ), size(siz) {}
152  };
153  std::vector<RecTypeSize> m_aRecords;
154 
156 
158 
159  sal_uInt16 m_nMajorVersion;
160  sal_uInt16 m_nMinorVersion;
161 
162  bool m_bWriteMode : 1;
163  bool m_bError : 1;
164 
165 public:
166  SwLayCacheIoImpl( SvStream& rStrm, bool bWrtMd );
167 
169  SvStream& GetStream() const { return *m_pStream; }
170 
172  void OpenRec( sal_uInt8 nType );
173 
176  void CloseRec();
177 
180  sal_uInt32 BytesLeft();
181 
183  sal_uInt8 Peek();
184 
186  void SkipRec();
187 
192 
194  void OpenFlagRec( sal_uInt8 nFlags, sal_uInt8 nLen );
195 
197  void CloseFlagRec();
198 
199  bool HasError() const { return m_bError; }
200 
201  sal_uInt16 GetMajorVersion() const { return m_nMajorVersion; }
202  sal_uInt16 GetMinorVersion() const { return m_nMinorVersion; }
203 };
204 
205 // Stored information about text frames:
206 class SwFlyCache : public SwRect // position and size
207 {
208 public:
210  sal_uInt16 nPageNum;
211  SwFlyCache( sal_uInt16 nP, sal_uLong nO, tools::Long nXL, tools::Long nYL, tools::Long nWL, tools::Long nHL ) :
212  SwRect( nXL, nYL, nWL, nHL ), nOrdNum( nO ), nPageNum( nP ){}
213 };
214 
215 #endif
216 
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwPageFlyCache m_FlyCache
Definition: layhelp.hxx:61
Base class of the Writer layout elements.
Definition: frame.hxx:298
RecTypeSize(sal_uInt8 typ, sal_uLong siz)
Definition: layhelp.hxx:151
std::deque< sal_Int32 > m_aOffset
either a textframe character offset, or a row index inside a table
Definition: layhelp.hxx:59
bool m_bUseFlyCache
Definition: layhelp.hxx:62
void CloseRec()
Close a record.
Definition: laycache.cxx:1095
bool IsUseFlyCache() const
Definition: layhelp.hxx:79
SvStream * m_pStream
Definition: layhelp.hxx:155
SwActualSection(SwActualSection *pUpper, SwSectionFrame *pSect, SwSectionNode *pNd)
helper class to create not nested section frames for nested sections.
Definition: laycache.cxx:455
sal_uIntPtr sal_uLong
long Long
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:132
Definition: doc.hxx:186
bool CheckInsert(sal_uLong nNodeIndex)
entry point for the InsertCnt_-function.
Definition: laycache.cxx:714
Helps during the InsertCnt_ function to create new pages.
Definition: layhelp.hxx:103
sal_uLong GetBreakIndex(size_t nIdx) const
Definition: layhelp.hxx:72
SwFrame *& mrpPrv
Definition: layhelp.hxx:106
void OpenRec(sal_uInt8 nType)
Open a record of type "nType".
Definition: laycache.cxx:1066
SwFlyCache(sal_uInt16 nP, sal_uLong nO, tools::Long nXL, tools::Long nYL, tools::Long nWL, tools::Long nHL)
Definition: layhelp.hxx:211
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
size_t size() const
Definition: layhelp.hxx:68
sal_uLong nOrdNum
Id to recognize text frames.
Definition: layhelp.hxx:209
std::unique_ptr< SwActualSection > & mrpActualSection
Definition: layhelp.hxx:109
SwActualSection * GetUpper()
Definition: layhelp.hxx:98
void SetUpper(SwActualSection *p)
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:116
sal_uInt16 GetMajorVersion() const
Definition: layhelp.hxx:201
sal_uInt16 GetMinorVersion() const
Definition: layhelp.hxx:202
SwFlyCache & GetFlyCache(size_t nIdx)
Definition: layhelp.hxx:77
sal_uInt8 OpenFlagRec()
Open a flag record for reading.
Definition: laycache.cxx:1171
std::vector< sal_uLong > mIndices
Definition: layhelp.hxx:57
void SkipRec()
Skip the current record.
Definition: laycache.cxx:1163
SwSectionNode * m_pSectNode
Definition: layhelp.hxx:88
sal_uInt16 m_nMajorVersion
Definition: layhelp.hxx:159
sal_uInt16 nPageNum
page number
Definition: layhelp.hxx:210
std::vector< RecTypeSize > m_aRecords
Definition: layhelp.hxx:153
bool Read(SvStream &rStream)
Definition: laycache.cxx:88
bool HasError() const
Definition: layhelp.hxx:199
sal_uInt32 BytesLeft()
Return the number of bytes contained in the current record that haven't been read by now...
Definition: laycache.cxx:1133
SwSectionNode * GetSectionNode()
Definition: layhelp.hxx:96
SwLayCacheImpl * mpImpl
Definition: layhelp.hxx:112
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:1190
size_t mnFlyIdx
the index in the fly cache array
Definition: layhelp.hxx:117
void SetSectionFrame(SwSectionFrame *p)
Definition: layhelp.hxx:95
A page of the document layout.
Definition: pagefrm.hxx:41
sal_uInt8 Peek()
Return the current record's type.
Definition: laycache.cxx:1146
sal_uLong mnMaxParaPerPage
Definition: layhelp.hxx:113
SwSectionFrame * GetSectionFrame()
Definition: layhelp.hxx:94
SwLayCacheIoImpl(SvStream &rStrm, bool bWrtMd)
Definition: laycache.cxx:1049
SwLayoutFrame *& mrpLay
Definition: layhelp.hxx:108
unsigned char sal_uInt8
bool mbBreakAfter
Definition: layhelp.hxx:110
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:520
std::vector< SwFlyCache > SwPageFlyCache
Definition: layhelp.hxx:52
SwFrame *& mrpFrame
Definition: layhelp.hxx:105
SvStream & GetStream() const
Get input or output stream.
Definition: layhelp.hxx:169
SwActualSection * m_pUpper
Definition: layhelp.hxx:86
bool mbFirst
Definition: layhelp.hxx:118
SwSectionFrame * m_pSectFrame
Definition: layhelp.hxx:87
sal_Int32 GetBreakOfst(size_t nIdx) const
Definition: layhelp.hxx:73
bool CheckInsertPage()
inserts a page and return true, if
Definition: laycache.cxx:637
void Insert(sal_uInt16 nType, sal_uLong nIndex, sal_Int32 nOffset)
Definition: laycache.cxx:81
A layout frame is a frame that contains other frames (m_pLower), e.g. SwPageFrame or SwTabFrame...
Definition: layfrm.hxx:35
SwDoc * mpDoc
Definition: layhelp.hxx:111
void CheckFlyCache_(SwPageFrame *pPage)
If a new page is inserted, the last page is analysed.
Definition: laycache.cxx:972
sal_uLong CalcPageCount()
Does NOT really calculate the page count, it returns the page count value from the layout cache...
Definition: laycache.cxx:573
sal_uLong mnParagraphCnt
Definition: layhelp.hxx:114
sal_uLong mnStartOfContent
Definition: layhelp.hxx:115
sal_uLong m_nFlagRecEnd
Definition: layhelp.hxx:157
sal_uInt16 m_nMinorVersion
Definition: layhelp.hxx:160
std::vector< sal_uInt16 > m_aType
Definition: layhelp.hxx:60
SwPageFrame *& mrpPage
Definition: layhelp.hxx:107